Skip to content

Commit

Permalink
Remove bad json for CheckRuns (#4074)
Browse files Browse the repository at this point in the history
- library doesn't handle this even though it encodes it.
  • Loading branch information
jtmcdole authored Dec 5, 2024
1 parent 75a48ef commit 08d6d03
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
16 changes: 13 additions & 3 deletions app_dart/lib/src/service/scheduler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ class Scheduler {
log.info('$logCrumb: Merge Queue finished successfully');

// Unlock the guarding check_run.
final checkRunGuard = CheckRun.fromJson(json.decode(conclusion.checkRunGuard!));
final checkRunGuard = checkRunFromString(conclusion.checkRunGuard!);
await unlockMergeGroupChecks(slug, sha, checkRunGuard, null);
}

Expand All @@ -880,7 +880,7 @@ class Scheduler {
log.info('$logCrumb: Stage failed: $stage with failed=${conclusion.failed}');

// Unlock the guarding check_run.
final checkRunGuard = CheckRun.fromJson(json.decode(conclusion.checkRunGuard!));
final checkRunGuard = checkRunFromString(conclusion.checkRunGuard!);
await unlockMergeGroupChecks(slug, sha, checkRunGuard, 'failed ${conclusion.failed} test');
}

Expand All @@ -894,7 +894,7 @@ class Scheduler {
}) async {
log.info('$logCrumb: Stage completed: $stage with failed=${conclusion.failed}');

final checkRunGuard = CheckRun.fromJson(json.decode(conclusion.checkRunGuard!));
final checkRunGuard = checkRunFromString(conclusion.checkRunGuard!);

// Look up the PR in our cache first. This reduces github quota and requires less calls.
PullRequest? pullRequest;
Expand Down Expand Up @@ -1154,4 +1154,14 @@ class Scheduler {

return totCommit;
}

/// Parses CheckRun from a previously json string encode
CheckRun checkRunFromString(String input) {
final checkRunJson = json.decode(input) as Map<String, dynamic>;
// Workaround for https://github.com/SpinlockLabs/github.dart/issues/412
if (checkRunJson['conclusion'] == 'null') {
checkRunJson.remove('conclusion');
}
return CheckRun.fromJson(checkRunJson);
}
}
9 changes: 9 additions & 0 deletions app_dart/test/service/scheduler_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2041,6 +2041,15 @@ targets:
);
});
});

test('busted CheckRun does not kill the system', () {
final data = scheduler.checkRunFromString(
'{"name":"Merge Queue Guard","id":33947747856,"external_id":"","status":"queued","head_sha":"","check_suite":{"id":31681571627},"details_url":"https://flutter-dashboard.appspot.com","started_at":"2024-12-05T01:05:24.000Z","conclusion":"null"}',
);
expect(data.name, 'Merge Queue Guard');
expect(data.id, 33947747856);
expect(data.conclusion, CheckRunConclusion.empty);
});
});
}

Expand Down

0 comments on commit 08d6d03

Please sign in to comment.