Skip to content

Commit 6de291f

Browse files
FayeSGWclaude
andauthored
fix(repo-info): preserve full CI-detected repo path in repo_info.name (#1017)
* fix(repo-info): preserve full CI-detected repo path in repo_info.name The --repository flag defaults to a short repo name in some CIs (GitLab's CI_PROJECT_NAME, Bitbucket's slug) while getGitRepoInfoFrom* detects the full path (GitLab's CI_PROJECT_PATH). Because mergeGitRepoInfo always applied the flag value, the short default clobbered the full CI-detected name, so repo_info.name lost its namespace (e.g. "creator" instead of "cyber-dojo/creator"). Only override the CI-detected name when --repository is set explicitly (or when no CI name was detected), threading repoNameExplicit through the attest/begin-trail commands. The GitLab API ProjectID path is untouched. Also fixes the same latent issue for Bitbucket. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test(repo-info): add wiring regression test and clarify GitLab PR comment Add RepoInfoWiringTestSuite covering the three run() paths that build repo_info (attest generic, begin trail, attest artifact): the CI-detected full-path name is used by default and an explicit --repository overrides it. A mutation (removing a repoNameExplicit assignment) fails the explicit cases, so the suite guards the command wiring. Also add a mergeGitRepoInfo unit case for a fully-populated base with no flags, and a comment on attestPRGitlab clarifying that GitlabConfig. Repository (short, for the API ProjectID) is separate from repo_info.name (full CI_PROJECT_PATH). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Remove stray committed file --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 20b8f04 commit 6de291f

17 files changed

Lines changed: 209 additions & 25 deletions

cmd/kosli/attestArtifact.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type attestArtifactOptions struct {
2727
repoName string
2828
repoURL string
2929
repoProvider string
30+
repoNameExplicit bool
3031
}
3132

3233
type AttestArtifactPayload struct {
@@ -133,6 +134,7 @@ func newAttestArtifactCmd(out io.Writer) *cobra.Command {
133134
return ValidateRegistryFlags(cmd, o.fingerprintOptions)
134135
},
135136
RunE: func(cmd *cobra.Command, args []string) error {
137+
o.repoNameExplicit = cmd.Flags().Changed("repository")
136138
return o.run(args)
137139
},
138140
}
@@ -210,7 +212,7 @@ func (o *attestArtifactOptions) run(args []string) error {
210212
if err != nil {
211213
logger.Warn("failed to get git repo info. %s", err.Error())
212214
}
213-
o.payload.GitRepoInfo = mergeGitRepoInfo(o.payload.GitRepoInfo, o.repoID, o.repoName, o.repoURL, o.repoProvider)
215+
o.payload.GitRepoInfo = mergeGitRepoInfo(o.payload.GitRepoInfo, o.repoID, o.repoName, o.repoURL, o.repoProvider, o.repoNameExplicit)
214216
o.payload.GitCommit = commitInfo.Sha1
215217
o.payload.GitCommitInfo = &commitInfo.BasicCommitInfo
216218

cmd/kosli/attestCustom.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ func newAttestCustomCmd(out io.Writer) *cobra.Command {
136136

137137
RunE: func(cmd *cobra.Command, args []string) error {
138138
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
139+
o.repoNameExplicit = cmd.Flags().Changed("repository")
139140
return o.run(args)
140141
},
141142
}

cmd/kosli/attestDecision.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ func newAttestDecisionCmd(out io.Writer) *cobra.Command {
132132

133133
RunE: func(cmd *cobra.Command, args []string) error {
134134
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
135+
o.repoNameExplicit = cmd.Flags().Changed("repository")
135136
return o.run(args)
136137
},
137138
}

cmd/kosli/attestGeneric.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func newAttestGenericCmd(out io.Writer) *cobra.Command {
130130

131131
RunE: func(cmd *cobra.Command, args []string) error {
132132
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
133+
o.repoNameExplicit = cmd.Flags().Changed("repository")
133134
return o.run(args)
134135
},
135136
}

cmd/kosli/attestJira.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ func newAttestJiraCmd(out io.Writer) *cobra.Command {
246246
},
247247
RunE: func(cmd *cobra.Command, args []string) error {
248248
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
249+
o.repoNameExplicit = cmd.Flags().Changed("repository")
249250
return o.run(args)
250251
},
251252
}

cmd/kosli/attestJunit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ func newAttestJunitCmd(out io.Writer) *cobra.Command {
134134
},
135135
RunE: func(cmd *cobra.Command, args []string) error {
136136
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
137+
o.repoNameExplicit = cmd.Flags().Changed("repository")
137138
return o.run(args)
138139
},
139140
}

cmd/kosli/attestOverride.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ func newAttestOverrideCmd(out io.Writer) *cobra.Command {
104104

105105
RunE: func(cmd *cobra.Command, args []string) error {
106106
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
107+
o.repoNameExplicit = cmd.Flags().Changed("repository")
107108
return o.run(args)
108109
},
109110
}

cmd/kosli/attestPRAzure.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ func newAttestAzurePRCmd(out io.Writer) *cobra.Command {
147147
},
148148
RunE: func(cmd *cobra.Command, args []string) error {
149149
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
150+
o.repoNameExplicit = cmd.Flags().Changed("repository")
150151
o.retriever = azUtils.NewAzureConfig(azureFlagsValues.Token,
151152
azureFlagsValues.OrgUrl, azureFlagsValues.Project, o.repoName)
152153
return o.run(args)

cmd/kosli/attestPRBitbucket.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ func newAttestBitbucketPRCmd(out io.Writer) *cobra.Command {
167167
},
168168
RunE: func(cmd *cobra.Command, args []string) error {
169169
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
170+
o.repoNameExplicit = cmd.Flags().Changed("repository")
170171
o.getRetriever().(*bbUtils.Config).Repository = o.repoName
171172
return o.run(args)
172173
},

cmd/kosli/attestPRGithub.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ func newAttestGithubPRCmd(out io.Writer) *cobra.Command {
142142
},
143143
RunE: func(cmd *cobra.Command, args []string) error {
144144
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
145+
o.repoNameExplicit = cmd.Flags().Changed("repository")
145146
o.retriever = ghUtils.NewGithubRetrieverFunc(githubFlagsValues.Token, githubFlagsValues.BaseURL,
146147
githubFlagsValues.Org, o.repoName, global.Debug)
147148
return o.run(args)

0 commit comments

Comments
 (0)