PR Vs Branch Analysis

Must-share information (formatted with Markdown):

  • SonarQube Version 9.9.1 LTS
  • Saas - https://mrv-sonarqube.mahindra.com/
  • Issue difference found in PR Analysis and New Code of Branch analysis
  • For a same file , which has only line deletion, the issue count (Code smell) differs in PR and branch analysis. PR analysis didnt report any issue whereas branch analysis identifies issues in New Code segment.

New Code baseline set as 1day and the PR is raised within that timelimit

PR :

Branch :

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

Hi @Megala_Natarajan ,

the PR analysis will only analyze changed lines, whereas the branch analysis analyses the whole file.

In this case the issues do not occur on any changed line, they are just a consequence of changes on other lines in that file. Because of this the PR analysis won’t find them.

For the branch analysis, analyzing the whole file, these issues are new, as they occured in the defined new code period.

I hope this helps, I was confused by this behaviour as well when it occured to me the first time.

Regards,
Carsten

1 Like

Thanks for the response. It makes things very clear.

Hi everyone. Sorry to “hijack” this elderly thread but we experience same issues (code deletion in a Pull Request) and are regularly facing a somewhat sudden quality gate failures on the target branch after such PR has been merged. A specific example:

Class Example {
  public function doThings() {
     $res = $this->heavyPerformanceTask();
     if ($res === null) {
        // do something
     }
  }
}

In our case the if statement was removed but the PR analysis did not detect that $res = $this→heavyPerformanceTask(); creates an issue related to unused variable. This issue only popped up after merge.

In our understanding the PR is the issue creator so such issues should be reported in the Pull Request prior to merging.

Thanks for (hopefully) replying to such an old thread.

Regards,

Steven