-
Notifications
You must be signed in to change notification settings - Fork 619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix missing gitlabUserUsername definition for MR and Note triggers #1469
Open
ljackiewicz
wants to merge
13
commits into
jenkinsci:master
Choose a base branch
from
ljackiewicz:fix/missing-defined-variables
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
32c8e82
gitlabUserUsername variable is not set for MR trigger
ljackiewicz 02cba11
gitlabUserUsername variable is not set for Note (comments) trigger
ljackiewicz 947445a
Merge branch 'master' into fix/missing-defined-variables
krisstern c39ff4d
Merge branch 'master' of https://github.com/jenkinsci/gitlab-plugin i…
krisstern 5671b24
Applying code review suggestions
krisstern c602665
Leave the previous values for gitlabUserName and gitlabUserEmail
ljackiewicz aee617b
Change confusing variable name
ljackiewicz 3ff76f2
Merge branch 'master' into fix/missing-defined-variables
ljackiewicz dc00bd1
Merge branch 'master' into fix/missing-defined-variables
krisstern 6404ccf
Merge branch 'master' into fix/missing-defined-variables
ljackiewicz 41b249f
Merge remote-tracking branch 'upstream/master' into fix/missing-defin…
MarkEWaite f8006a6
Merge branch 'master' into fix/missing-defined-variables
ljackiewicz 6fb9468
Merge branch 'master' into fix/missing-defined-variables
krisstern File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ | |
import com.dabsquared.gitlabjenkins.gitlab.hook.model.Repository; | ||
import com.dabsquared.gitlabjenkins.gitlab.hook.model.State; | ||
import com.dabsquared.gitlabjenkins.gitlab.hook.model.User; | ||
import com.dabsquared.gitlabjenkins.gitlab.hook.model.builder.generated.CommitBuilder; | ||
import com.dabsquared.gitlabjenkins.gitlab.hook.model.builder.generated.MergeRequestHookBuilder; | ||
import com.dabsquared.gitlabjenkins.gitlab.hook.model.builder.generated.ProjectBuilder; | ||
import com.dabsquared.gitlabjenkins.gitlab.hook.model.builder.generated.PushHookBuilder; | ||
|
@@ -36,7 +35,7 @@ | |
import hudson.model.Queue; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import org.jenkinsci.plugins.workflow.job.WorkflowJob; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
|
@@ -76,7 +75,7 @@ public void clearQueue() { | |
|
||
@Test | ||
public void projectCanBeConfiguredToSendPendingBuildStatusWhenTriggered() throws IOException { | ||
Project project = | ||
Project<?, ?> project = | ||
freestyleProject("freestyleProject1", new GitLabCommitStatusPublisher(GITLAB_BUILD_NAME, false)); | ||
|
||
GitLabPushTrigger gitLabPushTrigger = gitLabPushTrigger(project); | ||
|
@@ -118,7 +117,7 @@ public void workflowJobCanConfiguredToSendToPendingBuildStatusWhenTriggered() th | |
|
||
@Test | ||
public void queuedMergeRequestBuildsCanBeCancelledOnMergeRequestUpdate() throws IOException { | ||
Project project = freestyleProject("project1", new GitLabCommitStatusPublisher(GITLAB_BUILD_NAME, false)); | ||
Project<?, ?> project = freestyleProject("project1", new GitLabCommitStatusPublisher(GITLAB_BUILD_NAME, false)); | ||
|
||
GitLabPushTrigger gitLabPushTrigger = gitLabPushTrigger(project); | ||
gitLabPushTrigger.setCancelPendingBuildsOnUpdate(true); | ||
|
@@ -153,7 +152,7 @@ public void queuedMergeRequestBuildsCanBeCancelledOnMergeRequestUpdate() throws | |
assertThat(jenkins.getInstance().getQueue().getItems().length, is(3)); | ||
} | ||
|
||
private GitLabPushTrigger gitLabPushTrigger(Project project) throws IOException { | ||
private GitLabPushTrigger gitLabPushTrigger(Project<?, ?> project) throws IOException { | ||
GitLabPushTrigger gitLabPushTrigger = gitLabPushTrigger(); | ||
project.addTrigger(gitLabPushTrigger); | ||
gitLabPushTrigger.start(project, true); | ||
|
@@ -212,6 +211,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("[email protected]") | ||
.withAvatarUrl( | ||
"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon") | ||
.build()) | ||
.build(); | ||
} | ||
|
||
|
@@ -230,15 +236,17 @@ private PushHook pushHook(int projectId, String branch, String commitId) { | |
.withAfter(commitId) | ||
.withRepository(new Repository()) | ||
.withProject(ProjectBuilder.project().withNamespace("namespace").build()) | ||
.withCommits(Arrays.asList( | ||
CommitBuilder.commit().withId(commitId).withAuthor(user).build())) | ||
.withCommits(Collections.singletonList( | ||
commit().withId(commitId).withAuthor(user).build())) | ||
.withRepository(repository) | ||
.withObjectKind("push") | ||
.withUserName("username") | ||
.withUserName("User") | ||
.withUserUsername("username") | ||
.withUserEmail("[email protected]") | ||
.build(); | ||
} | ||
|
||
private Project freestyleProject(String name, GitLabCommitStatusPublisher gitLabCommitStatusPublisher) | ||
private Project<?, ?> freestyleProject(String name, GitLabCommitStatusPublisher gitLabCommitStatusPublisher) | ||
throws IOException { | ||
FreeStyleProject project = jenkins.createFreeStyleProject(name); | ||
project.setQuietPeriod(5000); | ||
|
@@ -248,7 +256,7 @@ private Project freestyleProject(String name, GitLabCommitStatusPublisher gitLab | |
} | ||
|
||
private WorkflowJob workflowJob() throws IOException { | ||
ItemGroup itemGroup = mock(ItemGroup.class); | ||
ItemGroup<WorkflowJob> itemGroup = mock(ItemGroup.class); | ||
when(itemGroup.getFullName()).thenReturn("parent"); | ||
when(itemGroup.getUrlChildPrefix()).thenReturn("prefix"); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
import hudson.util.OneShotEvent; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
import org.eclipse.jgit.api.Git; | ||
import org.eclipse.jgit.api.errors.GitAPIException; | ||
|
@@ -429,6 +430,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("[email protected]") | ||
.withAvatarUrl( | ||
"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon") | ||
.build()) | ||
.build(), | ||
true, | ||
BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)), | ||
|
@@ -452,6 +460,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("[email protected]") | ||
.withAvatarUrl( | ||
"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon") | ||
.build()) | ||
.build(), | ||
true, | ||
BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)), | ||
|
@@ -541,6 +556,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("[email protected]") | ||
.withAvatarUrl( | ||
"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon") | ||
.build()) | ||
.build(), | ||
true, | ||
BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)), | ||
|
@@ -564,7 +586,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen | |
}); | ||
project.setQuietPeriod(0); | ||
MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = new MergeRequestHookTriggerHandlerImpl( | ||
Arrays.asList(State.opened, State.reopened), Arrays.asList(Action.approved), false, false, false); | ||
Arrays.asList(State.opened, State.reopened), List.of(Action.approved), false, false, false); | ||
mergeRequestHookTriggerHandler.handle( | ||
project, | ||
mergeRequestHook() | ||
|
@@ -575,6 +597,13 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen | |
.withId("testid") | ||
.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)), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
@@ -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")); | ||
krisstern marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these are the tests we need for this PR I guess, which I have added/updated.