-
Notifications
You must be signed in to change notification settings - Fork 101
Auto add CICD label when PR author is a member or owner of flutter organization #4997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e9e707b
77f48e3
f8f4a52
7a28069
d545610
bd1e492
e5a9ecd
ecf36c5
8b5e96f
b126e68
0bb3d09
366df57
e182bbc
0ed8c76
c3cebef
9d2cbc2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -199,11 +199,14 @@ final class GithubWebhookSubscription extends SubscriptionHandler { | |
| final result = await _processPullRequestClosed(pullRequestEvent); | ||
| return result.toResponse(); | ||
| case 'edited': | ||
| await _addCICDForRollers(pullRequestEvent); | ||
| if (pullRequestEvent.changes != null && | ||
| pullRequestEvent.changes!.base != null) { | ||
| await _addCICDForRollersAndMembers(pullRequestEvent); | ||
| } | ||
| await _checkForTests(pullRequestEvent); | ||
| break; | ||
| case 'opened': | ||
| await _addCICDForRollers(pullRequestEvent); | ||
| await _addCICDForRollersAndMembers(pullRequestEvent); | ||
| await _checkForTests(pullRequestEvent); | ||
| await _tryReleaseApproval(pullRequestEvent); | ||
| break; | ||
|
|
@@ -232,8 +235,10 @@ final class GithubWebhookSubscription extends SubscriptionHandler { | |
| case 'dequeued': | ||
| await _respondToPullRequestDequeued(pullRequestEvent); | ||
| break; | ||
| // Ignore the rest of the events. | ||
| case 'synchronize': | ||
| await _addCICDForRollersAndMembers(pullRequestEvent); | ||
| break; | ||
| // Ignore the rest of the events. | ||
| case 'ready_for_review': | ||
| case 'unlabeled': | ||
| case 'assigned': | ||
|
|
@@ -569,12 +574,22 @@ final class GithubWebhookSubscription extends SubscriptionHandler { | |
| ); | ||
| } | ||
|
|
||
| Future<void> _addCICDForRollers(PullRequestEvent pullRequestEvent) async { | ||
| Future<void> _addCICDForRollersAndMembers( | ||
| PullRequestEvent pullRequestEvent, | ||
| ) async { | ||
| final pr = pullRequestEvent.pullRequest!; | ||
| final slug = pr.base!.repo!.slug(); | ||
| final author = pr.user!.login!; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I double checked that this returns the author's user, and not the user of the person interacting with the PR: |
||
| final githubService = await config.createGithubService(slug); | ||
|
|
||
| final isRoller = config.rollerAccounts.contains(pr.user!.login); | ||
| final isFlutterHacker = await githubService.isTeamMember( | ||
| 'flutter-hackers', | ||
| author, | ||
| slug.owner, | ||
| ); | ||
|
|
||
| if (config.rollerAccounts.contains(pr.user!.login) && | ||
| config.supportedRepos.contains(slug)) { | ||
| if (config.supportedRepos.contains(slug) && (isRoller || isFlutterHacker)) { | ||
| final gitHubClient = await config.createGitHubClient(pullRequest: pr); | ||
| await gitHubClient.issues.addLabelsToIssue(slug, pr.number!, ['CICD']); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -113,6 +113,20 @@ class GithubService { | |||
| .toList(); | ||||
| } | ||||
|
|
||||
| /// Check to see if user is a member of team in org. | ||||
| /// | ||||
| /// Note that we catch here as the api returns a 404 if the user has no | ||||
| /// membership in general or is not a member of the team. | ||||
| Future<bool> isTeamMember(String team, String user, String org) async { | ||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I copied this from
as there are duplicate github_service.darts and this one did not have the method. It may be good to de-dupe these at some point
|
||||
| try { | ||||
| final teamMembershipState = await github.organizations | ||||
| .getTeamMembershipByName(org, team, user); | ||||
| return teamMembershipState.isActive; | ||||
| } on GitHubError { | ||||
| return false; | ||||
| } | ||||
| } | ||||
|
|
||||
| /// Creates a pull request against the `baseRef` in the `slug` repository. | ||||
| /// | ||||
| /// The `entries` contains the file changes in the created pull request. This | ||||
|
|
||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a slight behavior change, I made it this way because before the path for scheduling tests checked these conditions:
363e9cd#diff-4d5f5e21f5b7eda8e7775b9a678fb60bb6cfba3321799948fb2b9a55cefbe439L202-L206
And I figured it was also fine to apply those checks for the roller case. Let me know if not