Skip to content

Commit 62ab6fc

Browse files
authored
Fix casting to GitLabMergeRequestTrigger and add more debug logs in Jenkins for plugin. Add option to alwaysIgnoreMRWorkInProgress (#266)
1 parent aa66886 commit 62ab6fc

17 files changed

+643
-524
lines changed

src/main/java/io/jenkins/plugins/gitlabbranchsource/AbstractGitLabSCMHeadEvent.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
public abstract class AbstractGitLabSCMHeadEvent<E> extends SCMHeadEvent<E> {
1717

18-
private static final Logger LOGGER = Logger.getLogger(AbstractGitLabSCMHeadEvent.class.getName());
18+
public static final Logger LOGGER = Logger.getLogger(AbstractGitLabSCMHeadEvent.class.getName());
1919

2020
private static final Pattern NONE_HASH_PATTERN = Pattern.compile("^0+$");
2121

@@ -30,7 +30,8 @@ static <E extends AbstractPushEvent> Type typeOf(E pushEvent) {
3030
} else if (hasBefore) {
3131
result = Type.REMOVED;
3232
} else {
33-
LOGGER.warning("Received push event with both \"before\" and \"after\" set to non-existing revision. Assuming removal.");
33+
LOGGER.warning(
34+
"Received push event with both \"before\" and \"after\" set to non-existing revision. Assuming removal.");
3435
result = Type.REMOVED;
3536
}
3637
return result;

src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestCommentTrigger.java

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
public class GitLabMergeRequestCommentTrigger extends AbstractGitLabJobTrigger<NoteEvent> {
2020

21-
public static final Logger LOGGER = Logger
22-
.getLogger(GitLabMergeRequestCommentTrigger.class.getName());
21+
public static final Logger LOGGER = Logger.getLogger(GitLabMergeRequestCommentTrigger.class.getName());
2322

2423
public GitLabMergeRequestCommentTrigger(NoteEvent payload) {
2524
super(payload);
@@ -28,11 +27,11 @@ public GitLabMergeRequestCommentTrigger(NoteEvent payload) {
2827
@Override
2928
public void isMatch() {
3029
if (getPayload().getObjectAttributes().getNoteableType()
31-
.equals(NoteEvent.NoteableType.MERGE_REQUEST)) {
30+
.equals(NoteEvent.NoteableType.MERGE_REQUEST)) {
3231
Long mergeRequestId = getPayload().getMergeRequest().getIid();
3332
final Pattern mergeRequestJobNamePattern = Pattern
34-
.compile("^MR-" + mergeRequestId + "\\b.*$",
35-
Pattern.CASE_INSENSITIVE);
33+
.compile("^MR-" + mergeRequestId + "\\b.*$",
34+
Pattern.CASE_INSENSITIVE);
3635
final String commentBody = getPayload().getObjectAttributes().getNote();
3736
final String commentUrl = getPayload().getObjectAttributes().getUrl();
3837
try (ACLContext ctx = ACL.as(ACL.SYSTEM)) {
@@ -49,35 +48,33 @@ public void isMatch() {
4948
}
5049
GitLabSCMSource gitLabSCMSource = (GitLabSCMSource) source;
5150
final GitLabSCMSourceContext sourceContext = new GitLabSCMSourceContext(
52-
null, SCMHeadObserver.none())
53-
.withTraits(gitLabSCMSource.getTraits());
51+
null, SCMHeadObserver.none())
52+
.withTraits(gitLabSCMSource.getTraits());
5453
if (!sourceContext.mrCommentTriggerEnabled()) {
5554
continue;
5655
}
57-
if (gitLabSCMSource.getProjectId() == getPayload().getMergeRequest()
58-
.getTargetProjectId() && isTrustedMember(gitLabSCMSource, sourceContext.getOnlyTrustedMembersCanTrigger())) {
56+
if (gitLabSCMSource.getProjectId() == getPayload().getMergeRequest().getTargetProjectId()
57+
&& isTrustedMember(gitLabSCMSource, sourceContext.getOnlyTrustedMembersCanTrigger())) {
5958
for (Job<?, ?> job : owner.getAllJobs()) {
6059
if (mergeRequestJobNamePattern.matcher(job.getName()).matches()) {
6160
String expectedCommentBody = sourceContext.getCommentBody();
6261
Pattern pattern = Pattern.compile(expectedCommentBody,
63-
Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
62+
Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
6463
if (commentBody == null || pattern.matcher(commentBody)
65-
.matches()) {
64+
.matches()) {
6665
ParameterizedJobMixIn.scheduleBuild2(job, 0,
67-
new CauseAction(
68-
new GitLabMergeRequestCommentCause(commentUrl, getPayload())));
66+
new CauseAction(
67+
new GitLabMergeRequestCommentCause(commentUrl, getPayload())));
6968
LOGGER.log(Level.INFO,
70-
"Triggered build for {0} due to MR comment on {1}",
71-
new Object[]{
72-
job.getFullName(),
73-
getPayload().getProject().getPathWithNamespace()
74-
}
75-
);
69+
"Triggered build for {0} due to MR comment on {1}",
70+
new Object[] {
71+
job.getFullName(),
72+
getPayload().getProject().getPathWithNamespace()
73+
});
7674
} else {
7775
LOGGER.log(Level.INFO,
78-
"MR comment does not match the trigger build string ({0}) for {1}",
79-
new Object[]{expectedCommentBody, job.getFullName()}
80-
);
76+
"MR comment does not match the trigger build string ({0}) for {1}",
77+
new Object[] { expectedCommentBody, job.getFullName() });
8178
}
8279
break;
8380
}
@@ -88,22 +85,21 @@ public void isMatch() {
8885
}
8986
if (!jobFound) {
9087
LOGGER.log(Level.INFO, "MR comment on {0} did not match any job",
91-
new Object[]{
92-
getPayload().getProject().getPathWithNamespace()
93-
}
94-
);
88+
new Object[] {
89+
getPayload().getProject().getPathWithNamespace()
90+
});
9591
}
9692
}
9793
}
9894
}
9995

10096
private boolean isTrustedMember(GitLabSCMSource gitLabSCMSource, boolean check) {
10197
// Return true if only trusted members can trigger option is not checked
102-
if(!check) {
98+
if (!check) {
10399
return true;
104100
}
105101
AccessLevel permission = gitLabSCMSource.getMembers()
106-
.get(getPayload().getUser().getUsername());
102+
.get(getPayload().getUser().getUsername());
107103
if (permission != null) {
108104
switch (permission) {
109105
case MAINTAINER:

0 commit comments

Comments
 (0)