18
18
19
19
public class GitLabMergeRequestCommentTrigger extends AbstractGitLabJobTrigger <NoteEvent > {
20
20
21
- public static final Logger LOGGER = Logger
22
- .getLogger (GitLabMergeRequestCommentTrigger .class .getName ());
21
+ public static final Logger LOGGER = Logger .getLogger (GitLabMergeRequestCommentTrigger .class .getName ());
23
22
24
23
public GitLabMergeRequestCommentTrigger (NoteEvent payload ) {
25
24
super (payload );
@@ -28,11 +27,11 @@ public GitLabMergeRequestCommentTrigger(NoteEvent payload) {
28
27
@ Override
29
28
public void isMatch () {
30
29
if (getPayload ().getObjectAttributes ().getNoteableType ()
31
- .equals (NoteEvent .NoteableType .MERGE_REQUEST )) {
30
+ .equals (NoteEvent .NoteableType .MERGE_REQUEST )) {
32
31
Long mergeRequestId = getPayload ().getMergeRequest ().getIid ();
33
32
final Pattern mergeRequestJobNamePattern = Pattern
34
- .compile ("^MR-" + mergeRequestId + "\\ b.*$" ,
35
- Pattern .CASE_INSENSITIVE );
33
+ .compile ("^MR-" + mergeRequestId + "\\ b.*$" ,
34
+ Pattern .CASE_INSENSITIVE );
36
35
final String commentBody = getPayload ().getObjectAttributes ().getNote ();
37
36
final String commentUrl = getPayload ().getObjectAttributes ().getUrl ();
38
37
try (ACLContext ctx = ACL .as (ACL .SYSTEM )) {
@@ -49,35 +48,33 @@ public void isMatch() {
49
48
}
50
49
GitLabSCMSource gitLabSCMSource = (GitLabSCMSource ) source ;
51
50
final GitLabSCMSourceContext sourceContext = new GitLabSCMSourceContext (
52
- null , SCMHeadObserver .none ())
53
- .withTraits (gitLabSCMSource .getTraits ());
51
+ null , SCMHeadObserver .none ())
52
+ .withTraits (gitLabSCMSource .getTraits ());
54
53
if (!sourceContext .mrCommentTriggerEnabled ()) {
55
54
continue ;
56
55
}
57
- if (gitLabSCMSource .getProjectId () == getPayload ().getMergeRequest ()
58
- . getTargetProjectId () && isTrustedMember (gitLabSCMSource , sourceContext .getOnlyTrustedMembersCanTrigger ())) {
56
+ if (gitLabSCMSource .getProjectId () == getPayload ().getMergeRequest (). getTargetProjectId ()
57
+ && isTrustedMember (gitLabSCMSource , sourceContext .getOnlyTrustedMembersCanTrigger ())) {
59
58
for (Job <?, ?> job : owner .getAllJobs ()) {
60
59
if (mergeRequestJobNamePattern .matcher (job .getName ()).matches ()) {
61
60
String expectedCommentBody = sourceContext .getCommentBody ();
62
61
Pattern pattern = Pattern .compile (expectedCommentBody ,
63
- Pattern .CASE_INSENSITIVE | Pattern .DOTALL );
62
+ Pattern .CASE_INSENSITIVE | Pattern .DOTALL );
64
63
if (commentBody == null || pattern .matcher (commentBody )
65
- .matches ()) {
64
+ .matches ()) {
66
65
ParameterizedJobMixIn .scheduleBuild2 (job , 0 ,
67
- new CauseAction (
68
- new GitLabMergeRequestCommentCause (commentUrl , getPayload ())));
66
+ new CauseAction (
67
+ new GitLabMergeRequestCommentCause (commentUrl , getPayload ())));
69
68
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
+ });
76
74
} else {
77
75
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 () });
81
78
}
82
79
break ;
83
80
}
@@ -88,22 +85,21 @@ public void isMatch() {
88
85
}
89
86
if (!jobFound ) {
90
87
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
+ });
95
91
}
96
92
}
97
93
}
98
94
}
99
95
100
96
private boolean isTrustedMember (GitLabSCMSource gitLabSCMSource , boolean check ) {
101
97
// Return true if only trusted members can trigger option is not checked
102
- if (!check ) {
98
+ if (!check ) {
103
99
return true ;
104
100
}
105
101
AccessLevel permission = gitLabSCMSource .getMembers ()
106
- .get (getPayload ().getUser ().getUsername ());
102
+ .get (getPayload ().getUser ().getUsername ());
107
103
if (permission != null ) {
108
104
switch (permission ) {
109
105
case MAINTAINER :
0 commit comments