Skip to content

Commit

Permalink
gitlabUserUsername variable is not set for Note (comments) trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
ljackiewicz committed May 9, 2023
1 parent 17ccfee commit 8c8d0da
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ protected CauseData retrieveCauseData(NoteHook hook) {
.withTargetProjectId(hook.getMergeRequest().getTargetProjectId())
.withBranch(hook.getMergeRequest().getSourceBranch())
.withSourceBranch(hook.getMergeRequest().getSourceBranch())
.withUserName(hook.getMergeRequest().getLastCommit().getAuthor().getName())
.withUserEmail(
hook.getMergeRequest().getLastCommit().getAuthor().getEmail())
.withUserName(hook.getUser().getName())
.withUserUsername(hook.getUser().getUsername())
.withUserEmail(hook.getUser().getEmail())
.withSourceRepoHomepage(hook.getMergeRequest().getSource().getHomepage())
.withSourceRepoName(hook.getMergeRequest().getSource().getName())
.withSourceNamespace(hook.getMergeRequest().getSource().getNamespace())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
.withWebUrl("https://gitlab.org/test.git")
.build())
.build())
.withUser(user().withId(1)
.withName("User")
.withUsername("user")
.withEmail("user@gitlab.com")
.withAvatarUrl(
"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon")
.build())
.build(),
true,
BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.dabsquared.gitlabjenkins.webhook.build;

import static com.dabsquared.gitlabjenkins.cause.CauseDataBuilder.causeData;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;

Expand Down Expand Up @@ -28,6 +32,7 @@
import org.jvnet.hudson.test.JenkinsRule;
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.StaplerResponse;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

Expand Down Expand Up @@ -68,13 +73,19 @@ public void setup() throws Exception {

@Test
public void build() throws IOException {
FreeStyleProject testProject = jenkins.createFreeStyleProject();
testProject.addTrigger(trigger);

exception.expect(HttpResponses.HttpResponseException.class);
new NoteBuildAction(testProject, getJson("NoteEvent.json"), null).execute(response);

verify(trigger).onPost(any(NoteHook.class));
try {
FreeStyleProject testProject = jenkins.createFreeStyleProject();
testProject.addTrigger(trigger);

exception.expect(HttpResponses.HttpResponseException.class);
new NoteBuildAction(testProject, getJson("NoteEvent.json"), null).execute(response);
} finally {
ArgumentCaptor<NoteHook> noteHookArgumentCaptor = ArgumentCaptor.forClass(NoteHook.class);
verify(trigger).onPost(noteHookArgumentCaptor.capture());
assertThat(noteHookArgumentCaptor.getValue().getUser(), is(notNullValue()));
assertThat(noteHookArgumentCaptor.getValue().getUser().getName(), containsString("Administrator"));
assertThat(noteHookArgumentCaptor.getValue().getUser().getUsername(), containsString("root"));
}
}

@Test
Expand Down

0 comments on commit 8c8d0da

Please sign in to comment.