Skip to content

Commit 383a09b

Browse files
Revert "Overhaul CICD label management for presubmits (#5028)" (#5029)
This reverts commit 7cbf0ea. This change caused issues where we were double-scheduling presubmits on roller bots, which caused failures. Rolling this back until we get this problem resolved.
1 parent 7cbf0ea commit 383a09b

3 files changed

Lines changed: 42 additions & 133 deletions

File tree

app_dart/docs/cicd_flowchart.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

app_dart/lib/src/request_handlers/github/webhook_subscription.dart

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,6 @@ final class GithubWebhookSubscription extends SubscriptionHandler {
173173
/// retried with exponential backoff within that time period. The GoB mirror
174174
/// should be caught up within that time frame via either the internal
175175
/// mirroring service or [VacuumGithubCommits].
176-
///
177-
/// See docs/cicd_flowchart.md for the flowchart of CICD label management.
178176
Future<Response> _handlePullRequest(String rawRequest) async {
179177
final pullRequestEvent = _getPullRequestEvent(rawRequest);
180178
if (pullRequestEvent == null) {
@@ -201,20 +199,16 @@ final class GithubWebhookSubscription extends SubscriptionHandler {
201199
final result = await _processPullRequestClosed(pullRequestEvent);
202200
return result.toResponse();
203201
case 'edited':
202+
if (pullRequestEvent.changes != null &&
203+
pullRequestEvent.changes!.base != null) {
204+
await _addCICDForRollersAndMembers(pullRequestEvent);
205+
}
206+
await scheduler.createAwaitingCicdLabelCheckRun(slug, pr.head!.sha!);
204207
await _checkForTests(pullRequestEvent);
205208
break;
206209
case 'opened':
207-
final isPrivileged = await _isPrivilegedUser(pr, slug);
208-
if (!pr.draft! && isPrivileged) {
209-
final gitHubClient = await config.createGitHubClient(pullRequest: pr);
210-
await gitHubClient.issues.addLabelsToIssue(slug, pr.number!, [
211-
'CICD',
212-
]);
213-
log.debug('Added CICD label to PR ${pr.number}');
214-
await _scheduleIfMergeable(pullRequestEvent);
215-
} else {
216-
await scheduler.createAwaitingCicdLabelCheckRun(slug, pr.head!.sha!);
217-
}
210+
await _addCICDForRollersAndMembers(pullRequestEvent);
211+
await scheduler.createAwaitingCicdLabelCheckRun(slug, pr.head!.sha!);
218212
await _checkForTests(pullRequestEvent);
219213
await _tryReleaseApproval(pullRequestEvent);
220214
break;
@@ -248,31 +242,7 @@ final class GithubWebhookSubscription extends SubscriptionHandler {
248242
await _respondToPullRequestDequeued(pullRequestEvent);
249243
break;
250244
case 'synchronize':
251-
final isPrivileged = await _isPrivilegedUser(pr, slug);
252-
final hasLabel =
253-
pr.labels?.any((l) => l.name == Config.kCicdLabel) ?? false;
254-
final githubService = await config.createGithubService(slug);
255-
256-
if (isPrivileged) {
257-
if (hasLabel) {
258-
await _scheduleIfMergeable(pullRequestEvent);
259-
} else {
260-
await scheduler.createAwaitingCicdLabelCheckRun(
261-
slug,
262-
pr.head!.sha!,
263-
);
264-
}
265-
} else {
266-
if (hasLabel) {
267-
await githubService.removeLabel(
268-
slug,
269-
pr.number!,
270-
Config.kCicdLabel,
271-
);
272-
log.debug('Removed CICD label from PR ${pr.number}');
273-
}
274-
await scheduler.createAwaitingCicdLabelCheckRun(slug, pr.head!.sha!);
275-
}
245+
await _addCICDForRollersAndMembers(pullRequestEvent);
276246
break;
277247
// Ignore the rest of the events.
278248
case 'ready_for_review':
@@ -610,16 +580,27 @@ final class GithubWebhookSubscription extends SubscriptionHandler {
610580
);
611581
}
612582

613-
/// Returns true if the user is a roller or a member of flutter-hackers.
614-
Future<bool> _isPrivilegedUser(PullRequest pr, RepositorySlug slug) async {
615-
final isRoller = config.rollerAccounts.contains(pr.user!.login);
583+
Future<void> _addCICDForRollersAndMembers(
584+
PullRequestEvent pullRequestEvent,
585+
) async {
586+
final pr = pullRequestEvent.pullRequest!;
587+
final slug = pr.base!.repo!.slug();
588+
final author = pr.user!.login!;
616589
final githubService = await config.createGithubService(slug);
590+
591+
final isRoller = config.rollerAccounts.contains(pr.user!.login);
617592
final isFlutterHacker = await githubService.isTeamMember(
618593
'flutter-hackers',
619-
pr.user!.login!,
620-
'flutter',
594+
author,
595+
slug.owner,
621596
);
622-
return isRoller || isFlutterHacker;
597+
log.debug('isRoller=$isRoller, isFlutterHacker=$isFlutterHacker');
598+
599+
if (config.supportedRepos.contains(slug) && (isRoller || isFlutterHacker)) {
600+
final gitHubClient = await config.createGitHubClient(pullRequest: pr);
601+
await gitHubClient.issues.addLabelsToIssue(slug, pr.number!, ['CICD']);
602+
log.debug('Added CICD label to PR $pr.number');
603+
}
623604
}
624605

625606
Future<void> _checkForTests(PullRequestEvent pullRequestEvent) async {

app_dart/test/request_handlers/github/webhook_subscription_test.dart

Lines changed: 17 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3755,7 +3755,7 @@ void foo() {
37553755
});
37563756

37573757
test(
3758-
'opened PR with adds CICD label and schedules tests if author is member of flutter-hackers',
3758+
'opened PR with adds CICD label if author is member of flutter-hackers',
37593759
() async {
37603760
tester.message = generateGithubWebhookMessage(
37613761
action: 'opened',
@@ -3766,8 +3766,7 @@ void foo() {
37663766

37673767
verify(
37683768
issuesService.addLabelsToIssue(Config.flutterSlug, 123, ['CICD']),
3769-
).called(1);
3770-
expect(scheduler.triggerPresubmitTargetsCnt, 1);
3769+
);
37713770
},
37723771
);
37733772
test(
@@ -3862,87 +3861,50 @@ void foo() {
38623861
);
38633862

38643863
test(
3865-
'synchronize event by non-privileged user removes CICD label and creates awaiting checkrun',
3864+
'synchronize event with CICD label does not schedules tests',
38663865
() async {
3867-
githubService.checkRunsMock = '{"total_count": 0, "check_runs": [{}]}';
38683866
tester.message = generateGithubWebhookMessage(
38693867
action: 'synchronize',
38703868
withCicdLabel: true,
38713869
);
38723870

38733871
await tester.post(webhook);
3874-
3875-
expect(githubService.removedLabels, [
3876-
(Config.flutterSlug, 123, Config.kCicdLabel),
3877-
]);
3878-
verify(
3879-
mockGithubChecksUtil.createCheckRun(
3880-
any,
3881-
any,
3882-
any,
3883-
'Awaiting CICD label',
3884-
output: anyNamed('output'),
3885-
),
3886-
).called(1);
38873872
expect(scheduler.triggerPresubmitTargetsCnt, 0);
38883873
},
38893874
);
38903875

38913876
test(
3892-
'synchronize event by non-privileged user without label creates awaiting checkrun',
3877+
'synchronize event adds CICD label if author is member of flutter-hackers',
38933878
() async {
3894-
githubService.checkRunsMock = '{"total_count": 0, "check_runs": [{}]}';
38953879
tester.message = generateGithubWebhookMessage(
38963880
action: 'synchronize',
3897-
withCicdLabel: false,
3881+
login: 'test-flutter-hacker',
38983882
);
38993883

39003884
await tester.post(webhook);
3901-
39023885
verify(
3903-
mockGithubChecksUtil.createCheckRun(
3904-
any,
3905-
any,
3906-
any,
3907-
'Awaiting CICD label',
3908-
output: anyNamed('output'),
3909-
),
3910-
).called(1);
3911-
expect(scheduler.triggerPresubmitTargetsCnt, 0);
3886+
issuesService.addLabelsToIssue(Config.flutterSlug, 123, ['CICD']),
3887+
);
39123888
},
39133889
);
3914-
39153890
test(
3916-
'synchronize event by privileged user with label schedules tests',
3891+
'synchronize event does not add CICD label if author is not member of flutter-hackers',
39173892
() async {
3918-
tester.message = generateGithubWebhookMessage(
3919-
action: 'synchronize',
3920-
login: 'test-flutter-hacker',
3921-
withCicdLabel: true,
3922-
);
3893+
tester.message = generateGithubWebhookMessage(action: 'synchronize');
39233894

39243895
await tester.post(webhook);
3925-
3926-
expect(scheduler.triggerPresubmitTargetsCnt, 1);
39273896
verifyNever(
3928-
mockGithubChecksUtil.createCheckRun(
3929-
any,
3930-
any,
3931-
any,
3932-
'Awaiting CICD label',
3933-
output: anyNamed('output'),
3934-
),
3897+
issuesService.addLabelsToIssue(Config.flutterSlug, 123, any),
39353898
);
39363899
},
39373900
);
39383901

39393902
test(
3940-
'synchronize event by privileged user without label creates awaiting checkrun',
3903+
'opened PR without CICD label creates "Awaiting CICD label" checkrun',
39413904
() async {
39423905
githubService.checkRunsMock = '{"total_count": 0, "check_runs": [{}]}';
39433906
tester.message = generateGithubWebhookMessage(
3944-
action: 'synchronize',
3945-
login: 'test-flutter-hacker',
3907+
action: 'opened',
39463908
withCicdLabel: false,
39473909
);
39483910

@@ -3957,17 +3919,16 @@ void foo() {
39573919
output: anyNamed('output'),
39583920
),
39593921
).called(1);
3960-
expect(scheduler.triggerPresubmitTargetsCnt, 0);
39613922
},
39623923
);
39633924

39643925
test(
3965-
'opened PR without CICD label creates "Awaiting CICD label" checkrun',
3926+
'opened PR with CICD label STILL creates "Awaiting CICD label" checkrun if not exists',
39663927
() async {
39673928
githubService.checkRunsMock = '{"total_count": 0, "check_runs": [{}]}';
39683929
tester.message = generateGithubWebhookMessage(
39693930
action: 'opened',
3970-
withCicdLabel: false,
3931+
withCicdLabel: true,
39713932
);
39723933

39733934
await tester.post(webhook);
@@ -3985,12 +3946,12 @@ void foo() {
39853946
);
39863947

39873948
test(
3988-
'opened PR with CICD label STILL creates "Awaiting CICD label" checkrun if not exists',
3949+
'edited PR without CICD label creates "Awaiting CICD label" checkrun if not exists',
39893950
() async {
39903951
githubService.checkRunsMock = '{"total_count": 0, "check_runs": [{}]}';
39913952
tester.message = generateGithubWebhookMessage(
3992-
action: 'opened',
3993-
withCicdLabel: true,
3953+
action: 'edited',
3954+
withCicdLabel: false,
39943955
);
39953956

39963957
await tester.post(webhook);

0 commit comments

Comments
 (0)