Repository navigation
fix(sonar): attest a SonarQube Cloud short-lived branch by project key - #1295
Conversation
SonarQube Cloud serves api/project_analyses/search only for long-lived branches, so --sonar-branch on a feature branch failed with "Branch '...' is not of type LONG". When the search fails and the branch is listed as short-lived, use its latest analysis from api/project_branches/list and its quality gate by project key and branch. The revision must be that latest commit, checked again after reading the gate in case a newer push was processed in between. Fixes #1294 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rmed The check after reading a short-lived branch's quality gate let the attestation through when the second branch listing failed or no longer listed the branch, so a gate of another commit could be attested. Fail instead, and decide "gate is the branch's latest" in one place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Claude finished @AlexKantor87's task in 2m 6s —— View job Follow-up review of c33ffba — findings re-checked
Status of each previously-raised finding:
New issues in the changed lines (2374801..c33ffba): none found. Checked for: nil-pointer risk on No new inline comments posted — the one open thread was already resolved by the fix, and no regressions were found in the touched lines. Note: I wasn't able to execute |
|
Thanks for the review. Here's what happened to each finding in c33ffba.
search: grep -nE 'try again later' internal/sonar/sonar.go In each of these, the scan may not be processed yet, so a retry can help. The newer-analysis message has none. mutation: make The full local suite is green on this tree (3661 tests). 🤖 Addressed by Claude Code |
…irmed The branch lookup now reports a non-2xx response as an error, so the re-check after reading the gate keeps the HTTP status, and a branch no longer listed is named as the cause. When a newer analysis has replaced the attested revision, the error says so rather than suggesting a retry that cannot help. search: grep -nE 'isShort|shortLivedBranchAnalysis' internal/sonar/sonar.go 465-466 the first lookup in GetProjectAnalysisFromRevision, still the only caller; 499/504 its definition. The re-check no longer calls it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes #1294
Release together: don't merge this on its own. It ships in the same release as #1297. That PR fixes the
report-task.txtand--sonar-ce-task-urlpaths. That PR builds on this branch, so the short-lived branch rule stays in one function.What
On SonarQube Cloud,
--sonar-branchfailed on a feature branch withBranch '...' is not of type LONG. The analysis search only serves long-lived branches.When that search fails and the branch is listed as short-lived, the CLI now:
api/project_branches/list.--sonar-revision. SonarQube Cloud keeps only the latest analysis of a short-lived branch, as it does for pull requests.Any other SonarQube error is returned unchanged. A long-lived branch makes no extra calls.
Evidence
internal/sonar/sonar_short_branch_test.go. Onmain, the four short-branch tests fail with the reported error. All pass with the fix, and mutating each guard turns its test red.cyber-dojo_differ/run-workflow-196. It rejects a wrong revision.mainbehaves as before.Not covered
report-task.txtand--sonar-ce-task-urlvery likely fail the same way (see the issue).api/ce/activity.🤖 Generated with Claude Code