Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/src/common/model/checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,14 @@ class CheckRunAction {
@immutable
class CheckSuite {
final int? id;
final String? headBranch;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the changelog and pubspec?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I wasn't sure about the version to use so lmk

final String? headSha;
final CheckRunConclusion conclusion;
final List<PullRequest> pullRequests;

const CheckSuite({
required this.conclusion,
required this.headBranch,
required this.headSha,
required this.id,
required this.pullRequests,
Expand All @@ -381,6 +383,7 @@ class CheckSuite {
.toList();
return CheckSuite(
conclusion: CheckRunConclusion._fromValue(input['conclusion']),
headBranch: input['head_branch'],
headSha: input['head_sha'],
id: input['id'],
pullRequests: pullRequests,
Expand Down
121 changes: 121 additions & 0 deletions test/unit/checksuite_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import 'dart:convert';

import 'package:github/src/common/model/checks.dart';
import 'package:test/test.dart';

/// The checkSuite Json is composed from multiple GitHub examples
///
/// See https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28
/// See https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28
const checkSuiteJson = '''{
"id": 5,
"head_branch": "main",
"head_sha": "d6fde92930d4715a2b49857d24b940956b26d2d3",
"conclusion": "neutral",
"pull_requests": [
{
"url": "https://api.github.com/repos/github/hello-world/pulls/1",
"id": 1934,
"number": 3956,
"head": {
"ref": "say-hello",
"sha": "3dca65fa3e8d4b3da3f3d056c59aee1c50f41390",
"repo": {
"id": 526,
"url": "https://api.github.com/repos/github/hello-world",
"name": "hello-world"
}
},
"base": {
"ref": "master",
"sha": "e7fdf7640066d71ad16a86fbcbb9c6a10a18af4f",
"repo": {
"id": 526,
"url": "https://api.github.com/repos/github/hello-world",
"name": "hello-world"
}
}
}
]
}''';

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"}';

void main() {
group('Check suite', () {
test('CheckSuite fromJson', () {
final checkSuite = CheckSuite.fromJson(jsonDecode(checkSuiteJson));

expect(checkSuite.id, 5);
expect(checkSuite.headBranch, 'main');
expect(checkSuite.headSha, 'd6fde92930d4715a2b49857d24b940956b26d2d3');
expect(checkSuite.conclusion, CheckRunConclusion.neutral);
expect(checkSuite.pullRequests.isNotEmpty, true);
});

test('CheckSuite fromJson for skipped conclusion', () {
/// The checkSuite Json is composed from multiple GitHub examples
///
/// See https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28
/// See https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28
const checkSuiteJson = '''{
"id": 10,
"head_branch": "master",
"head_sha": "ce587453ced02b1526dfb4cb910479d431683101",
"conclusion": "skipped",
"pull_requests": [
{
"url": "https://api.github.com/repos/github/hello-world/pulls/1",
"id": 1934,
"number": 3956,
"head": {
"ref": "say-hello",
"sha": "3dca65fa3e8d4b3da3f3d056c59aee1c50f41390",
"repo": {
"id": 526,
"url": "https://api.github.com/repos/github/hello-world",
"name": "hello-world"
}
},
"base": {
"ref": "master",
"sha": "e7fdf7640066d71ad16a86fbcbb9c6a10a18af4f",
"repo": {
"id": 526,
"url": "https://api.github.com/repos/github/hello-world",
"name": "hello-world"
}
}
}
]
}''';
final checkSuite = CheckSuite.fromJson(jsonDecode(checkSuiteJson));

expect(checkSuite.id, 10);
expect(checkSuite.headBranch, 'master');
expect(checkSuite.headSha, 'ce587453ced02b1526dfb4cb910479d431683101');
expect(checkSuite.conclusion, CheckRunConclusion.skipped);
expect(checkSuite.pullRequests.isNotEmpty, true);
});

test('CheckSuite fromJson for forked repository', () {
/// The checkSuite Json is composed from multiple GitHub examples
///
/// See https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28
/// See https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28
const checkSuiteJson = '''{
"id": 10,
"head_branch": null,
"head_sha": "ce587453ced02b1526dfb4cb910479d431683101",
"conclusion": "skipped",
"pull_requests": []
}''';
final checkSuite = CheckSuite.fromJson(jsonDecode(checkSuiteJson));

expect(checkSuite.id, 10);
expect(checkSuite.headBranch, null);
expect(checkSuite.pullRequests.isEmpty, true);
});
});
}