3232import org .kohsuke .github .GHPullRequest ;
3333import org .kohsuke .github .GHPullRequestCommitDetail ;
3434import org .kohsuke .github .GHRepository ;
35+ import org .kohsuke .github .GHTeam ;
3536import org .kohsuke .github .GHUser ;
37+ import org .kohsuke .github .GitHub ;
3638
3739public class CheckPullRequestContributionRules {
3840
@@ -58,35 +60,36 @@ void pullRequestChanged(
5860 @ PullRequest .Opened @ PullRequest .Reopened @ PullRequest .Edited @ PullRequest .Synchronize
5961 GHEventPayload .PullRequest payload ,
6062 @ 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 () );
6366 }
6467
6568 void checkRunRequested (@ CheckRun .Rerequested GHEventPayload .CheckRun payload ,
6669 @ 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 {
6872 for ( GHPullRequest pullRequest : payload .getCheckRun ().getPullRequests () ) {
69- checkPullRequestContributionRules ( payload .getRepository (), repositoryConfig , pullRequestTemplate , pullRequest );
73+ checkPullRequestContributionRules ( payload .getRepository (), gitHub , repositoryConfig , pullRequestTemplate , pullRequest );
7074 }
7175 }
7276
7377 void checkSuiteRequested (@ CheckSuite .Requested @ CheckSuite .Rerequested GHEventPayload .CheckSuite payload ,
7478 @ 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 {
7681 for ( GHPullRequest pullRequest : payload .getCheckSuite ().getPullRequests () ) {
77- checkPullRequestContributionRules ( payload .getRepository (), repositoryConfig , pullRequestTemplate , pullRequest );
82+ checkPullRequestContributionRules ( payload .getRepository (), gitHub , repositoryConfig , pullRequestTemplate , pullRequest );
7883 }
7984 }
8085
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 {
8588 if ( !shouldCheck ( repository , pullRequest ) ) {
8689 return ;
8790 }
8891
89- PullRequestCheckRunContext context = new PullRequestCheckRunContext ( deploymentConfig , repository , repositoryConfig , pullRequest );
92+ PullRequestCheckRunContext context = new PullRequestCheckRunContext ( deploymentConfig , gitHub , repository , repositoryConfig , pullRequest );
9093 List <PullRequestCheck > checks = createChecks ( repositoryConfig , pullRequestTemplate );
9194 List <PullRequestCheckRunOutput > outputs = new ArrayList <>();
9295 for ( PullRequestCheck check : checks ) {
@@ -323,8 +326,21 @@ protected boolean shouldCheckPullRequest(PullRequestCheckRunContext context) thr
323326 GHUser author = context .pullRequest .getUser ();
324327 String title = context .pullRequest .getTitle ();
325328 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 () ) {
328344 return false ;
329345 }
330346 }
0 commit comments