From 89d0ebd2249e3ead6138d8d2172a6494c8c3879a Mon Sep 17 00:00:00 2001 From: John McDole Date: Fri, 6 Dec 2024 08:42:57 -0800 Subject: [PATCH] Handle 'null' conclusion Creating a new concolusion with the GitHub API and then encoding that CheckRun to json adds: `"conclusion":"null"` to the json string; attempting to decode that throws an exception. Fixes #412 --- lib/src/common/model/checks.dart | 2 +- test/unit/checks_test.dart | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/src/common/model/checks.dart b/lib/src/common/model/checks.dart index 5068febc..b7666579 100644 --- a/lib/src/common/model/checks.dart +++ b/lib/src/common/model/checks.dart @@ -54,7 +54,7 @@ class CheckRunConclusion extends EnumWithValue { const CheckRunConclusion._(super.value); factory CheckRunConclusion._fromValue(String? value) { - if (value == null) { + if (value == null || value == 'null') { return empty; } for (final level in const [ diff --git a/test/unit/checks_test.dart b/test/unit/checks_test.dart index 8af59043..2eb7e6c4 100644 --- a/test/unit/checks_test.dart +++ b/test/unit/checks_test.dart @@ -100,6 +100,9 @@ const checkRunJson = '''{ const String expectedToString = '{"name":"mighty_readme","id":4,"external_id":"","status":"completed","head_sha":"","check_suite":{"id":5},"details_url":"https://example.com","started_at":"2018-05-04T01:14:52.000Z","conclusion":"neutral"}'; +const String newCheckRun = + '{"name":"New CheckRun","id":12345,"external_id":"","status":"queued","head_sha":"","check_suite":{"id":123456},"details_url":"https://example.com","started_at":"2024-12-05T01:05:24.000Z","conclusion":"null"}'; + void main() { group('Check run', () { test('CheckRun fromJson', () { @@ -110,6 +113,14 @@ void main() { expect(checkRun.conclusion, CheckRunConclusion.neutral); }); + test('CheckRun from freshly created and encoded', () { + final checkRun = CheckRun.fromJson(jsonDecode(newCheckRun)); + + expect(checkRun.id, 12345); + expect(checkRun.name, 'New CheckRun'); + expect(checkRun.conclusion, CheckRunConclusion.empty); + }); + test('CheckRun fromJson for skipped conclusion', () { /// The checkRun Json is the official Github values ///