Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mc1arke opened this issue Aug 12, 2024 · 1 comment
Closed

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

mc1arke opened this issue Aug 12, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@mc1arke
Copy link
Owner

mc1arke commented Aug 12, 2024

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

  • SonarQube Version: 10.6
  • Plugin Version: 1.21.0

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 mc1arke added the bug Something isn't working label Aug 12, 2024
mc1arke added a commit that referenced this issue Aug 13, 2024
Sonarqube currently reports a fixed issues metric for pull requests, but
the plugin isn't providing the data to allow that value to be
calculated. To resolve this an additional IssueVisitor has been
introduced that compares the issues from the target branch with the
findings on the source branch and finds any target code blocks that no
longer exists - implying the issue line has been removed - or any code
that still exists but is now reporting the issue as fixed, and reports
them to the PullRequestFixedIssuesRepository which is used within
Sonarqube to gather the count of issues fixed in the current analysis.
mc1arke added a commit that referenced this issue Aug 18, 2024
Sonarqube currently reports a fixed issues metric for pull requests, but
the plugin isn't providing the data to allow that value to be
calculated. To resolve this an additional IssueVisitor has been
introduced that compares the issues from the target branch with the
findings on the source branch and finds any target code blocks that no
longer exists - implying the issue line has been removed - or any code
that still exists but is now reporting the issue as fixed, and reports
them to the PullRequestFixedIssuesRepository which is used within
Sonarqube to gather the count of issues fixed in the current analysis.
mc1arke added a commit that referenced this issue Aug 18, 2024
Sonarqube currently reports a fixed issues metric for pull requests, but
the plugin isn't providing the data to allow that value to be
calculated. To resolve this an additional IssueVisitor has been
introduced that compares the issues from the target branch with the
findings on the source branch and finds any target code blocks that no
longer exists - implying the issue line has been removed - or any code
that still exists but is now reporting the issue as fixed, and reports
them to the PullRequestFixedIssuesRepository which is used within
Sonarqube to gather the count of issues fixed in the current analysis.
@mc1arke mc1arke added the awaiting release Merged but not currently in release vesrion label Aug 18, 2024
@mc1arke
Copy link
Owner Author

mc1arke commented Sep 7, 2024

Released in 1.22.0

@mc1arke mc1arke closed this as completed Sep 7, 2024
@mc1arke mc1arke removed the awaiting release Merged but not currently in release vesrion label Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant