Skip to content

Commit 742ab63

Browse files
authored
Merge pull request #203 from kevmoo/reactions
Reactions
2 parents bfeee33 + c6915ef commit 742ab63

File tree

10 files changed

+85
-5
lines changed

10 files changed

+85
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 6.1.0
2+
- Add (experimental) `listReactions` method to `IssueService`.
3+
14
## 6.0.6
25
- Clean up lints https://github.com/SpinlockLabs/github.dart/pull/202
36

lib/src/common.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export 'package:github/src/common/model/misc.dart';
1717
export 'package:github/src/common/model/notifications.dart';
1818
export 'package:github/src/common/model/orgs.dart';
1919
export 'package:github/src/common/model/pulls.dart';
20+
export 'package:github/src/common/model/reaction.dart';
2021
export 'package:github/src/common/model/repos.dart';
2122
export 'package:github/src/common/model/repos_commits.dart';
2223
export 'package:github/src/common/model/repos_contents.dart';

lib/src/common/github.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class GitHub {
229229
headers['Accept'] = preview;
230230
}
231231

232-
headers.putIfAbsent('Accept', () => 'application/vnd.github.v3+json');
232+
headers.putIfAbsent('Accept', () => v3ApiMimeType);
233233

234234
final response = await request(
235235
method,

lib/src/common/issues_service.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:async';
22
import 'dart:convert';
3+
34
import 'package:github/src/common.dart';
45
import 'package:github/src/common/model/users.dart';
56
import 'package:github/src/common/util/pagination.dart';
@@ -129,6 +130,19 @@ class IssuesService extends Service {
129130
);
130131
}
131132

133+
/// This API is currently in preview. It may break.
134+
///
135+
/// See https://developer.github.com/v3/reactions/
136+
Stream<Reaction> listReactions(RepositorySlug slug, int issueNumber) =>
137+
PaginationHelper(github).objects(
138+
'GET',
139+
'/repos/${slug.owner}/${slug.name}/issues/$issueNumber/reactions',
140+
(i) => Reaction.fromJson(i),
141+
headers: {
142+
'Accept': 'application/vnd.github.squirrel-girl-preview+json',
143+
},
144+
);
145+
132146
/// Edit an issue.
133147
///
134148
/// API docs: https://developer.github.com/v3/issues/#edit-an-issue

lib/src/common/model/reaction.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'package:github/src/common.dart';
2+
import 'package:github/src/common/model/users.dart';
3+
import 'package:json_annotation/json_annotation.dart';
4+
5+
part 'reaction.g.dart';
6+
7+
/// This API is currently in preview. It may break.
8+
///
9+
/// See https://developer.github.com/v3/reactions/
10+
@JsonSerializable(fieldRename: FieldRename.snake)
11+
class Reaction {
12+
final int id;
13+
final String nodeId;
14+
final User user;
15+
final String content;
16+
final DateTime createdAt;
17+
18+
Reaction({
19+
this.id,
20+
this.nodeId,
21+
this.user,
22+
this.content,
23+
this.createdAt,
24+
});
25+
26+
factory Reaction.fromJson(Map<String, dynamic> json) =>
27+
_$ReactionFromJson(json);
28+
29+
Map<String, dynamic> toJson() => _$ReactionToJson(this);
30+
}

lib/src/common/model/reaction.g.dart

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

lib/src/common/repos_service.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,8 +1140,8 @@ class RepositoriesService extends Service {
11401140
) async {
11411141
ArgumentError.checkNotNull(slug);
11421142
final path = '/repos/${slug.fullName}/stats/contributors';
1143-
final response = await github.request('GET', path,
1144-
headers: {'Accept': 'application/vnd.github.v3+json'});
1143+
final response =
1144+
await github.request('GET', path, headers: {'Accept': v3ApiMimeType});
11451145

11461146
if (response.statusCode == StatusCodes.OK) {
11471147
return (jsonDecode(response.body) as List)

lib/src/common/util/pagination.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'dart:convert' show jsonDecode;
44
import 'package:http/http.dart' as http;
55

66
import '../../common.dart';
7+
import '../../util.dart';
78

89
/// Internal Helper for dealing with GitHub Pagination.
910
class PaginationHelper {
@@ -93,7 +94,7 @@ class PaginationHelper {
9394
if (preview != null) {
9495
headers['Accept'] = preview;
9596
}
96-
headers.putIfAbsent('Accept', () => 'application/vnd.github.v3+json');
97+
headers.putIfAbsent('Accept', () => v3ApiMimeType);
9798

9899
await for (final response in fetchStreamed(method, path,
99100
pages: pages,

lib/src/util.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
final RegExp githubDateRemoveRegExp = RegExp(r'\.\d*');
22

3+
const v3ApiMimeType = 'application/vnd.github.v3+json';
4+
35
String buildQueryString(Map<String, dynamic> params) {
46
final queryString = StringBuffer();
57

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: 6.0.6
2+
version: 6.1.0-dev
33
description: A high-level GitHub API Client Library that uses Github's v3 API
44
homepage: https://github.com/SpinlockLabs/github.dart
55

0 commit comments

Comments
 (0)