How to verify a PR fixes existing issues before it merges

Setup

  • SonarQube Cloud, public project
  • Scanned from GitHub Actions with SonarSource/sonarqube-scan-action v8.4.0
  • Main branch: develop. PRs scan with the automatic GitHub PR parameters; manual runs scan with -Dsonar.branch.name=<branch>

What I’m trying to do

I have a branch that fixes two existing vulnerabilities reported on develop (jssecurity:S5147 NoSQL injection and jssecurity:S5131 reflected XSS). Before merging, I want SonarQube Cloud to confirm that the branch actually fixes them.

What I see

  • PR analysis: shows 0 new issues, which is good. But the PR stores no issues at all (api/issues/search?pullRequest=<n> returns total: 0), so nothing says the two existing issues were fixed.
  • Branch analysis: the branch was created as SHORT. It analyzed only the changed files (879 lines, versus about 161k on develop) and reports only new issues, so it also shows 0 issues in total. That doesn’t tell me whether the existing ones are gone.
  • IDE: both rules are taint-analysis rules, so SonarQube for IDE can’t confirm them locally either.

As far as I can tell, the only way to see these issues marked as fixed is to merge into develop and wait for its next analysis to close them.

Questions

  1. Is there a way to see which existing issues a PR or short-lived branch fixes before it merges, in the UI or the API?
  2. If not, is the recommended approach a long-lived branch per fix, so that it gets a full analysis and issue tracking? Are there downsides to that?
  3. If neither exists, please treat this as a feature request. Showing “fixed issues” in PR analysis would let us verify security fixes before merging, rather than after they reach the main branch.

Hello Billy,

Your understanding is correct. SonarQube Cloud PR analysis reports issues introduced by the PR, rather than showing which existing issues on the target branch would be fixed by merging it. Short-lived branch analysis follows the same principle. Consequently, an empty PR issue list means no new issues were reported, but it does not confirm that the two vulnerabilities on develop have been fixed.

There is currently no supported UI or API view in SonarQube Cloud that provides that target-branch fixed-issues list for a PR. This capability exists in SonarQube Server, but has not been made available in Cloud. We discussed the same limitation in this earlier topic.

A long-lived branch analysis is a workaround for checking the fixes before merging, where your plan supports branch analysis. It exposes findings for the overall code, so you can inspect the affected files and rules independently of the PR’s new-issue results:

  • Configure a branch name to match your project’s long-lived branch pattern before its first analysis, then run a separate branch analysis on the fix commit.

  • Check the branch’s Overall Code results for the two vulnerabilities. For a clearer before/after comparison, analyze the pre-fix commit on that verification branch first, then analyze the fixed commit.

  • Your existing SHORT branch cannot be converted in place by changing the pattern. Using a fresh verification branch name avoids deleting its existing analysis history.

The tradeoffs are an additional branch analysis and manual cleanup, since long-lived branches are retained until deleted. I would treat this as an occasional verification workaround rather than a requirement to create a long-lived branch for every fix. The branch analysis setup documentation explains the branch-type and retention behavior.

There is already a Fixed issues in pull requests feature request for this. Your need to verify security fixes before merging is a useful example of its value. I don’t have a delivery date to share.

I’d still like to see this feature added. It’s been over a year since I created my topic and 5+ years since the feature request was created. I think it’d be pretty easy to implement at this point with some AI assistance.