Uh oh!
There was an error while loading. Please reload this page.
Fix missing gitlabUserUsername definition for MR and Note triggers - #1469
Fix missing gitlabUserUsername definition for MR and Note triggers#1469ljackiewicz wants to merge 13 commits into
Conversation
8c8d0da to
02cba11CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
ljackiewicz
commented
May 17, 2023
It seems that the jenkins build didn't run for the last changes added, is there any way to trigger it manually? |
472cd77 to
82a1838Comparekrisstern
commented
May 29, 2023
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
c39ff4dCompare
krisstern
left a comment
There was a problem hiding this comment.
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.
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.
I think these are the tests we need for this PR I guess, which I have added/updated.
ljackiewicz
commented
May 30, 2023
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 |
| .withSourceBranch(hook.getObjectAttributes().getSourceBranch()) | ||
| .withUserName( | ||
| hook.getObjectAttributes().getLastCommit().getAuthor().getName()) | ||
| .withUserUsername(hook.getUser().getUsername()) |
There was a problem hiding this comment.
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.
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).
krisstern
commented
May 30, 2023
Then if we were to follow your logic the test cases below will need to be changed as well to include the username: |
ljackiewicz
commented
May 30, 2023
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. |
krisstern
commented
May 30, 2023
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. |
ljackiewicz
commented
Jun 15, 2023
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? |
krisstern
commented
Jun 27, 2023
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. |
krisstern
commented
Jul 30, 2023
Any updates? @ljackiewicz |
ljackiewicz
commented
Aug 27, 2023
@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. |
zeteref
commented
Sep 17, 2023
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. |
ljackiewicz
commented
Nov 16, 2023
@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).