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

Correctly report coverage back to Gitlab #145

Closed
wants to merge 11 commits into from

Conversation

teake
Copy link
Contributor

@teake teake commented Mar 26, 2020

GitLab does not have a concept of 'new' coverage, only that of total coverage.
As such, SonarQube should report back the total coverage.

In addition, reporting coverage back is optional, see
https://docs.gitlab.com/ee/api/commits.html#post-the-build-status-to-a-commit.
So if there is no coverage information, we do not report it back.

mc1arke and others added 11 commits February 2, 2020 21:53
Sonarqube 8.1 removed the concept of short and long lived branches, instead simplifying the setup to either `BRANCH` or `PULL_REQUEST`. This release of Sonarqube also moved the management of Pull Request decoration into a standard User Interface calling a set of 'ALM' services that provide the management of decorators, and the binding of each project to these decorators. However the implementation of these services is not included in the Community Edition of Sonarqube, although the UI is made visible based on the presence of the branch management components provided by this plugin.

This change therefore introduces the services required to support UI components for the management of Pull Request decoration, as well as updating the handling of the configuration and loading of branches to support the removal of the SHORT/LONG branch constructs. As these changes require the reference of classes that were not present in older version of Sonarqube (namely `AlmSettingsDao` and `ProjectAlmSettingsDao`), the compatibility interfaces for these versions have been removed, as well as any methods and classes that existed purely to allow these versions to be supported by this plugin.

Given the standard UI provides a restricted set of fields for creating and binding each Pull Request decorator, some of the patterns that were previously used by this plugin for configuring the decoration of Pull Requests do not fit into this UI, and were awkward to find/manage when moved to another screen in the UI. This results in the configuration for disabling the addition and removing of comments on Merge Requests being removed from the plugin, with the Gitlab decorator removing the deleting of old comments since this was leading to discussion boxes being shown in Gitlab with no content, and the BitBucket decorator removing since it can't work out which user posted comments based purely on the configuration provided by Sonarqube.

To ensure the UI works for all configuration options, the services for configuring and binding Azure DevOps configuration have been included in this change-set, although no decorator currently exists for this ALM, so any project attempting to use this configuration will get a warning appear in the CE logs when attempting to use this decorator. Similarly, as the UI does not provide any options for configuring the URL for the Gitlab API, or the Slug/name of the project on the binding, a `Sensor` has been added into the scanner to detect these properties from injection by the Gitlab CI Runner, as well as injection directly from scanner arguments of `com.github.mc1arke.sonarqube.plugin.branch.pullrequest.gitlab.url` and `com.github.mc1arke.sonarqube.plugin.branch.pullrequest.gitlab.repositorySlug` for the repository URL and repository-name configuration entries.
The Github ALM Binding Web Service uses the `AlmRepo` field to store the repository name, but the Github decorator was using `AlmSlug` to try and retrieve the repository name, so was getting a `null` value back and failing to find a matching repository. Switching to using `AlmRepo` in the decorator overcomes this issues.
GitLab does not have a concept of 'new' coverage, only that of total coverage.
As such, SonarQube should report back the total coverage.

In addition, reporting coverage back is optional, see
https://docs.gitlab.com/ee/api/commits.html#post-the-build-status-to-a-commit.
So if there is no coverage information, we do not report it back.
@teake
Copy link
Contributor Author

teake commented Mar 26, 2020

Note that I haven't updated the tests accordingly, so they might fail. I have tested it on my SonarQube instance, and it seems to work correctly.

@mc1arke
Copy link
Owner

mc1arke commented Apr 20, 2020

Please rebase this onto the latest head of your target branch

@teake
Copy link
Contributor Author

teake commented Apr 20, 2020

Not a big fan of the whole rebase + force push -> rewriting history thing, so I've created a new PR to supersede this one: #157.

@teake teake closed this Apr 20, 2020
@teake teake deleted the correct-coverage branch August 7, 2020 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants