Autosubmit remove label on missing tree status for #106914 (#1961)
diff --git a/auto_submit/lib/validations/ci_successful.dart b/auto_submit/lib/validations/ci_successful.dart
index 19268dc..db01585 100644
--- a/auto_submit/lib/validations/ci_successful.dart
+++ b/auto_submit/lib/validations/ci_successful.dart
@@ -41,6 +41,17 @@
statuses.addAll(commit.status!.contexts!);
}
+ // We want to check statuses for luci-flutter and luci-engine but do not
+ // want to block on other repos like plugins or packages. If there are no
+ // statuses we want to remove the label but also warn the user and log a
+ // message for us.
+ // https://github.com/flutter/flutter/issues/106914
+ if (Config.reposWithTreeStatus.contains(slug) && statuses.isEmpty) {
+ log.warning('Statuses were not ready.');
+ return ValidationResult(
+ false, Action.REMOVE_LABEL, 'Try again when the tree status has been applied to this PR.');
+ }
+
/// Validate tree statuses are set.
validateTreeStatusIsSet(slug, statuses, failures);
@@ -114,7 +125,6 @@
for (ContextNode status in statuses) {
// How can name be null but presumed to not be null below when added to failure?
final String? name = status.context;
-
if (status.state != STATUS_SUCCESS) {
if (notInAuthorsControl.contains(name) && labelNames.contains(overrideTreeStatusLabel)) {
continue;
diff --git a/auto_submit/test/validations/ci_successful_test.dart b/auto_submit/test/validations/ci_successful_test.dart
index a7234b6..e2ee5b0 100644
--- a/auto_submit/test/validations/ci_successful_test.dart
+++ b/auto_submit/test/validations/ci_successful_test.dart
@@ -249,6 +249,7 @@
ciSuccessful.validateTreeStatusIsSet(slug, contextNodeList, failures);
expect(failures, isNotEmpty);
expect(failures.length, 1);
+ expect(failures.elementAt(0).name.contains('tree status luci-flutter'), isTrue);
});
});
@@ -268,12 +269,30 @@
githubService.checkRunsData = checkRunsMock;
ciSuccessful.validate(queryResult, npr).then((value) {
- // No failure.
- expect(true, value.result);
+ // fails because in this case there is only a single fail status
+ expect(false, value.result);
// Remove label.
expect((value.action == Action.REMOVE_LABEL), isTrue);
- expect(value.message,
- '- The status or check suite [tree status luci-flutter](https://flutter-dashboard.appspot.com/#/build) has failed. Please fix the issues identified (or deflake) before re-applying this label.\n');
+ expect(value.message, 'Try again when the tree status has been applied to this PR.');
+ });
+ });
+
+ test('Commit has no statuses to verify.', () {
+ final Map<String, dynamic> queryResultJsonDecode = jsonDecode(noStatusInCommitJson) as Map<String, dynamic>;
+ final QueryResult queryResult = QueryResult.fromJson(queryResultJsonDecode);
+ expect(queryResult, isNotNull);
+ final PullRequest pr = queryResult.repository!.pullRequest!;
+ expect(pr, isNotNull);
+
+ final github.PullRequest npr = generatePullRequest(labelName: 'needs tests');
+ githubService.checkRunsData = checkRunsMock;
+
+ ciSuccessful.validate(queryResult, npr).then((value) {
+ // fails because in this case there is only a single fail status
+ expect(false, value.result);
+ // Remove label.
+ expect((value.action == Action.REMOVE_LABEL), isTrue);
+ expect(value.message, 'Try again when the tree status has been applied to this PR.');
});
});
diff --git a/auto_submit/test/validations/ci_successful_test_data.dart b/auto_submit/test/validations/ci_successful_test_data.dart
index 9676629..cf909f7 100644
--- a/auto_submit/test/validations/ci_successful_test_data.dart
+++ b/auto_submit/test/validations/ci_successful_test_data.dart
@@ -4,6 +4,49 @@
/// Constants used for testing in ci_successful_test.dart.
+const String noStatusInCommitJson = """
+{
+ "repository": {
+ "pullRequest": {
+ "author": {
+ "login": "author1"
+ },
+ "authorAssociation": "MEMBER",
+ "id": "PR_kwDOA8VHis43rs4_",
+ "title": "[dependabot] Remove human reviewers",
+ "commits": {
+ "nodes":[
+ {
+ "commit": {
+ "abbreviatedOid": "4009ecc",
+ "oid": "4009ecc0b6dbf5cb19cb97472147063e7368ec10",
+ "committedDate": "2022-05-11T22:35:02Z",
+ "pushedDate": "2022-05-11T22:35:03Z",
+ "status": {
+ "contexts":[
+
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "reviews": {
+ "nodes": [
+ {
+ "author": {
+ "login": "keyonghan"
+ },
+ "authorAssociation": "MEMBER",
+ "state": "APPROVED"
+ }
+ ]
+ }
+ }
+ }
+ }
+""";
+
const String nullStatusCommitRepositoryJson = """
{
"repository": {