Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,9 @@ protected CauseData retrieveCauseData(MergeRequestHook hook) {
.withTargetProjectId(hook.getObjectAttributes().getTargetProjectId())
.withBranch(hook.getObjectAttributes().getSourceBranch())
.withSourceBranch(hook.getObjectAttributes().getSourceBranch())
.withUserName(
hook.getObjectAttributes().getLastCommit().getAuthor().getName())
.withUserEmail(
hook.getObjectAttributes().getLastCommit().getAuthor().getEmail())
.withUserName(hook.getUser().getName())
.withUserUsername(hook.getUser().getUsername())
Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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).

.withUserEmail(hook.getUser().getEmail())
Comment thread
krisstern marked this conversation as resolved.
Outdated
.withSourceRepoHomepage(hook.getObjectAttributes().getSource().getHomepage())
.withSourceRepoName(hook.getObjectAttributes().getSource().getName())
.withSourceNamespace(hook.getObjectAttributes().getSource().getNamespace())
Expand Down
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())
Comment thread
krisstern marked this conversation as resolved.
Outdated
.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 @@ -212,6 +212,13 @@ private MergeRequestHook mergeRequestHook(int projectId, String branch, String c
.withProject(ProjectBuilder.project()
.withWebUrl("https://gitlab.org/test.git")
.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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,13 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
.withProject(project()
.withWebUrl("https://gitlab.org/test.git")
.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 All @@ -452,6 +459,13 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
.withProject(project()
.withWebUrl("https://gitlab.org/test.git")
.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 Expand Up @@ -541,6 +555,13 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
.withProject(project()
.withWebUrl("https://gitlab.org/test.git")
.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 Expand Up @@ -575,6 +596,13 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
.withId("testid")
.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
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,7 @@
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;
Expand Down Expand Up @@ -107,6 +108,9 @@ public void build() throws IOException {
verify(mockTrigger).onPost(pushHookArgumentCaptor.capture());
assertThat(pushHookArgumentCaptor.getValue().getProject(), is(notNullValue()));
assertThat(pushHookArgumentCaptor.getValue().getProject().getWebUrl(), is(notNullValue()));
assertThat(pushHookArgumentCaptor.getValue().getUser(), is(notNullValue()));
assertThat(pushHookArgumentCaptor.getValue().getUser().getName(), containsString("Administrator"));
assertThat(pushHookArgumentCaptor.getValue().getUser().getUsername(), containsString("root"));
Comment thread
krisstern marked this conversation as resolved.
Outdated
Copy link
Copy Markdown
Member

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.

}
}

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"));
Comment thread
krisstern marked this conversation as resolved.
}
}

@Test
Expand Down