0167: Sonar ratings judge a pull request's new code; main carries the overall bar¶
- Implementation built
Context and Problem Statement¶
The Sonar ratings job read the project-wide reliability, security and maintainability ratings of main's latest
SonarCloud analysis, and CI OK requires it on every pull request. Once main fell below A, every pull request failed,
including the one that fixes it. SonarCloud's pull request analyses carry only new-code measures. No ADR covered this
gate. What should a pull request be judged on, and where does the bar for the whole project live?
Decision Drivers¶
- A pull request is judged on what it changes, and the fix for a sub-A main can merge.
- A sub-A main stays visible and has an owner; no answer from SonarCloud is never a pass.
- No manual exemption and no verdict that depends on fragile analysis history.
Considered Options¶
- Two parts: the pull request's new code must be A; main's overall ratings warn on a pull request and fail on a push to main (chosen)
- A ratchet against the base analysis: the history lookup is fragile and ties the verdict to analysis timing.
- An exemption label: manual and easy to abuse.
Decision Outcome¶
Chosen option: two parts, because the pull request answers for its own code and main still answers for the whole.
- On a pull request the job polls, for a bounded time, until SonarCloud reports an analysis of this pull request's head SHA; without one it is a TOOL ERROR. Then the new-code reliability, security and maintainability ratings of that analysis must all be A.
- The pull request also adds no open vulnerability or bug (each one is named), and its own security and reliability ratings are A, so merging it cannot drop main's overall rating below A (0.9.59: main went to security C while the gate passed).
- Main's overall ratings are read too: all A passes; below A passes with a warning that names the rating.
- On a push to main the same job requires the overall ratings to be A and fails red otherwise.
Consequences¶
- Good: a sub-A main no longer blocks every pull request, and the fix merges through the normal gate.
- Bad: a sub-A main is no longer stopped by the next pull request; the red main run and the warning must be owned.
- Bad: the pull request job waits for SonarCloud's analysis, up to its polling bound.
Confirmation¶
The unit tests of the ratings script pin the four verdicts (new code A with main below A passes and warns, new code B fails, an added vulnerability or a sub-A own rating fails, a missing or stale analysis is a tool error, a sub-A main run fails), and the coverage floor tests pin the job's events and inputs in the CI workflow.