Skip to content

Commit

Permalink
Handle 'null' conclusion
Browse files Browse the repository at this point in the history
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 SpinlockLabs#412
  • Loading branch information
jtmcdole committed Dec 6, 2024
1 parent 8169398 commit 89d0ebd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/src/common/model/checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
11 changes: 11 additions & 0 deletions test/unit/checks_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand All @@ -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
///
Expand Down

0 comments on commit 89d0ebd

Please sign in to comment.