fix: migrate source project version per branch instead of hardcoded 1.0.0 (Issue #137)#156
Conversation
….0.0 (Issue #137) Source project version (e.g., "3.20") was systematically migrated to SonarCloud as "1.0.0" because the version was hardcoded in two places: 1. The `sonar.projectVersion` form parameter in the `api/ce/submit` form data. 2. The `projectVersion` field of the protobuf metadata embedded inside the scanner report zip uploaded to the CE. This second location is what SonarCloud's CE actually reads — fixing only the form parameter does nothing because the report metadata overrides it. This change fetches the version per branch from the source SonarQube via `GET /api/navigation/component?component=<key>&branch=<branch>` (omitting `branch` for the main branch so the API's default applies, which is robust to SQ↔SC main branch name differences). The fetched version is passed through the transfer chain into both the form parameter and the protobuf metadata, falling back to "1.0.0" only when the API call fails or the setting is unset. Applied across all 4 pipelines (sq-9.9, sq-10.0, sq-10.4, sq-2025): - New shared helper `resolve-source-project-version.js` calls the navigation API. - `transferBranch` resolves the version once per branch and threads it down to `transferBranchBatched` / `uploadReport` and the `ProtobufBuilder` factory. - The `ProtobufBuilder` factory accepts `options.sourceProjectVersion` and `build-metadata.js` reads it with the "1.0.0" fallback. - All call sites (`transferMainBranch`, `transferOneBranch`/`transferSingleBranch`, `transferNonMainBranches`, top-level `runTransferPhases`/`executeTransfer`) forward `sonarQubeClient` so the helper can hit the source API. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
SummaryThis PR fixes Issue The fix introduces a new helper Key detail: The version must be set in both places (protobuf metadata field and form parameter) because SonarCloud's Compute Engine reads from the metadata inside the report zip, not the form parameter. The author's description explains why only fixing one location didn't work. What reviewers should knowStart here:
What to check:
Known gaps:
|
Summary
Closes #137.
The source project version (e.g.
3.20) was systematically migrated to SonarCloud as1.0.0. The fix migrates the real source version, per branch, by queryingGET /api/navigation/component?component=<key>&branch=<name>on the source SonarQube and threading the result through to the scanner report uploaded toapi/ce/submit.Why the obvious fix wasn't enough
The version was hardcoded in two places:
sonar.projectVersionform parameter inapi/ce/submit.projectVersionfield of the protobufmetadatamessage embedded inside the scanner-report zip.SonarCloud's Compute Engine reads the version from the protobuf metadata inside the report — the form parameter is overridden. So fixing only the form parameter still produced
1.0.0. This PR fixes both.Implementation
src/shared/utils/source-version/resolve-source-project-version.jscallsapi/navigation/component, returns theversionstring (trimmed), ornullon error / unset / blank value.branchparam is omitted, so the source's main-branch version is returned regardless of SQ↔SC main-branch name differences.branchis passed through (per-branch versions land per-branch on SC).sq-9.9,sq-10.0,sq-10.4,sq-2025) now:transferBranch(the per-branch upload entry point).sourceProjectVersiontotransferBranchBatched/uploadReport(for the form parameter).ProtobufBuilderfactory options (build-metadata.jsreadsinst.sourceProjectVersion).'1.0.0'if the resolution fails (preserves prior behaviour for unreachable APIs).sonarQubeClientis forwarded throughtransferMainBranch,transferOneBranch/transferSingleBranch,transferNonMainBranches, and the top-levelrunTransferPhases/executeTransferso the helper can hit the source API.Test plan
main(70 pre-existing failures, 0 new). No regressions.docs/regression-testing.md(verify3.20ends up on the SC project, and per-branch versions land on the right branches).🤖 Generated with Claude Code
Note
Medium Risk
Moderate risk because it changes scanner-report metadata and upload parameters across all supported pipeline versions and adds an extra SonarQube API call per branch; failures fall back to the prior
1.0.0behavior.Overview
Fixes project version migration by resolving the real SonarQube project
versionper branch and using it in SonarCloud uploads instead of always sending1.0.0.Adds
resolveSourceProjectVersion(callsGET /api/navigation/component) and threadssourceProjectVersionthrough branch transfer flows insq-9.9,sq-10.0,sq-10.4, andsq-2025, updating both the upload form metadata (version) and the embedded protobufmetadata.projectVersionviaProtobufBuilderoptions.Reviewed by Cursor Bugbot for commit da6f51d. Bugbot is set up for automated code reviews on this repo. Configure here.