dieuhd / sonar-quality-gate

Quality Code Gate for Gitlab and Github
MIT License
38 stars 9 forks source link

feat: Pull Request support if using SonarQube community version with community-branch-plugin installed #55

Closed jsproede closed 10 months ago

jsproede commented 10 months ago

Hello again 😄

We have another Pull Request as we identified that this tool currently is unable to determine the correct issues and Quality Gate data when using SonarQube community version with the community-branch-plugin installed.

The issue is, that if the plugin is installed and enabled in SonarQube, the SonarQube API requires the Pull/Merge Request ID for which the issues and quality gate should be retrieved. The Pull/Merge Request ID can be specified by the query parameter &pullRequest=[ID].

Therefore we've added a new flag (--sonar-branch-plugin or -b), with which the community-branch-plugin support can be enabled in this tool. Then the pullRequest query parameter (we've added a TypeScript type for this matter) will be appended to each SonarQube API request and the Quality Gate Pull/Merge Request decoration comment URLs. We also needed to increase the INTERVAL_SECONDS variable to 5 minutes to be able to retrieve the newly created issues in SonarQube as there is some delay caused by our GitLab CI/CD jobs. 1 minute is not enough. Maybe we should make this configurable too?

I know this is a fairly large change. We've tested the changes with our self-hosted GitLab and SonarQube 10.3 with the community-branch-plugin installed in version 1.16.1 (I hope that official support of SonarQube 10.3 doesn't take too long 🤞). It'd be great if you could test our changes on your end, if you're interested in merging this pull request :)

hblab-dieuhd commented 10 months ago

hi @jsproede

can you show images of result for me?

jsproede commented 10 months ago

hi @jsproede

can you show images of result for me?

Hi @hblab-dieuhd, I'm not sure how to show screenshots of the result 😅 As soon as the Community-Branch Plugin is installed in SonarQube Community Edition, it is required to append the pullRequest Query Parameter to SonarQube's Search API to retrieve the correct issues from the PR analysis. Otherwise the SonarQube API returns issues from the main-branch. The PR decoration in GitLab/GitHub does not look different, the quality-gate-tool simply retrieves the correct issues, if SonarQube has the Community-Branch Plugin installed and the support of this plugin is enabled via --sonar-branch-plugin 😊 The first screenshot I've attached does contain the Pull Requests (Dropdown in SonarQube) for one of our projects. The second one shows the internal HTTP request from SonarQube itself if the plugin is installed where you can see, SonarQube appends automatically the PR number to the API request.

PRs in SonarQube Community Edition Chrome HTTP request from SonarQube

dieuhd commented 10 months ago

:tada: This PR is included in version 1.3.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: