Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
gitlabUserUsername variable is not set for Note (comments) trigger
  • Loading branch information
ljackiewicz committed May 10, 2023
commit 02cba115f1d2faabc7eb72cd109e6848af7758d0
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("[email protected]")
.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