Skip to content

Commit 17ccfee

Browse files
committed
gitlabUserUsername variable is not set for MR trigger
1 parent ea1ea43 commit 17ccfee

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/merge/MergeRequestHookTriggerHandlerImpl.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,9 @@ protected CauseData retrieveCauseData(MergeRequestHook hook) {
196196
.withTargetProjectId(hook.getObjectAttributes().getTargetProjectId())
197197
.withBranch(hook.getObjectAttributes().getSourceBranch())
198198
.withSourceBranch(hook.getObjectAttributes().getSourceBranch())
199-
.withUserName(
200-
hook.getObjectAttributes().getLastCommit().getAuthor().getName())
201-
.withUserEmail(
202-
hook.getObjectAttributes().getLastCommit().getAuthor().getEmail())
199+
.withUserName(hook.getUser().getName())
200+
.withUserUsername(hook.getUser().getUsername())
201+
.withUserEmail(hook.getUser().getEmail())
203202
.withSourceRepoHomepage(hook.getObjectAttributes().getSource().getHomepage())
204203
.withSourceRepoName(hook.getObjectAttributes().getSource().getName())
205204
.withSourceNamespace(hook.getObjectAttributes().getSource().getNamespace())

src/test/java/com/dabsquared/gitlabjenkins/trigger/handler/PendingBuildsHandlerTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ private MergeRequestHook mergeRequestHook(int projectId, String branch, String c
212212
.withProject(ProjectBuilder.project()
213213
.withWebUrl("https://gitlab.org/test.git")
214214
.build())
215+
.withUser(user().withId(1)
216+
.withName("User")
217+
.withUsername("user")
218+
.withEmail("[email protected]")
219+
.withAvatarUrl(
220+
"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon")
221+
.build())
215222
.build();
216223
}
217224

src/test/java/com/dabsquared/gitlabjenkins/trigger/handler/merge/MergeRequestHookTriggerHandlerImplTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,13 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
429429
.withProject(project()
430430
.withWebUrl("https://gitlab.org/test.git")
431431
.build())
432+
.withUser(user().withId(1)
433+
.withName("User")
434+
.withUsername("user")
435+
.withEmail("[email protected]")
436+
.withAvatarUrl(
437+
"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon")
438+
.build())
432439
.build(),
433440
true,
434441
BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
@@ -452,6 +459,13 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
452459
.withProject(project()
453460
.withWebUrl("https://gitlab.org/test.git")
454461
.build())
462+
.withUser(user().withId(1)
463+
.withName("User")
464+
.withUsername("user")
465+
.withEmail("[email protected]")
466+
.withAvatarUrl(
467+
"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon")
468+
.build())
455469
.build(),
456470
true,
457471
BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
@@ -541,6 +555,13 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
541555
.withProject(project()
542556
.withWebUrl("https://gitlab.org/test.git")
543557
.build())
558+
.withUser(user().withId(1)
559+
.withName("User")
560+
.withUsername("user")
561+
.withEmail("[email protected]")
562+
.withAvatarUrl(
563+
"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon")
564+
.build())
544565
.build(),
545566
true,
546567
BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
@@ -575,6 +596,13 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
575596
.withId("testid")
576597
.build())
577598
.build())
599+
.withUser(user().withId(1)
600+
.withName("User")
601+
.withUsername("user")
602+
.withEmail("[email protected]")
603+
.withAvatarUrl(
604+
"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon")
605+
.build())
578606
.build(),
579607
true,
580608
BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),

src/test/java/com/dabsquared/gitlabjenkins/webhook/build/MergeRequestBuildActionTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.dabsquared.gitlabjenkins.webhook.build;
22

33
import static com.dabsquared.gitlabjenkins.cause.CauseDataBuilder.causeData;
4+
import static org.hamcrest.CoreMatchers.containsString;
45
import static org.hamcrest.MatcherAssert.assertThat;
56
import static org.hamcrest.Matchers.is;
67
import static org.hamcrest.Matchers.notNullValue;
@@ -107,6 +108,9 @@ public void build() throws IOException {
107108
verify(mockTrigger).onPost(pushHookArgumentCaptor.capture());
108109
assertThat(pushHookArgumentCaptor.getValue().getProject(), is(notNullValue()));
109110
assertThat(pushHookArgumentCaptor.getValue().getProject().getWebUrl(), is(notNullValue()));
111+
assertThat(pushHookArgumentCaptor.getValue().getUser(), is(notNullValue()));
112+
assertThat(pushHookArgumentCaptor.getValue().getUser().getName(), containsString("Administrator"));
113+
assertThat(pushHookArgumentCaptor.getValue().getUser().getUsername(), containsString("root"));
110114
}
111115
}
112116

0 commit comments

Comments
 (0)