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#1017FayeSGW wants to merge 3 commits into
Conversation
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>
…ment 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>
|
Claude finished @FayeSGW's task in 3m 35s —— View job Review complete ✅
SummaryThis is a well-scoped, well-reasoned fix. The root-cause analysis in the PR description checks out against the code:
Verified:
Tests — strong.
Issues1. Stray file committed — 2. Per-command duplication of the Nits (optional)
Overall: clean fix, thoughtful backward-compat analysis, good tests. The only thing I'd block on is removing the stray |
| return err | ||
| } | ||
| payload.GitRepoInfo = mergeGitRepoInfo(payload.GitRepoInfo, o.repoID, o.repoName, o.repoURL, o.repoProvider) | ||
| payload.GitRepoInfo = mergeGitRepoInfo(payload.GitRepoInfo, o.repoID, o.repoName, o.repoURL, o.repoProvider, o.repoNameExplicit) |
There was a problem hiding this comment.
Minor / maintainability: o.repoNameExplicit is populated per-command via cmd.Flags().Changed("repository") duplicated across 14 RunE bodies. Any future attest command that forgets that line will silently fall back to repoNameExplicit=false, causing an explicit --repository to be ignored whenever a CI-detected base name is present — a quiet correctness regression rather than a compile error.
This mirrors the existing repoURLExplicit convention, so it's consistent and fine to keep. But since run() already has the flag values, consider a follow-up that derives both *Explicit bools centrally (e.g. threading cmd in, or a shared PersistentPreRunE on the attest command group) so it can't be forgotten. Not blocking.
Problem
For GitLab (and Bitbucket) CI,
repo_info.namewas reported as the short project name (e.g.creator) instead of the full path (e.g.cyber-dojo/creator), losing the namespace/sub-group context.Root cause:
getGitRepoInfoFromGitLab()correctly detects the full path (CI_PROJECT_PATH), but the--repositoryflag defaults to a shorter value (CI_PROJECT_NAME), andmergeGitRepoInfounconditionally applied the flag value over the CI-detected base — so the short default always clobbered the full path. Bitbucket had the same latent issue (BITBUCKET_REPO_SLUGvsBITBUCKET_REPO_FULL_NAME).Fix
--repositorynow overrides the CI-detected name only when set explicitly (or when the CI base has no name). Otherwise the fuller CI-detected value is preserved:repoNameExplicitis threaded from each command viacmd.Flags().Changed("repository"), mirroring the existingrepoURLExplicitpattern.Why this approach
The alternative — changing the GitLab
--repositorydefault toCI_PROJECT_PATH— would have broken GitLab's APIProjectID()(Org/Repository→namespace/full-path, a duplicated namespace) and changed the meaning of--gitlab-org. This approach leaves the GitLab PR/API path completely untouched and fixes Bitbucket for free.Testing
TestMergeGitRepoInfo— added cases for full-path preservation, explicit override, and a fully-populated base with no flags.RepoInfoWiringTestSuite(new) — dry-run payload assertions across the threerun()paths that buildrepo_info(attest generic,begin trail,attest artifact): CI-detected name used by default, explicit--repositoryoverrides. A mutation (removing arepoNameExplicitassignment) fails the explicit cases, confirming the suite guards the wiring.attest pr *(call the live VCS API before the dry-run guard; token-gated, as the existing PR tests are).Backward compatibility
(org_id, repo_id)(externalCI_PROJECT_ID), treatingnameas a mutable field. The next attestation updates the name in place — sameinner_id, no fork. All downstream records (artifacts, trails, environment events, deployments, tags) key offinner_id, not name. The CLI only emitsrepo_infowhenid+name+urlare all present, so the server's name-fallback (fork risk) is never triggered.--repositorynow report the full path.kosli get repo <short>,list artifacts --repo <short>,log environment --repo <short>, and the list-reposname=filter. Callers should use the full path,--repo-id, orsearch=. Not data loss.--repositoryusers, and GitHub/Azure/CircleCI users, are unaffected.repo_id; identity stays a single document throughout.Follow-ups (not in this PR)
list artifacts --repohelp/example still saysyourRepoName; could be updated to reflect full-path naming.