@@ -158,9 +158,8 @@ private List<PullRequestCheck> createChecks(RepositoryConfig repositoryConfig, S
158158 && repositoryConfig .licenseAgreement != null
159159 && repositoryConfig .licenseAgreement .getEnabled ().orElse ( Boolean .FALSE ) ) {
160160 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 () ) );
164163 }
165164 else {
166165 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
169168
170169 if ( repositoryConfig != null && repositoryConfig .pullRequestTasks != null
171170 && repositoryConfig .pullRequestTasks .getEnabled ().orElse ( Boolean .FALSE ) ) {
172- checks .add ( new TasksCompletedCheck () );
171+ checks .add ( new TasksCompletedCheck (repositoryConfig . pullRequestTasks . getIgnore () ) );
173172 }
174173
175174 return checks ;
@@ -192,33 +191,25 @@ public void perform(PullRequestCheckRunContext context, PullRequestCheckRunOutpu
192191 }
193192 }
194193
195- static class JiraIssuesCheck extends PullRequestCheck {
194+ static class JiraIssuesCheck extends IgnorablePullRequestCheck {
196195
197196 private final Pattern issueKeyPattern ;
198197
199198 private final Integer issueLinksLimit ;
200199
201- private final List <RepositoryConfig .IgnoreConfiguration > ignoredPRConfigurations ;
202200 private final GlobMatcher ignoredFilesMatcher ;
203201
204202 JiraIssuesCheck (Pattern issueKeyPattern , Integer issueLinksLimit ,
205203 List <RepositoryConfig .IgnoreConfiguration > ignoredPRConfigurations ,
206204 List <String > ignoreFilePatterns ) {
207- super ( "Contribution — JIRA issues" );
205+ super ( "Contribution — JIRA issues" , ignoredPRConfigurations );
208206 this .issueKeyPattern = issueKeyPattern ;
209207 this .issueLinksLimit = issueLinksLimit ;
210- this .ignoredPRConfigurations = ignoredPRConfigurations ;
211208 this .ignoredFilesMatcher = new GlobMatcher ( ignoreFilePatterns );
212209 }
213210
214211 @ 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 {
222213 String title = context .pullRequest .getTitle ();
223214 String body = context .pullRequest .getBody ();
224215
@@ -263,32 +254,19 @@ public void perform(PullRequestCheckRunContext context, PullRequestCheckRunOutpu
263254 }
264255 }
265256 }
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- }
279257 }
280258
281- static class LicenseCheck extends PullRequestCheck {
259+ static class LicenseCheck extends IgnorablePullRequestCheck {
282260
283261 private final String agreementText ;
284262
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 );
287265 this .agreementText = Patterns .sanitizeNewLines ( agreementText );
288266 }
289267
290268 @ Override
291- public void perform (PullRequestCheckRunContext context , PullRequestCheckRunOutput output ) {
269+ public void doPerform (PullRequestCheckRunContext context , PullRequestCheckRunOutput output ) {
292270 String body = Patterns .sanitizeNewLines ( context .pullRequest .getBody () );
293271 PullRequestCheckRunRule rule = output .rule ( "The pull request description must contain the license agreement text." );
294272 if ( body != null && body .contains ( agreementText ) ) {
@@ -305,18 +283,54 @@ public void perform(PullRequestCheckRunContext context, PullRequestCheckRunOutpu
305283 }
306284 }
307285
308- static class TasksCompletedCheck extends PullRequestCheck {
286+ static class TasksCompletedCheck extends IgnorablePullRequestCheck {
309287
310- protected TasksCompletedCheck () {
311- super ( "Contribution — Review tasks" );
288+ protected TasksCompletedCheck (List < RepositoryConfig . IgnoreConfiguration > ignoredPRConfigurations ) {
289+ super ( "Contribution — Review tasks" , ignoredPRConfigurations );
312290 }
313291
314292 @ Override
315- public void perform (PullRequestCheckRunContext context , PullRequestCheckRunOutput output ) {
293+ public void doPerform (PullRequestCheckRunContext context , PullRequestCheckRunOutput output ) {
316294 String body = context .pullRequest .getBody ();
317295 output .rule ( "All pull request tasks should be completed." )
318296 .result ( !EditPullRequestBodyAddTaskList .containsUnfinishedTasks ( body ) );
319297 }
320298 }
321299
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+
322336}
0 commit comments