-
Notifications
You must be signed in to change notification settings - Fork 618
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
Fix missing gitlabUserUsername definition for MR and Note triggers #1469
base: master
Are you sure you want to change the base?
Fix missing gitlabUserUsername definition for MR and Note triggers #1469
Conversation
8c8d0da
to
02cba11
Compare
...a/com/dabsquared/gitlabjenkins/trigger/handler/merge/MergeRequestHookTriggerHandlerImpl.java
Outdated
Show resolved
Hide resolved
src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/note/NoteHookTriggerHandlerImpl.java
Outdated
Show resolved
Hide resolved
src/test/java/com/dabsquared/gitlabjenkins/webhook/build/NoteBuildActionTest.java
Show resolved
Hide resolved
src/test/java/com/dabsquared/gitlabjenkins/webhook/build/MergeRequestBuildActionTest.java
Outdated
Show resolved
Hide resolved
It seems that the jenkins build didn't run for the last changes added, is there any way to trigger it manually? |
472cd77
to
82a1838
Compare
Thanks @ljackiewicz! Let me do a review of your PR now. Will get back to you within a few hours. |
…nto fix/missing-defined-variables
82a1838
to
c39ff4d
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.
Looks okay so far... @ljackiewicz If it looks okay to you too I will merge it as is.
assertThat(pushHookArgumentCaptor.getValue().getUser(), is(notNullValue())); | ||
assertThat(pushHookArgumentCaptor.getValue().getUser().getName(), containsString("Administrator")); | ||
assertThat(pushHookArgumentCaptor.getValue().getUser().getUsername(), containsString("root")); |
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.
Actually this only checks for when the User's name contains "Administrator" and the User's username is "root" by design. But there should be no harm done by adding this code snippet.
.withUserName("User") | ||
.withUserUsername("username") | ||
.withUserEmail("user@gitlab.com") |
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 think these are the tests we need for this PR I guess, which I have added/updated.
Thanks for the code review and your comments, but unfortunately, it's not look okay to me, because now this PR does not fix described problem and I'm not quiet sure why the proposed changes were overwritten. I tried to explain it above, but though the User object has a username field defined and we can call the getUsername method on it, this value is not set for the author of the commit, the GitLab webhook passes only the name and email (if the email is set to public for the GitLab account) values. Example request for MR Event: https://github.com/jenkinsci/gitlab-plugin/blob/master/src/test/resources/com/dabsquared/gitlabjenkins/webhook/build/MergeRequestEvent.json#L63 Example request for Note Event: https://github.com/jenkinsci/gitlab-plugin/blob/master/src/test/resources/com/dabsquared/gitlabjenkins/webhook/build/NoteEvent.json#L102 So the |
@@ -198,6 +198,7 @@ protected CauseData retrieveCauseData(MergeRequestHook hook) { | |||
.withSourceBranch(hook.getObjectAttributes().getSourceBranch()) | |||
.withUserName( | |||
hook.getObjectAttributes().getLastCommit().getAuthor().getName()) | |||
.withUserUsername(hook.getUser().getUsername()) |
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.
If the UserUsername
cannot be returned here with hook.getObjectAttributes().getLastCommit().getAuthor().getUsername()
then we will need some upstream changes. I don't think we are supposed to stray from the pattern prescribed, as the suggested hook.getUser().getUsername()
would obviously return something not related to the Last Commit Author.
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.
Yeah, and I mentioned that it can be confusing that gitlabUserName and gitlabUserUsername can represent two different persons.
It was probably a mistake that the author of the last commit was set as the author of the merge request (in case of MR Event) or comment (in case of Note Event).
Then if we were to follow your logic the test cases below will need to be changed as well to include the username:
|
It's not a mistake in existing test cases, these represent very well the real ones. I don't know why, but the GitLab webhook will never pass the username value of an author of the commit by design. |
It is exactly my point. I don't mean there are mistakes in the existing test cases, but if your code works we will need to update as well as pass the new tests as well. Maybe we could work together to figure something out. |
I misunderstand you then, and maybe I'm a bit stubborn, but I would like to ask do you completely rejecting an idea to make some breaking changes to the project and add gitlabLastCommiterName and gitlabLastCommiterEmail variables mentioned earlier and change the values of the gitlabUserName and gitlabUserEmail variables? |
Hi @ljackiewicz Actually I think it would be good to have the both the gitlab last committer name and gitlab username as variables. I am not sure if this would be breaking though (it probably is) but will need to see how other parts of the codebase is impacted with this change. |
Any updates? @ljackiewicz |
@krisstern Unfortunately, I don't currently have enough time to make these changes, but I think I will try to do it as soon as possible. |
Hi, i have encountered a small bug related to this change. If a MR is created from tag/commitid instead of a branch hook.getObjectAttributes().getLastCommit().getAuthor().getUsername() raises nullpointerexception. |
@zeteref Can you provide some more information about the problem you encountered, and are you sure that you describe it well? Because there are nowhere in code call of hook.getObjectAttributes().getLastCommit().getAuthor().getUsername(). It was just krisstern's suggestion, but since this call will always return null, it should never be used. I understand that you manually built and installed the plugin based on changes provided in this PR? |
It seems that gitlabUserUsername variable is not set in case of build triggered by MergeRequest event and Note (comments) event.
Additionally, gitlabUserName and gitlabUserEmail variables for these triggers (MR and Note) was changed to their real values from GitLab webhooks. In case of MR Event user is an author of specific MR, and in case of Note (Comments) Event user is an author of specific comment in MR, not author of last commit.
The proposed changes have been checked on a local GitLab instance (launched from src/docker).