Skip to content

Commit

Permalink
Merge pull request #269 from CaseyHillers/checkrun-event
Browse files Browse the repository at this point in the history
Add CheckSuiteEvent and CheckRunEvent
  • Loading branch information
robrbecker authored Oct 18, 2021
2 parents 28a3884 + af0f14d commit 983eae2
Show file tree
Hide file tree
Showing 7 changed files with 702 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 8.2.1
- Add `CheckSuiteEvent` and `CheckRunEvent`

## 8.2.0
- add more fields to the PullRequest class and fixed JSON naming bugs
- Added:
Expand Down
24 changes: 24 additions & 0 deletions lib/src/common/model/checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ class CheckRun {
startedAt: DateTime.parse(input['started_at']),
);
}

Map<String, dynamic> toJson() {
return <String, dynamic>{
'name': name,
'id': id,
'external_id': externalId,
'status': status,
'head_sha': externalId,
'check_suite': <String, dynamic>{
'id': checkSuiteId,
},
'details_url': detailsUrl,
'started_at': startedAt.toIso8601String(),
};
}
}

@immutable
Expand Down Expand Up @@ -325,6 +340,7 @@ class CheckRunAction {
}
}

/// API docs: https://docs.github.com/en/rest/reference/checks#check-suites
@immutable
class CheckSuite {
final int? id;
Expand All @@ -344,6 +360,14 @@ class CheckSuite {
id: input['id'],
);
}

Map<String, dynamic> toJson() {
return <String, dynamic>{
'conclusion': conclusion,
'head_sha': headSha,
'id': id,
};
}
}

@immutable
Expand Down
37 changes: 37 additions & 0 deletions lib/src/server/hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,43 @@ class UnknownHookEvent extends HookEvent {
UnknownHookEvent(this.event, this.data);
}

@JsonSerializable()
class CheckRunEvent extends HookEvent {
CheckRunEvent({
this.action,
this.checkRun,
this.sender,
this.repository,
});

factory CheckRunEvent.fromJson(Map<String, dynamic> input) => _$CheckRunEventFromJson(input);
CheckRun? checkRun;
String? action;
User? sender;
Repository? repository;

Map<String, dynamic> toJson() => _$CheckRunEventToJson(this);
}

@JsonSerializable()
class CheckSuiteEvent extends HookEvent {
CheckSuiteEvent({
this.action,
this.checkSuite,
this.repository,
this.sender,
});

String? action;
CheckSuite? checkSuite;
Repository? repository;
User? sender;

factory CheckSuiteEvent.fromJson(Map<String, dynamic> input) =>
_$CheckSuiteEventFromJson(input);
Map<String, dynamic> toJson() => _$CheckSuiteEventToJson(this);
}

@JsonSerializable()
class RepositoryEvent extends HookEvent {
RepositoryEvent({
Expand Down
46 changes: 46 additions & 0 deletions lib/src/server/hooks.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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: 8.2.0
version: 8.2.1
description: A high-level GitHub API Client Library that uses Github's v3 API
homepage: https://github.com/SpinlockLabs/github.dart

Expand Down
41 changes: 41 additions & 0 deletions test/server/hooks_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import 'dart:convert';
import 'package:github/github.dart';
import 'package:github/hooks.dart';
import 'package:test/test.dart';

import 'hooks_test_data.dart';

void main() {
group('CheckSuiteEvent', () {
test('deserialize', () async {
final checkSuiteEvent =
CheckSuiteEvent.fromJson(json.decode(checkSuiteString) as Map<String, dynamic>);
// Top level properties.
expect(checkSuiteEvent.action, 'requested');
expect(checkSuiteEvent.checkSuite, isA<CheckSuite>());
// CheckSuite properties.
final suite = checkSuiteEvent.checkSuite!;
expect(suite.headSha, 'ec26c3e57ca3a959ca5aad62de7213c562f8c821');
expect(suite.id, 118578147);
expect(suite.conclusion, CheckRunConclusion.success);
});
});
group('CheckRunEvent', () {
test('deserialize', () async {
final checkRunEvent = CheckRunEvent.fromJson(json.decode(checkRunString) as Map<String, dynamic>);
// Top level properties.
expect(checkRunEvent.action, 'created');
expect(checkRunEvent.checkRun, isA<CheckRun>());
// CheckSuite properties.
final checkRun = checkRunEvent.checkRun!;
expect(checkRun.headSha, 'ec26c3e57ca3a959ca5aad62de7213c562f8c821');
expect(checkRun.checkSuiteId, 118578147);
expect(checkRun.detailsUrl, 'https://octocoders.io');
expect(checkRun.externalId, '');
expect(checkRun.id, 128620228);
expect(checkRun.name, 'Octocoders-linter');
expect(checkRun.startedAt, DateTime.utc(2019, 05, 15, 15, 21, 12));
expect(checkRun.status, CheckRunStatus.queued);
});
});
}
Loading

0 comments on commit 983eae2

Please sign in to comment.