Skip to content

Commit 4256ac1

Browse files
jtmcdolerobrbecker
andauthored
Handle 'null' conclusion (#413)
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 Co-authored-by: Rob Becker <[email protected]>
1 parent d13786f commit 4256ac1

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/src/common/model/checks.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class CheckRunConclusion extends EnumWithValue {
5454
const CheckRunConclusion._(super.value);
5555

5656
factory CheckRunConclusion._fromValue(String? value) {
57-
if (value == null) {
57+
if (value == null || value == 'null') {
5858
return empty;
5959
}
6060
for (final level in const [

test/unit/checks_test.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ const checkRunJson = '''{
100100
const String expectedToString =
101101
'{"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"}';
102102

103+
const String newCheckRun =
104+
'{"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"}';
105+
103106
void main() {
104107
group('Check run', () {
105108
test('CheckRun fromJson', () {
@@ -110,6 +113,14 @@ void main() {
110113
expect(checkRun.conclusion, CheckRunConclusion.neutral);
111114
});
112115

116+
test('CheckRun from freshly created and encoded', () {
117+
final checkRun = CheckRun.fromJson(jsonDecode(newCheckRun));
118+
119+
expect(checkRun.id, 12345);
120+
expect(checkRun.name, 'New CheckRun');
121+
expect(checkRun.conclusion, CheckRunConclusion.empty);
122+
});
123+
113124
test('CheckRun fromJson for skipped conclusion', () {
114125
/// The checkRun Json is the official Github values
115126
///

0 commit comments

Comments
 (0)