Skip to content

Commit 983eae2

Browse files
authored
Merge pull request #269 from CaseyHillers/checkrun-event
Add CheckSuiteEvent and CheckRunEvent
2 parents 28a3884 + af0f14d commit 983eae2

File tree

7 files changed

+702
-1
lines changed

7 files changed

+702
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 8.2.1
2+
- Add `CheckSuiteEvent` and `CheckRunEvent`
3+
14
## 8.2.0
25
- add more fields to the PullRequest class and fixed JSON naming bugs
36
- Added:

lib/src/common/model/checks.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,21 @@ class CheckRun {
124124
startedAt: DateTime.parse(input['started_at']),
125125
);
126126
}
127+
128+
Map<String, dynamic> toJson() {
129+
return <String, dynamic>{
130+
'name': name,
131+
'id': id,
132+
'external_id': externalId,
133+
'status': status,
134+
'head_sha': externalId,
135+
'check_suite': <String, dynamic>{
136+
'id': checkSuiteId,
137+
},
138+
'details_url': detailsUrl,
139+
'started_at': startedAt.toIso8601String(),
140+
};
141+
}
127142
}
128143

129144
@immutable
@@ -325,6 +340,7 @@ class CheckRunAction {
325340
}
326341
}
327342

343+
/// API docs: https://docs.github.com/en/rest/reference/checks#check-suites
328344
@immutable
329345
class CheckSuite {
330346
final int? id;
@@ -344,6 +360,14 @@ class CheckSuite {
344360
id: input['id'],
345361
);
346362
}
363+
364+
Map<String, dynamic> toJson() {
365+
return <String, dynamic>{
366+
'conclusion': conclusion,
367+
'head_sha': headSha,
368+
'id': id,
369+
};
370+
}
347371
}
348372

349373
@immutable

lib/src/server/hooks.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,43 @@ class UnknownHookEvent extends HookEvent {
8989
UnknownHookEvent(this.event, this.data);
9090
}
9191

92+
@JsonSerializable()
93+
class CheckRunEvent extends HookEvent {
94+
CheckRunEvent({
95+
this.action,
96+
this.checkRun,
97+
this.sender,
98+
this.repository,
99+
});
100+
101+
factory CheckRunEvent.fromJson(Map<String, dynamic> input) => _$CheckRunEventFromJson(input);
102+
CheckRun? checkRun;
103+
String? action;
104+
User? sender;
105+
Repository? repository;
106+
107+
Map<String, dynamic> toJson() => _$CheckRunEventToJson(this);
108+
}
109+
110+
@JsonSerializable()
111+
class CheckSuiteEvent extends HookEvent {
112+
CheckSuiteEvent({
113+
this.action,
114+
this.checkSuite,
115+
this.repository,
116+
this.sender,
117+
});
118+
119+
String? action;
120+
CheckSuite? checkSuite;
121+
Repository? repository;
122+
User? sender;
123+
124+
factory CheckSuiteEvent.fromJson(Map<String, dynamic> input) =>
125+
_$CheckSuiteEventFromJson(input);
126+
Map<String, dynamic> toJson() => _$CheckSuiteEventToJson(this);
127+
}
128+
92129
@JsonSerializable()
93130
class RepositoryEvent extends HookEvent {
94131
RepositoryEvent({

lib/src/server/hooks.g.dart

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: github
2-
version: 8.2.0
2+
version: 8.2.1
33
description: A high-level GitHub API Client Library that uses Github's v3 API
44
homepage: https://github.com/SpinlockLabs/github.dart
55

test/server/hooks_test.dart

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import 'dart:convert';
2+
import 'package:github/github.dart';
3+
import 'package:github/hooks.dart';
4+
import 'package:test/test.dart';
5+
6+
import 'hooks_test_data.dart';
7+
8+
void main() {
9+
group('CheckSuiteEvent', () {
10+
test('deserialize', () async {
11+
final checkSuiteEvent =
12+
CheckSuiteEvent.fromJson(json.decode(checkSuiteString) as Map<String, dynamic>);
13+
// Top level properties.
14+
expect(checkSuiteEvent.action, 'requested');
15+
expect(checkSuiteEvent.checkSuite, isA<CheckSuite>());
16+
// CheckSuite properties.
17+
final suite = checkSuiteEvent.checkSuite!;
18+
expect(suite.headSha, 'ec26c3e57ca3a959ca5aad62de7213c562f8c821');
19+
expect(suite.id, 118578147);
20+
expect(suite.conclusion, CheckRunConclusion.success);
21+
});
22+
});
23+
group('CheckRunEvent', () {
24+
test('deserialize', () async {
25+
final checkRunEvent = CheckRunEvent.fromJson(json.decode(checkRunString) as Map<String, dynamic>);
26+
// Top level properties.
27+
expect(checkRunEvent.action, 'created');
28+
expect(checkRunEvent.checkRun, isA<CheckRun>());
29+
// CheckSuite properties.
30+
final checkRun = checkRunEvent.checkRun!;
31+
expect(checkRun.headSha, 'ec26c3e57ca3a959ca5aad62de7213c562f8c821');
32+
expect(checkRun.checkSuiteId, 118578147);
33+
expect(checkRun.detailsUrl, 'https://octocoders.io');
34+
expect(checkRun.externalId, '');
35+
expect(checkRun.id, 128620228);
36+
expect(checkRun.name, 'Octocoders-linter');
37+
expect(checkRun.startedAt, DateTime.utc(2019, 05, 15, 15, 21, 12));
38+
expect(checkRun.status, CheckRunStatus.queued);
39+
});
40+
});
41+
}

0 commit comments

Comments
 (0)