Skip to content

fix(sonar): attest a SonarQube Cloud short-lived branch scan found by its CE task - #1297

Merged
AlexKantor87 merged 6 commits into
mainfrom
claude/sonar-short-branch-ce-task
Oct 23, 2026
Merged

AlexKantor87 merged 6 commits into
mainfrom
claude/sonar-short-branch-ce-task

Conversation

@AlexKantor87

@AlexKantor87 AlexKantor87 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1296.

Ships in the same release as #1295. #1295 is merged; this PR is now based on main.

What it fixes

kosli attest sonar failed with "Branch '...' is not of type LONG" on a SonarQube Cloud short-lived branch when it found the scan through report-task.txt or --sonar-ce-task-url. #1295 fixed the project-key path only.

How

On these paths we know the scan's analysis ID, not its commit. For a short-lived branch, SonarCloud gives only the commit of the branch's latest analysis (api/project_branches/list). We use it only when that analysis is ours. After listing the branch, api/ce/component must show our task as the project's last finished task. No task that could be on the branch may be running. That endpoint needs only Browse permission. A running task counts because SonarQube saves a scan's analysis before it records the task as finished.

The first lookup on both paths (project key and CE task) now goes through one function, shortLivedBranchAnalysis, built on #1295's listedShortLivedBranch. Each path only says how it knows the branch's latest analysis is the one it attests.

Limits

  • The check relies on SonarCloud running one task per project at a time, as SonarQube does. SonarCloud's code isn't public.
  • On a busy project, another scan often finishes first. The command then fails and says to use --sonar-project-key with --sonar-revision.

Tested

  • New tests red on fix(sonar): attest a SonarQube Cloud short-lived branch by project key #1295's branch; each guard's mutation caught.
  • cli-suite.sh green against a local server.
  • Live SonarCloud, public projects, auth stripped:
    • Project key: cyber-dojo_differ, branch run-workflow-196. Latest commit attests; another commit is refused.
    • CE task URL: aelassas_servy, branch net48, attested commit 5c50372, which matches GitHub's branch head. We served only api/ce/task from a captured copy, since it needs Execute Analysis. report-task.txt runs the same code after reading the file.

🤖 Generated with Claude Code

AlexKantor87 and others added 5 commits October 23, 2026 08:26
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>
…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>
… its CE task

report-task.txt and --sonar-ce-task-url failed on a short-lived branch,
because SonarCloud's analyses search refuses those branches. The branch
list gives the commit of the branch's latest analysis only. We use it
when api/ce/component, read after the list, shows our task as the
project's last finished task and no task is in progress.

All three short-lived branch lookups now go through one function,
shortLivedBranchAnalysis. Each path only says how it knows the branch's
latest analysis is the one it attests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… into claude/sonar-short-branch-ce-task

# Conflicts:
#	internal/sonar/sonar.go
mbevc1
mbevc1 previously approved these changes Oct 23, 2026
Base automatically changed from claude/sonar-short-lived-branch to main October 23, 2026 08:35
@AlexKantor87
AlexKantor87 dismissed mbevc1’s stale review October 23, 2026 08:35

The base branch was changed.

…anch-ce-task

# Conflicts:
#	internal/sonar/sonar.go
@claude

claude Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @AlexKantor87's task in 34s —— View job


Follow-up review — new commits

  • Fetch previous review findings
  • Diff BEFORE..AFTER commits
  • Evaluate status of each prior finding
  • Check new commits for introduced bugs/regressions (changed lines only)
  • Post summary comment

What changed between the two commits: the only new commit (7437149, a merge of origin/main) brings in #1295 (already merged to main) plus routine CI/dependency bumps — harden-runner pin update, claude-code-action version bump, and go.mod/go.sum dependency updates. None of this PR's substantive files (cmd/kosli/attestSonar.go, internal/sonar/sonar.go, internal/sonar/sonar_ce_short_branch_test.go) were touched.

Previous findings: none to report — there is no prior Claude review on this PR with findings to reconcile. The only existing review (by mbevc1) was dismissed and had no comment body.

New issues: none found — no inline comments posted, since no logic changed.

@AlexKantor87
AlexKantor87 enabled auto-merge (squash) October 23, 2026 08:46
@AlexKantor87
AlexKantor87 merged commit 9b15cbb into main Oct 23, 2026
30 of 32 checks passed
@AlexKantor87
AlexKantor87 deleted the claude/sonar-short-branch-ce-task branch October 23, 2026 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

attest sonar fails on a SonarQube Cloud short-lived branch via report-task.txt or --sonar-ce-task-url

2 participants