32
32
import org .kohsuke .github .GHPullRequest ;
33
33
import org .kohsuke .github .GHPullRequestCommitDetail ;
34
34
import org .kohsuke .github .GHRepository ;
35
+ import org .kohsuke .github .GHTeam ;
35
36
import org .kohsuke .github .GHUser ;
37
+ import org .kohsuke .github .GitHub ;
36
38
37
39
public class CheckPullRequestContributionRules {
38
40
@@ -58,35 +60,36 @@ void pullRequestChanged(
58
60
@ PullRequest .Opened @ PullRequest .Reopened @ PullRequest .Edited @ PullRequest .Synchronize
59
61
GHEventPayload .PullRequest payload ,
60
62
@ ConfigFile ("hibernate-github-bot.yml" ) RepositoryConfig repositoryConfig ,
61
- @ ConfigFile ("PULL_REQUEST_TEMPLATE.md" ) String pullRequestTemplate ) throws IOException {
62
- checkPullRequestContributionRules ( payload .getRepository (), repositoryConfig , pullRequestTemplate , payload .getPullRequest () );
63
+ @ ConfigFile ("PULL_REQUEST_TEMPLATE.md" ) String pullRequestTemplate ,
64
+ GitHub gitHub ) throws IOException {
65
+ checkPullRequestContributionRules ( payload .getRepository (), gitHub , repositoryConfig , pullRequestTemplate , payload .getPullRequest () );
63
66
}
64
67
65
68
void checkRunRequested (@ CheckRun .Rerequested GHEventPayload .CheckRun payload ,
66
69
@ ConfigFile ("hibernate-github-bot.yml" ) RepositoryConfig repositoryConfig ,
67
- @ ConfigFile ("PULL_REQUEST_TEMPLATE.md" ) String pullRequestTemplate ) throws IOException {
70
+ @ ConfigFile ("PULL_REQUEST_TEMPLATE.md" ) String pullRequestTemplate ,
71
+ GitHub gitHub ) throws IOException {
68
72
for ( GHPullRequest pullRequest : payload .getCheckRun ().getPullRequests () ) {
69
- checkPullRequestContributionRules ( payload .getRepository (), repositoryConfig , pullRequestTemplate , pullRequest );
73
+ checkPullRequestContributionRules ( payload .getRepository (), gitHub , repositoryConfig , pullRequestTemplate , pullRequest );
70
74
}
71
75
}
72
76
73
77
void checkSuiteRequested (@ CheckSuite .Requested @ CheckSuite .Rerequested GHEventPayload .CheckSuite payload ,
74
78
@ ConfigFile ("hibernate-github-bot.yml" ) RepositoryConfig repositoryConfig ,
75
- @ ConfigFile ("PULL_REQUEST_TEMPLATE.md" ) String pullRequestTemplate ) throws IOException {
79
+ @ ConfigFile ("PULL_REQUEST_TEMPLATE.md" ) String pullRequestTemplate ,
80
+ GitHub gitHub ) throws IOException {
76
81
for ( GHPullRequest pullRequest : payload .getCheckSuite ().getPullRequests () ) {
77
- checkPullRequestContributionRules ( payload .getRepository (), repositoryConfig , pullRequestTemplate , pullRequest );
82
+ checkPullRequestContributionRules ( payload .getRepository (), gitHub , repositoryConfig , pullRequestTemplate , pullRequest );
78
83
}
79
84
}
80
85
81
- private void checkPullRequestContributionRules (GHRepository repository , RepositoryConfig repositoryConfig ,
82
- String pullRequestTemplate ,
83
- GHPullRequest pullRequest )
84
- throws IOException {
86
+ private void checkPullRequestContributionRules (GHRepository repository , GitHub gitHub , RepositoryConfig repositoryConfig ,
87
+ String pullRequestTemplate , GHPullRequest pullRequest ) throws IOException {
85
88
if ( !shouldCheck ( repository , pullRequest ) ) {
86
89
return ;
87
90
}
88
91
89
- PullRequestCheckRunContext context = new PullRequestCheckRunContext ( deploymentConfig , repository , repositoryConfig , pullRequest );
92
+ PullRequestCheckRunContext context = new PullRequestCheckRunContext ( deploymentConfig , gitHub , repository , repositoryConfig , pullRequest );
90
93
List <PullRequestCheck > checks = createChecks ( repositoryConfig , pullRequestTemplate );
91
94
List <PullRequestCheckRunOutput > outputs = new ArrayList <>();
92
95
for ( PullRequestCheck check : checks ) {
@@ -323,8 +326,21 @@ protected boolean shouldCheckPullRequest(PullRequestCheckRunContext context) thr
323
326
GHUser author = context .pullRequest .getUser ();
324
327
String title = context .pullRequest .getTitle ();
325
328
for ( RepositoryConfig .IgnoreConfiguration ignore : ignoredPRConfigurations ) {
326
- if ( ignore .getUser ().equals ( author .getLogin () )
327
- && ignore .getTitlePattern ().matcher ( title ).matches () ) {
329
+ if ( ignore .getTeam ().isPresent () ) {
330
+ boolean userTeamCanSkip = false ;
331
+ var teamToFind = ignore .getTeam ().get ();
332
+ GHTeam team = context .gitHub .getOrganization ( teamToFind .getOrganization () ).getTeamByName ( teamToFind .getName () );
333
+ for ( GHUser user : team .listMembers () ) {
334
+ if ( user .getLogin ().equals ( author .getLogin () ) ) {
335
+ userTeamCanSkip = true ;
336
+ break ;
337
+ }
338
+ }
339
+ if ( userTeamCanSkip && ignore .getTitlePattern ().matcher ( title ).matches () ) {
340
+ return false ;
341
+ }
342
+ }
343
+ else if ( ignore .getUser ().equals ( author .getLogin () ) && ignore .getTitlePattern ().matcher ( title ).matches () ) {
328
344
return false ;
329
345
}
330
346
}
0 commit comments