-
-
Notifications
You must be signed in to change notification settings - Fork 523
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
Add support for decorating Pull Requests (Gitlab Server) #34
Conversation
cdc5117
to
fa0b186
Compare
I think this is great to start with, I would probably implement deletion of old comments just because (as you can see from your examples), you'll get a lot of comments. :) One thing I definitely miss is opening and closing discussions based on new sonar smells, which makes code review a lot easier. You could then:
But there are a bunch of corner cases so I'd rather do that separately. :) |
Deletion of old comments is already implemented. Will look into "real discussions" next week. |
fa0b186
to
872fadf
Compare
Rebased against the changes from #31 |
f053ed7
to
3eb5def
Compare
@tisoft Could you rebase this against the updated base branch please? |
Merged in the new changes. Compiles and runs again. I changed the visibility of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution!
Is there any reason you've made your changes on-top of Bitbucket decoration changes? It makes it a bit more difficult to review and unpick any issues.
Please add some tests to cover your new code. When we get to the point where I'm having to manage changes in Sonarqube and different providers (Gitlab, Bitbucket, Github, Azure, etc) APIs, I'm not going to have time to exhaustively check all the edge cases for each provider, so need there to be a high coverage of automated tests to do this.
For my comment on one of your classes and Json deserialisation, this also applies to other classes in your code, but I dind't want to spam the Pull Request, so you'll want to check all your JSON model classes.
Shout if you have any questions or disagree with my comments.
src/main/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPlugin.java
Outdated
Show resolved
Hide resolved
src/main/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPlugin.java
Outdated
Show resolved
Hide resolved
src/main/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/AnalysisDetails.java
Outdated
Show resolved
Hide resolved
src/main/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/AnalysisDetails.java
Outdated
Show resolved
Hide resolved
.../github/mc1arke/sonarqube/plugin/ce/pullrequest/gitlab/GitlabServerPullRequestDecorator.java
Outdated
Show resolved
Hide resolved
.../github/mc1arke/sonarqube/plugin/ce/pullrequest/gitlab/GitlabServerPullRequestDecorator.java
Show resolved
Hide resolved
.../github/mc1arke/sonarqube/plugin/ce/pullrequest/gitlab/GitlabServerPullRequestDecorator.java
Outdated
Show resolved
Hide resolved
.../github/mc1arke/sonarqube/plugin/ce/pullrequest/gitlab/GitlabServerPullRequestDecorator.java
Outdated
Show resolved
Hide resolved
.../github/mc1arke/sonarqube/plugin/ce/pullrequest/gitlab/GitlabServerPullRequestDecorator.java
Outdated
Show resolved
Hide resolved
src/main/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/gitlab/response/Commit.java
Outdated
Show resolved
Hide resolved
3eb5def
to
e808a9d
Compare
@mc1arke thanks for the review! Will have a look into the issues next year🎇. |
e808a9d
to
ce99b08
Compare
d94425a
to
807e3cd
Compare
Where can I get the configuration settings, that are used by the "official" plugin, so that I can reuse the configuration names for those? (Will add testcases as soon as the other review items are resolved) |
3114ac2
to
42ce3bd
Compare
f84dacf
to
6ebd6e0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only major issue with this is the lack of unit or integration tests. I've not tried running it yet, but the code looks like it's doing what I'd expect.
src/main/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPlugin.java
Outdated
Show resolved
Hide resolved
src/main/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/AnalysisDetails.java
Outdated
Show resolved
Hide resolved
src/main/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPlugin.java
Outdated
Show resolved
Hide resolved
src/main/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPlugin.java
Outdated
Show resolved
Hide resolved
src/main/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPlugin.java
Outdated
Show resolved
Hide resolved
SonarSource no longer seem to document the properties used for configuring each Pull Request provider. I'll see if I can confirm what they've used for Gitlab, but am happy you use the names you've suggested given they seem sensible. |
The changes for Github and Bitbucket decoration have now been merged into the target pr-decoration branch. This has caused some conflicts against your changes in common files, and also needs updates in your changes for some constants that @4n4n4s created for the properties shared between your 2 changes. Could you rebase your MR and resolve these conflicts please? |
beeac00
to
7a9fceb
Compare
Rebased, will now cleanup and add tests |
LOGGER.info(String.format("Commits in MR: %s ", commits.stream().map(Commit::getId).collect(Collectors.joining(", ")))); | ||
List<CommitDiscussion> commitDiscussions = new ArrayList<>(); | ||
for (Commit commit : commits) { | ||
getCommitDiscussions(projectURL + String.format("/repository/commits/%s/discussions", commit.getId()), headers, deleteCommentsEnabled) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the difference between creating discussions on MR's commits VS directly on MR?
there's an API for creating discussions or MR directly: https://docs.gitlab.com/ee/api/discussions.html#create-new-merge-request-thread
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am unsure about the difference between the 2 APIs. The one I'm using also creates a discussion, that can be replied to.
I will also try the MR discussion API out, to see if that has any differences. But I want to rebase, cleanup and test the current code before I do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see that with the commit comments.
I will play around with the MR discussions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have played around with MR discussions. code and result can be seen here: https://gitlab.com/tisoft/sonarqube-community-branch-plugin-gitlab-test/merge_requests/1
Resolving of discussions is currently not done by the plugin, it will delete all discussions and recreate them at each run.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, looks awesome, well done! 💯 💪
may I suggest adding a link to Sonar issue and/or Sonar rule? 👼
I would also try creating discussions first, and then creating MR comment with summary, so that would also be at the end (before user comments, of course). What do you think?
not sure if it's something on my end (tried also incognito), but images aren't loading for me:
other than that, looks really nice, thanks for trying this out! 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I like having the summary on top, so that I have a quick overview and don't need to do endless scrolling before I can get to that.
Images are loaded from the github master branch of this repo, and since this is not yet merged into master, there are no images yet. The contents of the summary and issue comments is shared between all the decoration implementations, I don't want to change that as part as of this PR, but I agree that a link back to sonar would be helpful. Will do a followup PR as soon as everything else is settled.
If you click on the failed pipeline marker on the righrt and then on SonarQube, you are send to the sonar instance. (which will not work since its running on localhost on my machine 😆)
a115f77
to
6d008a0
Compare
* set build status * add a summery comment * add file comments * delete all previous comments Notes: * Deleting comments will delete all comments from the commits made by the specified user, so this is only usefull if there is a dedicated sonar user configured in gitlab
6d008a0
to
659a7e5
Compare
Is this ready for final review and merge? If so, please remove the 'WIP' from the title. |
Its now ready from my point of view. I have changed it to use merge request discussions instead of file comments, since MR discussions look better in the gitlab merge request views. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 very minor comments which it would be nice to fix if you get a chance, but wont block me merging this later today if you don't get round to it.
.../github/mc1arke/sonarqube/plugin/ce/pullrequest/gitlab/GitlabServerPullRequestDecorator.java
Outdated
Show resolved
Hide resolved
.../github/mc1arke/sonarqube/plugin/ce/pullrequest/gitlab/GitlabServerPullRequestDecorator.java
Outdated
Show resolved
Hide resolved
fixed your comments in a new commit for easier review. feel free to squash all commits into a single one. |
@tisoft how does the repository slug configuration works? I only see the parameter available in global administration settings and not in the project settings. How can I analyse several GitLab repositories with the plugin? |
@tisoft thanks! I wasn't looking in the right place |
@tisoft des it work with SonarQube 8.0 or do we need 8.1? I can't trigger the MR decoration on my projects. I'm running a Maven build from GitLab CI with The branch analysis is performed, but nothing happens concerning the decoration. I have configured GitLab host and acces token in global settings, project slug in project settings, and sonar.pullrequest.* parameters on the command line. Am I missing something? In TRACE level I can see this in ce.log:
EDIT: I've found the problem, my command line also contained the parameter |
Based on the work of @4n4n4s in #31 I've implemented the pull request decoration for gitlab. It's work in progress currently. Output can be seen here: https://gitlab.com/tisoft/sonarqube-community-branch-plugin-gitlab-test/merge_requests/1
Current features:
I will try to switch to conversations instead of notes/comments and see how they behave. Maybe both can be supported. Still playing around with this. 😄