@@ -158,9 +158,8 @@ private List<PullRequestCheck> createChecks(RepositoryConfig repositoryConfig, S
158
158
&& repositoryConfig .licenseAgreement != null
159
159
&& repositoryConfig .licenseAgreement .getEnabled ().orElse ( Boolean .FALSE ) ) {
160
160
Matcher matcher = repositoryConfig .licenseAgreement .getPullRequestTemplatePattern ().matcher ( pullRequestTemplate );
161
- if ( matcher .matches ()
162
- && matcher .groupCount () == 1 ) {
163
- checks .add ( new LicenseCheck ( matcher .group ( 1 ).trim () ) );
161
+ if ( matcher .matches () && matcher .groupCount () == 1 ) {
162
+ checks .add ( new LicenseCheck ( matcher .group ( 1 ).trim (), repositoryConfig .licenseAgreement .getIgnore () ) );
164
163
}
165
164
else {
166
165
throw new IllegalArgumentException ( "Misconfigured license agreement check. Pattern should contain exactly 1 match group. Pattern: %s. Fetched Pull Request template: %s" .formatted ( repositoryConfig .licenseAgreement .getPullRequestTemplatePattern (), pullRequestTemplate ) );
@@ -169,7 +168,7 @@ private List<PullRequestCheck> createChecks(RepositoryConfig repositoryConfig, S
169
168
170
169
if ( repositoryConfig != null && repositoryConfig .pullRequestTasks != null
171
170
&& repositoryConfig .pullRequestTasks .getEnabled ().orElse ( Boolean .FALSE ) ) {
172
- checks .add ( new TasksCompletedCheck () );
171
+ checks .add ( new TasksCompletedCheck (repositoryConfig . pullRequestTasks . getIgnore () ) );
173
172
}
174
173
175
174
return checks ;
@@ -192,33 +191,25 @@ public void perform(PullRequestCheckRunContext context, PullRequestCheckRunOutpu
192
191
}
193
192
}
194
193
195
- static class JiraIssuesCheck extends PullRequestCheck {
194
+ static class JiraIssuesCheck extends IgnorablePullRequestCheck {
196
195
197
196
private final Pattern issueKeyPattern ;
198
197
199
198
private final Integer issueLinksLimit ;
200
199
201
- private final List <RepositoryConfig .IgnoreConfiguration > ignoredPRConfigurations ;
202
200
private final GlobMatcher ignoredFilesMatcher ;
203
201
204
202
JiraIssuesCheck (Pattern issueKeyPattern , Integer issueLinksLimit ,
205
203
List <RepositoryConfig .IgnoreConfiguration > ignoredPRConfigurations ,
206
204
List <String > ignoreFilePatterns ) {
207
- super ( "Contribution — JIRA issues" );
205
+ super ( "Contribution — JIRA issues" , ignoredPRConfigurations );
208
206
this .issueKeyPattern = issueKeyPattern ;
209
207
this .issueLinksLimit = issueLinksLimit ;
210
- this .ignoredPRConfigurations = ignoredPRConfigurations ;
211
208
this .ignoredFilesMatcher = new GlobMatcher ( ignoreFilePatterns );
212
209
}
213
210
214
211
@ Override
215
- public void perform (PullRequestCheckRunContext context , PullRequestCheckRunOutput output ) throws IOException {
216
- if ( !shouldCheckPullRequest ( context ) ) {
217
- // Means we have an ignore rule configured that matches our pull request.
218
- // No need to check anything else.
219
- return ;
220
- }
221
-
212
+ public void doPerform (PullRequestCheckRunContext context , PullRequestCheckRunOutput output ) throws IOException {
222
213
String title = context .pullRequest .getTitle ();
223
214
String body = context .pullRequest .getBody ();
224
215
@@ -263,32 +254,19 @@ public void perform(PullRequestCheckRunContext context, PullRequestCheckRunOutpu
263
254
}
264
255
}
265
256
}
266
-
267
- private boolean shouldCheckPullRequest (PullRequestCheckRunContext context ) throws IOException {
268
- GHUser author = context .pullRequest .getUser ();
269
- String title = context .pullRequest .getTitle ();
270
- for ( RepositoryConfig .IgnoreConfiguration ignore : ignoredPRConfigurations ) {
271
- if ( ignore .getUser ().equals ( author .getLogin () )
272
- && ignore .getTitlePattern ().matcher ( title ).matches () ) {
273
- return false ;
274
- }
275
- }
276
-
277
- return true ;
278
- }
279
257
}
280
258
281
- static class LicenseCheck extends PullRequestCheck {
259
+ static class LicenseCheck extends IgnorablePullRequestCheck {
282
260
283
261
private final String agreementText ;
284
262
285
- protected LicenseCheck (String agreementText ) {
286
- super ( "Contribution — License agreement" );
263
+ protected LicenseCheck (String agreementText , List < RepositoryConfig . IgnoreConfiguration > ignoredPRConfigurations ) {
264
+ super ( "Contribution — License agreement" , ignoredPRConfigurations );
287
265
this .agreementText = Patterns .sanitizeNewLines ( agreementText );
288
266
}
289
267
290
268
@ Override
291
- public void perform (PullRequestCheckRunContext context , PullRequestCheckRunOutput output ) {
269
+ public void doPerform (PullRequestCheckRunContext context , PullRequestCheckRunOutput output ) {
292
270
String body = Patterns .sanitizeNewLines ( context .pullRequest .getBody () );
293
271
PullRequestCheckRunRule rule = output .rule ( "The pull request description must contain the license agreement text." );
294
272
if ( body != null && body .contains ( agreementText ) ) {
@@ -305,18 +283,54 @@ public void perform(PullRequestCheckRunContext context, PullRequestCheckRunOutpu
305
283
}
306
284
}
307
285
308
- static class TasksCompletedCheck extends PullRequestCheck {
286
+ static class TasksCompletedCheck extends IgnorablePullRequestCheck {
309
287
310
- protected TasksCompletedCheck () {
311
- super ( "Contribution — Review tasks" );
288
+ protected TasksCompletedCheck (List < RepositoryConfig . IgnoreConfiguration > ignoredPRConfigurations ) {
289
+ super ( "Contribution — Review tasks" , ignoredPRConfigurations );
312
290
}
313
291
314
292
@ Override
315
- public void perform (PullRequestCheckRunContext context , PullRequestCheckRunOutput output ) {
293
+ public void doPerform (PullRequestCheckRunContext context , PullRequestCheckRunOutput output ) {
316
294
String body = context .pullRequest .getBody ();
317
295
output .rule ( "All pull request tasks should be completed." )
318
296
.result ( !EditPullRequestBodyAddTaskList .containsUnfinishedTasks ( body ) );
319
297
}
320
298
}
321
299
300
+ static abstract class IgnorablePullRequestCheck extends PullRequestCheck {
301
+
302
+ private final List <RepositoryConfig .IgnoreConfiguration > ignoredPRConfigurations ;
303
+
304
+ protected IgnorablePullRequestCheck (String title , List <RepositoryConfig .IgnoreConfiguration > ignoredPRConfigurations ) {
305
+ super ( title );
306
+ this .ignoredPRConfigurations = ignoredPRConfigurations ;
307
+ }
308
+
309
+ @ Override
310
+ public final void perform (PullRequestCheckRunContext context , PullRequestCheckRunOutput output ) throws IOException {
311
+ if ( !shouldCheckPullRequest ( context ) ) {
312
+ // Means we have an ignore rule configured that matches our pull request.
313
+ // No need to check anything else.
314
+ return ;
315
+ }
316
+
317
+ doPerform ( context , output );
318
+ }
319
+
320
+ abstract void doPerform (PullRequestCheckRunContext context , PullRequestCheckRunOutput output ) throws IOException ;
321
+
322
+ protected boolean shouldCheckPullRequest (PullRequestCheckRunContext context ) throws IOException {
323
+ GHUser author = context .pullRequest .getUser ();
324
+ String title = context .pullRequest .getTitle ();
325
+ for ( RepositoryConfig .IgnoreConfiguration ignore : ignoredPRConfigurations ) {
326
+ if ( ignore .getUser ().equals ( author .getLogin () )
327
+ && ignore .getTitlePattern ().matcher ( title ).matches () ) {
328
+ return false ;
329
+ }
330
+ }
331
+
332
+ return true ;
333
+ }
334
+ }
335
+
322
336
}
0 commit comments