Skip to content

Commit

Permalink
Add "head_branch" field to CheckSuite object (#347)
Browse files Browse the repository at this point in the history
* Add "head_branch" field to CheckSuite object

* Add CheckSuite test

* Add forked repository test to validate behavior when "head_branch" is null

* Update CHANGELOG and pubspec
  • Loading branch information
nehalvpatel committed Jan 26, 2023
1 parent 067d7d3 commit 4f65537
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 9.8.0

* Add "head_branch" field to CheckSuite object by @nehalvpatel in https://github.com/SpinlockLabs/github.dart/pull/347

## New Contributors
* @nehalvpatel made their first contribution in https://github.com/SpinlockLabs/github.dart/pull/347

**Full Changelog**: https://github.com/SpinlockLabs/github.dart/compare/9.7.0...9.8.0

## 9.7.0
* Add calendar versioning by @CaseyHillers in https://github.com/SpinlockLabs/github.dart/pull/338

Expand Down
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;
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
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: github
version: 9.7.0
version: 9.8.0
description: A high-level GitHub API Client Library that uses Github's v3 API
homepage: https://github.com/SpinlockLabs/github.dart

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);
});
});
}

0 comments on commit 4f65537

Please sign in to comment.