- Sonarqube 9.1 with Github
- Using Github Flow where all PRs are targetting main branch
- Using “Previous version” as New Code definition
I have been looking for hours and I’m still not clear on how New Code is defined in the context of PRs in the following scenario I have:
- PR with initial commit is submitted for scan via a CI pipeline by developer. Quality Gate fails due to 0% coverage on 10 new lines to cover.
- After first scan, more commits are done to the same PR with added coverage (although not for all lines that need it) and other fixes/changes.
- PR is again submitted for scan. Quality Gate fails again with 0% coverage, but now on 8 new lines to cover.
Why is coverage still 0% when coverage was added after it failed the Quality Gate the first time? I would expect it to increase based on the added coverage, even if it didn’t pass. There is definitely coverage added on the PR.
How does Sonar define new code in this situation where PR branch has multiple scans with different changes?
I thought Sonar could be considering new code after every scan, but this is clearly not the case as one of the new lines requiring coverage on the latest scan was submitted during the initial commit.
Unfortunately, Sonar doesn’t keep history of previous scans for the same PR so I cannot compare to see what it was complaining about on the first scan (and we unfortunately don’t remember).
As a related side note, what is the recommended way to set up New Code definition as for a project using Github Flow (merging everything to main branch). Would it be better to use “Reference Branch” (chose main branch as reference for the New Code)?