Revert timing fix (#2097)
diff --git a/auto_submit/lib/service/approver_service.dart b/auto_submit/lib/service/approver_service.dart
index 98c9e24..4699a2f 100644
--- a/auto_submit/lib/service/approver_service.dart
+++ b/auto_submit/lib/service/approver_service.dart
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+import 'package:auto_submit/model/auto_submit_query_result.dart';
import 'package:auto_submit/service/log.dart';
import 'package:github/github.dart' as gh;
@@ -32,11 +33,12 @@
}
/// Auto approves a pull request when the revert label is present.
- Future<void> revertApproval(gh.PullRequest pullRequest) async {
+ Future<void> revertApproval(QueryResult queryResult, gh.PullRequest pullRequest) async {
final Set<String> approvedAuthorAssociations = <String>{'MEMBER', 'OWNER'};
final String? author = pullRequest.user!.login;
- final String? authorAssociation = pullRequest.authorAssociation;
+ // Use the QueryResult for this field
+ final String? authorAssociation = queryResult.repository!.pullRequest!.authorAssociation;
log.info('Attempting to approve revert request by author $author, authorAssociation $authorAssociation.');
diff --git a/auto_submit/lib/service/validation_service.dart b/auto_submit/lib/service/validation_service.dart
index 72560a4..ad7968d 100644
--- a/auto_submit/lib/service/validation_service.dart
+++ b/auto_submit/lib/service/validation_service.dart
@@ -199,7 +199,7 @@
if (revertValidationResult.result) {
// Approve the pull request automatically as it has been validated.
ApproverService approverService = ApproverService(config);
- await approverService.revertApproval(messagePullRequest);
+ await approverService.revertApproval(result, messagePullRequest);
bool processed = await processMerge(config, result, messagePullRequest);
if (processed) {
diff --git a/auto_submit/test/service/approver_service_test.dart b/auto_submit/test/service/approver_service_test.dart
index e71291d..b6c16bf 100644
--- a/auto_submit/test/service/approver_service_test.dart
+++ b/auto_submit/test/service/approver_service_test.dart
@@ -2,14 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+import 'package:auto_submit/model/auto_submit_query_result.dart';
import 'package:auto_submit/service/approver_service.dart';
-import 'package:github/github.dart';
+import 'package:github/github.dart' as gh;
import 'package:mockito/mockito.dart';
import 'package:test/test.dart';
import '../requests/github_webhook_test_data.dart';
import '../src/service/fake_config.dart';
import '../utilities/mocks.dart';
+import '../utilities/utils.dart';
void main() {
FakeConfig config;
@@ -23,66 +25,90 @@
service = ApproverService(config);
pullRequests = MockPullRequestsService();
when(github.pullRequests).thenReturn(pullRequests);
- when(pullRequests.createReview(any, any)).thenAnswer((_) async => PullRequestReview(id: 123, user: User()));
+ when(pullRequests.createReview(any, any)).thenAnswer((_) async => gh.PullRequestReview(id: 123, user: gh.User()));
});
test('Verify approval ignored', () async {
- PullRequest pr = generatePullRequest(author: 'not_a_user');
+ gh.PullRequest pr = generatePullRequest(author: 'not_a_user');
await service.autoApproval(pr);
verifyNever(pullRequests.createReview(any, captureAny));
});
test('Verify approve', () async {
- when(pullRequests.listReviews(any, any)).thenAnswer((_) => const Stream<PullRequestReview>.empty());
- PullRequest pr = generatePullRequest(author: 'dependabot[bot]');
+ when(pullRequests.listReviews(any, any)).thenAnswer((_) => const Stream<gh.PullRequestReview>.empty());
+ gh.PullRequest pr = generatePullRequest(author: 'dependabot[bot]');
await service.autoApproval(pr);
final List<dynamic> reviews = verify(pullRequests.createReview(any, captureAny)).captured;
expect(reviews.length, 1);
- final CreatePullRequestReview review = reviews.single as CreatePullRequestReview;
+ final gh.CreatePullRequestReview review = reviews.single as gh.CreatePullRequestReview;
expect(review.event, 'APPROVE');
});
test('Already approved', () async {
- PullRequestReview review = PullRequestReview(id: 123, user: User(login: 'fluttergithubbot'), state: 'APPROVED');
- when(pullRequests.listReviews(any, any)).thenAnswer((_) => Stream<PullRequestReview>.value(review));
- PullRequest pr = generatePullRequest(author: 'dependabot[bot]');
+ gh.PullRequestReview review =
+ gh.PullRequestReview(id: 123, user: gh.User(login: 'fluttergithubbot'), state: 'APPROVED');
+ when(pullRequests.listReviews(any, any)).thenAnswer((_) => Stream<gh.PullRequestReview>.value(review));
+ gh.PullRequest pr = generatePullRequest(author: 'dependabot[bot]');
await service.autoApproval(pr);
verifyNever(pullRequests.createReview(any, captureAny));
});
test('AutoApproval does not approve revert pull request.', () async {
- PullRequest pr = generatePullRequest(author: 'not_a_user');
- List<IssueLabel> issueLabels = pr.labels ?? [];
- IssueLabel issueLabel = IssueLabel(name: 'revert');
+ gh.PullRequest pr = generatePullRequest(author: 'not_a_user');
+ List<gh.IssueLabel> issueLabels = pr.labels ?? [];
+ gh.IssueLabel issueLabel = gh.IssueLabel(name: 'revert');
issueLabels.add(issueLabel);
await service.autoApproval(pr);
verifyNever(pullRequests.createReview(any, captureAny));
});
test('Revert request is auto approved.', () async {
- when(pullRequests.listReviews(any, any)).thenAnswer((_) => const Stream<PullRequestReview>.empty());
- PullRequest pr = generatePullRequest(author: 'dependabot[bot]');
+ when(pullRequests.listReviews(any, any)).thenAnswer((_) => const Stream<gh.PullRequestReview>.empty());
+ gh.PullRequest pr = generatePullRequest(author: 'dependabot[bot]');
- List<IssueLabel> issueLabels = pr.labels ?? [];
- IssueLabel issueLabel = IssueLabel(name: 'revert');
+ List<gh.IssueLabel> issueLabels = pr.labels ?? [];
+ gh.IssueLabel issueLabel = gh.IssueLabel(name: 'revert');
issueLabels.add(issueLabel);
- await service.revertApproval(pr);
+ PullRequestHelper flutterRequest = PullRequestHelper(
+ prNumber: 0,
+ lastCommitHash: oid,
+ reviews: <PullRequestReviewHelper>[],
+ );
+ QueryResult queryResult = createQueryResult(flutterRequest);
+
+ await service.revertApproval(queryResult, pr);
final List<dynamic> reviews = verify(pullRequests.createReview(any, captureAny)).captured;
expect(reviews.length, 1);
- final CreatePullRequestReview review = reviews.single as CreatePullRequestReview;
+ final gh.CreatePullRequestReview review = reviews.single as gh.CreatePullRequestReview;
expect(review.event, 'APPROVE');
});
test('Revert request is not auto approved when the revert label is not present.', () async {
- PullRequest pr = generatePullRequest(author: 'not_a_user');
- await service.revertApproval(pr);
+ gh.PullRequest pr = generatePullRequest(author: 'not_a_user');
+
+ PullRequestHelper flutterRequest = PullRequestHelper(
+ prNumber: 0,
+ lastCommitHash: oid,
+ reviews: <PullRequestReviewHelper>[],
+ );
+ QueryResult queryResult = createQueryResult(flutterRequest);
+
+ await service.revertApproval(queryResult, pr);
verifyNever(pullRequests.createReview(any, captureAny));
});
test('Revert request is not auto approved on bad author association.', () async {
- PullRequest pr = generatePullRequest(author: 'not_a_user', authorAssociation: 'CONTRIBUTOR');
- await service.revertApproval(pr);
+ gh.PullRequest pr = generatePullRequest(author: 'not_a_user', authorAssociation: 'CONTRIBUTOR');
+
+ PullRequestHelper flutterRequest = PullRequestHelper(
+ prNumber: 0,
+ lastCommitHash: oid,
+ reviews: <PullRequestReviewHelper>[],
+ );
+ QueryResult queryResult = createQueryResult(flutterRequest);
+
+ await service.revertApproval(queryResult, pr);
verifyNever(pullRequests.createReview(any, captureAny));
});
}
diff --git a/auto_submit/test/utilities/mocks.mocks.dart b/auto_submit/test/utilities/mocks.mocks.dart
index 33d35ac..b69010b 100644
--- a/auto_submit/test/utilities/mocks.mocks.dart
+++ b/auto_submit/test/utilities/mocks.mocks.dart
@@ -4,8 +4,9 @@
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i6;
-import 'dart:typed_data' as _i7;
+import 'dart:typed_data' as _i8;
+import 'package:auto_submit/model/auto_submit_query_result.dart' as _i7;
import 'package:auto_submit/service/approver_service.dart' as _i5;
import 'package:auto_submit/service/config.dart' as _i2;
import 'package:github/github.dart' as _i4;
@@ -205,8 +206,8 @@
returnValue: _i6.Future<void>.value(),
returnValueForMissingStub: _i6.Future<void>.value()) as _i6.Future<void>);
@override
- _i6.Future<void> revertApproval(_i4.PullRequest? pullRequest) =>
- (super.noSuchMethod(Invocation.method(#revertApproval, [pullRequest]),
+ _i6.Future<void> revertApproval(_i7.QueryResult? queryResult, _i4.PullRequest? pullRequest) =>
+ (super.noSuchMethod(Invocation.method(#revertApproval, [queryResult, pullRequest]),
returnValue: _i6.Future<void>.value(),
returnValueForMissingStub: _i6.Future<void>.value()) as _i6.Future<void>);
}
@@ -980,8 +981,8 @@
}
@override
- _i7.Uint8List get bodyBytes =>
- (super.noSuchMethod(Invocation.getter(#bodyBytes), returnValue: _i7.Uint8List(0)) as _i7.Uint8List);
+ _i8.Uint8List get bodyBytes =>
+ (super.noSuchMethod(Invocation.getter(#bodyBytes), returnValue: _i8.Uint8List(0)) as _i8.Uint8List);
@override
String get body => (super.noSuchMethod(Invocation.getter(#body), returnValue: '') as String);
@override
diff --git a/dashboard/pubspec.lock b/dashboard/pubspec.lock
index 9c194aa..789e94e 100644
--- a/dashboard/pubspec.lock
+++ b/dashboard/pubspec.lock
@@ -489,7 +489,7 @@
name: test_api
url: "https://pub.dartlang.org"
source: hosted
- version: "0.4.12"
+ version: "0.4.13"
timing:
dependency: transitive
description:
@@ -566,7 +566,7 @@
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
- version: "2.1.2"
+ version: "2.1.3"
watcher:
dependency: transitive
description:
@@ -589,5 +589,5 @@
source: hosted
version: "3.1.1"
sdks:
- dart: ">=2.17.0 <3.0.0"
+ dart: ">=2.18.0-146.0.dev <3.0.0"
flutter: ">=2.10.0"