mc1arke / sonarqube-community-branch-plugin

A plugin that allows branch analysis and pull request decoration in the Community version of Sonarqube
GNU Lesser General Public License v3.0
2.26k stars 526 forks source link

Fixed Issues is always shown at 0 on Pull Requests #945

Closed mc1arke closed 2 months ago

mc1arke commented 3 months ago

Describe the bug When reporting on the results of a pull request, Sonarqube reports a Fixed issues statistic on the Pull Request overview page, but this always appears as 0, regardless of the number of issues fixed.

To Reproduce

  1. Submit a branch (e.g. master) for analysis with some findings in it, such as using System.err.println rather than a logger
  2. Ensure Sonarqube shows the issue in the branch overview
  3. Create another branch from master and 'fix' those issues, such as switching to using a logger or removing the problem lines
  4. Analyse the changed commit, reporting it as a Pull Request to Sonarqube, with the base branch as the branch from step 1
  5. Open the overview page for the pull request, and check the Fixed issues panel

Expected behaviour The fixed issues panel should show a number that reflects the number of issues fixed (i.e. not 0 in the above case)

Screenshots

image

Software Versions

Additional context The Fixed issues metric is exposed in the component API as a metric with key pull_request_fixed_issues:

curl 'http://sonar.local:9000/api/measures/component?additionalFields=metrics&component=<snip>&metricKeys=pull_request_fixed_issues&pullRequest=1' \ 
  -H 'Accept: application/json' \
  -H 'Cookie: XSRF-TOKEN=<snip>; JWT-SESSION=<snip>'

The metric is set by PullRequestFixedIssuesMeasureStep reading from PullRequestFixedIssueRepository, with the repository just being an in-memory store for a list of issues. As PullRequestFixedIssuesMeasureStep is invoked after any IssueVisitor, implementing onRawIssues with some filtering/comparison between baseIssues and rawIssues looks like a potential solution.

mc1arke commented 2 months ago

Released in 1.22.0