feat: allow --sonar-revision with --pull-request to validate analysis commit - #1193
Conversation
|
Claude finished @mbevc1's task in 1m 41s —— View job Follow-up review: status of prior findingsReviewed commit
No new bugs, security issues, or regressions found in the changed lines of Note: I was unable to run Full details posted as a separate summary comment. |
0157bbf to
c27ec6a
Compare
Follow-up review: status of prior findingsChecked
No new inline comments: since the pushed commits didn't change any lines relative to what was already reviewed, there's nothing new to flag within scope. |
SonarQube holds one analysis per pull request, the latest one. Until the scan for the current push is processed, that is the previous push's analysis, and it was being attested against the new commit. When the caller names a revision alongside the pull request, the pull request's analysed commit must now match it. Nothing is checked when no revision is given, so existing callers are unaffected. Refs #1192
The two flags were mutually exclusive, so nothing could ask for the pull request's analysed commit to be checked. They are now accepted together, and the pull request's analysis must then be of the given revision. Only a revision the user set (flag, env var or config) is passed on for a pull-request scan. The flag defaults to the CI commit, which nobody asked to have checked, so existing pull-request attestations are unchanged. Refs #1192
- Note in the comment that only a revision passed alongside --pull-request is checked; on the report-task.txt/--sonar-ce-task-url paths without that flag, sc.revision is the defaulted CI commit, not an expectation to verify. - Pin that gap with a dedicated test: when the pull request is discovered from the CE task response rather than --pull-request, the check does not fire. - Fix the error message's stray trailing space and one-space indent, and drop the redundant third interpolation of the expected revision. - Rename test case 25 to not overstate what it checks: getPRAnalysisRevision reads the expected SHA from the same endpoint the production code reads the actual SHA from, so it is a smoke test for the flag combination, not an independent assertion on the revision.
c0181f4 to
1fc3bc4
Compare
Follow-up review: status of prior findingsReviewed commit
No new bugs, security issues, or regressions found in the changed lines of |
kosli-cli 2.42.0 Created-by: HarmonybrewBot Commit-by: HarmonybrewBot Merged-by: HarmonybrewBot Description: Created by `brew bump` --- Created with `brew bump-formula-pr`.<details> <summary>release notes</summary> <pre># New features - `kosli snapshot s3`: added `--download-concurrency` and `--download-budget` flags to control parallel downloads and peak temporary disk usage when fingerprinting S3 buckets. - `kosli attest sonar`: `--sonar-revision` can now be used together with `--pull-request`; when provided, the command fails if the pull request's latest analysis is not of the specified revision. # Improvements - `kosli snapshot s3`: S3 object keys are no longer used as local file names; each object is downloaded to a temporary file, hashed, and removed, so any valid S3 key can be fingerprinted on any OS. - `kosli get flow` and `kosli list flows`: the `Visibility` field is no longer shown in table output (it is a legacy field with no effect on access). - `kosli list flows`: fixed a panic when a flow has no tags. <!-- Release notes generated using configuration in .github/release.yml at v2.42.0 --> ## What's Changed * ci(kosli): attest SBOMs with the sbom type by @AlexKantor87 in kosli-dev/cli#1186 * feat(snapshot s3): fingerprint S3 buckets from a virtual tree by @mbevc1 in kosli-dev/cli#1180 * fix(ci): wait for staging to settle before picking a server image by @AlexKantor87 in kosli-dev/cli#1190 * feat(snapshot s3): download objects in parallel within a count and byte budget by @mbevc1 in kosli-dev/cli#1191 * feat: allow --sonar-revision with --pull-request to validate analysis commit by @mbevc1 in kosli-dev/cli#1193 * chore(list-flows): drop the VISIBILITY column from the table output by @dangrondahl in kosli-dev/cli#1187 * chore(get-flow): drop the Visibility row from the table output by @dangrondahl in kosli-dev/cli#1188 * fix(snapshot k8s): do not abort the snapshot when a Running pod has an empty imageID by @dangrondahl in kosli-dev/cli#1195 * test(fingerprint): cover OCI capture cleanliness against a fake registry by @mbevc1 in kosli-dev/cli#1197 **Full Changelog**: kosli-dev/cli@v2.41.0...v2.42.0 </pre> <p>View the full release notes at <a href="https://github.com/kosli-dev/cli/releases/tag/v2.42.0">https://github.com/kosli-dev/cli/releases/tag/v2.42.0</a>.</p> </details> <hr> See merge request: Harmonybrew/homebrew-core!20398
What does this PR change and why?
This PR allows users to specify both
--pull-requestand--sonar-revisiontogether when attesting SonarQube pull request scans. Previously, these flags were mutually exclusive.Why this matters: SonarQube keeps only the latest analysis of a pull request. If a scan for the current push hasn't finished processing, the API returns the previous push's analysis. This change lets users validate that the attested analysis is actually of the commit they expect by providing
--sonar-revision. If the pull request's analysis is of a different commit, the command fails with a clear error message.Changes
cmd/kosli/attestSonar.go--sonar-revisionand--pull-requestrevisionExplicitfield to track whether the user explicitly provided--sonar-revisioninternal/sonar/sonar.gopullRequestandrevisionare provided, verify that the returned analysis matches the expected revisioncmd/kosli/attestSonar_test.goprRevisionfield to test suite to capture the actual commit analyzed by the PR scangetPRAnalysisRevision()helper to fetch the PR's analyzed commit from SonarCloudinternal/sonar/sonar_test.go/api/ce/taskendpoint handler to the fake SonarQube serverTestGetSonarResults_PullRequestRevision()covering three scenarios:cmd/kosli/root.gosonarRevisionFlaghelp text to clarify the new behavior with pull requestsFixes #1192
Checklist