This is an automated email from the ASF dual-hosted git repository. squakez pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit fb1812987130c11cf07d2fc759d524612095b10a Author: Jan Bouecke <[email protected]> AuthorDate: Thu Oct 8 15:02:42 2026 +0200 Fix #6869: let callers provide the Git username to CloneGitProject Address review feedback: instead of a separate CloneGitProjectWithUsername func, CloneGitProject now takes the username as a parameter and the callers are in charge to provide the default value. Co-Authored-By: Claude Opus 5.5 <[email protected]> --- pkg/builder/git.go | 2 +- pkg/trait/gitops.go | 2 +- pkg/util/gitops/gitops.go | 17 ++++------------- pkg/util/gitops/gitops_test.go | 18 ++++-------------- 4 files changed, 10 insertions(+), 29 deletions(-) diff --git a/pkg/builder/git.go b/pkg/builder/git.go index f1e3b3016..7935c471e 100644 --- a/pkg/builder/git.go +++ b/pkg/builder/git.go @@ -75,7 +75,7 @@ func cloneProject(ctx *builderContext) error { if ctx.Build.Git.Path != "" { gitClonePath = filepath.Join(ctx.Path, "repo") } - if _, err := util.CloneGitProject(*ctx.Build.Git, gitClonePath, secretToken); err != nil { + if _, err := util.CloneGitProject(*ctx.Build.Git, gitClonePath, util.DefaultGitUsername, secretToken); err != nil { return err } if ctx.Build.Git.Path != "" { diff --git a/pkg/trait/gitops.go b/pkg/trait/gitops.go index 6f58c274b..d5eab2b93 100644 --- a/pkg/trait/gitops.go +++ b/pkg/trait/gitops.go @@ -117,7 +117,7 @@ func (t *gitOpsTrait) pushGitOpsItInGitRepo(ctx context.Context, it *v1.Integrat } // Clone repo - repo, err := util.CloneGitProjectWithUsername(gitConf, dir, t.getUsername(), token) + repo, err := util.CloneGitProject(gitConf, dir, t.getUsername(), token) if err != nil { return err } diff --git a/pkg/util/gitops/gitops.go b/pkg/util/gitops/gitops.go index bed29e976..1120f02b1 100644 --- a/pkg/util/gitops/gitops.go +++ b/pkg/util/gitops/gitops.go @@ -477,7 +477,7 @@ patches: return createOrAppendAll(destinationDir, dstPipe.Name, namespaceDest) } -// DefaultGitUsername is the username used to authenticate against the Git server when none is provided. +// DefaultGitUsername is the username callers can use to authenticate against the Git server when none is configured. // Most Git servers (ie, GitHub) accept any non empty value when authenticating with a token. const DefaultGitUsername = "camel-k" @@ -500,16 +500,10 @@ func GitToken(ctx context.Context, c client.Client, namespace, secret string) (s return "", nil } -// CloneGitProject is in charge to clone the project from a given Git repo configuration. +// CloneGitProject is in charge to clone the project from a given Git repo configuration, +// authenticating with the given username and secretToken. // If no secretToken is provided, then, it is assumed the project is public. -func CloneGitProject(gitConf v1.GitConfigSpec, dir, secretToken string) (*git.Repository, error) { - return CloneGitProjectWithUsername(gitConf, dir, "", secretToken) -} - -// CloneGitProjectWithUsername is in charge to clone the project from a given Git repo configuration, -// authenticating with the given username and secretToken. If no username is provided, then, DefaultGitUsername is used. -// If no secretToken is provided, then, it is assumed the project is public. -func CloneGitProjectWithUsername(gitConf v1.GitConfigSpec, dir, username, secretToken string) (*git.Repository, error) { +func CloneGitProject(gitConf v1.GitConfigSpec, dir, username, secretToken string) (*git.Repository, error) { depth := 1 if gitConf.Commit != "" { // only the commit checkout requires full git project history @@ -538,9 +532,6 @@ func CloneGitProjectWithUsername(gitConf v1.GitConfigSpec, dir, username, secret } if secretToken != "" { - if username == "" { - username = DefaultGitUsername - } gitCloneOptions.Auth = &http.BasicAuth{ Username: username, Password: secretToken, diff --git a/pkg/util/gitops/gitops_test.go b/pkg/util/gitops/gitops_test.go index 552fa94d8..032247b1a 100644 --- a/pkg/util/gitops/gitops_test.go +++ b/pkg/util/gitops/gitops_test.go @@ -63,7 +63,7 @@ func cloneWithRecorder(t *testing.T, clone func(conf v1.GitConfigSpec, dir strin func TestCloneGitProjectDefaultUsername(t *testing.T) { recorder := cloneWithRecorder(t, func(conf v1.GitConfigSpec, dir string) error { - _, err := CloneGitProject(conf, dir, "my-token") + _, err := CloneGitProject(conf, dir, DefaultGitUsername, "my-token") return err }) @@ -72,9 +72,9 @@ func TestCloneGitProjectDefaultUsername(t *testing.T) { assert.Equal(t, "my-token", recorder.password) } -func TestCloneGitProjectWithUsername(t *testing.T) { +func TestCloneGitProject(t *testing.T) { recorder := cloneWithRecorder(t, func(conf v1.GitConfigSpec, dir string) error { - _, err := CloneGitProjectWithUsername(conf, dir, "x-token-auth", "my-token") + _, err := CloneGitProject(conf, dir, "x-token-auth", "my-token") return err }) @@ -83,19 +83,9 @@ func TestCloneGitProjectWithUsername(t *testing.T) { assert.Equal(t, "my-token", recorder.password) } -func TestCloneGitProjectWithEmptyUsername(t *testing.T) { - recorder := cloneWithRecorder(t, func(conf v1.GitConfigSpec, dir string) error { - _, err := CloneGitProjectWithUsername(conf, dir, "", "my-token") - - return err - }) - assert.True(t, recorder.ok) - assert.Equal(t, DefaultGitUsername, recorder.username) -} - func TestCloneGitProjectWithoutToken(t *testing.T) { recorder := cloneWithRecorder(t, func(conf v1.GitConfigSpec, dir string) error { - _, err := CloneGitProjectWithUsername(conf, dir, "x-token-auth", "") + _, err := CloneGitProject(conf, dir, "x-token-auth", "") return err })
