From 08d6d03f1cd7d62febe1901274250e05912d9673 Mon Sep 17 00:00:00 2001 From: John McDole Date: Thu, 5 Dec 2024 11:23:18 -0800 Subject: [PATCH] Remove bad json for CheckRuns (#4074) - library doesn't handle this even though it encodes it. --- app_dart/lib/src/service/scheduler.dart | 16 +++++++++++++--- app_dart/test/service/scheduler_test.dart | 9 +++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app_dart/lib/src/service/scheduler.dart b/app_dart/lib/src/service/scheduler.dart index 6d83efe0f..a0ca1e784 100644 --- a/app_dart/lib/src/service/scheduler.dart +++ b/app_dart/lib/src/service/scheduler.dart @@ -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); } @@ -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'); } @@ -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; @@ -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; + // Workaround for https://github.com/SpinlockLabs/github.dart/issues/412 + if (checkRunJson['conclusion'] == 'null') { + checkRunJson.remove('conclusion'); + } + return CheckRun.fromJson(checkRunJson); + } } diff --git a/app_dart/test/service/scheduler_test.dart b/app_dart/test/service/scheduler_test.dart index 41f8f2635..e292598ed 100644 --- a/app_dart/test/service/scheduler_test.dart +++ b/app_dart/test/service/scheduler_test.dart @@ -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); + }); }); }