-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.dart
52 lines (42 loc) · 1.28 KB
/
github.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import 'dart:convert';
import 'opensource_platform.dart';
import '../parser/todo.dart';
import '../utils/configuration.dart';
import '../core/http_client/http_client_interface.dart';
class GitHub extends IOpenSourcePlatform {
final IHttpClient httpClient;
GitHub(this.httpClient);
Map<String, String> getHeaders(Configuration configuration) {
return {
"accept": "application/vnd.github+json",
"Authorization": "Bearer ${configuration.githubToken}",
"Content-Type": "application/json"
};
}
String getUrl(Configuration configuration) {
return "/repos/${configuration.owner}/${configuration.repoNameGitHub}/issues";
}
Map<String, String> getBody(Todo todo) {
Map<String, String> body = {
"title": todo.title,
"body": todo.body,
};
if (todo.labels.isNotEmpty) {
body.putIfAbsent("labels", () => jsonEncode(todo.labels));
}
return body;
}
@override
Future<HttpResponse> createIssue(
Todo todo, Configuration configuration) async {
String url = getUrl(configuration);
Map<String, String> headers = getHeaders(configuration);
Map<String, String> body = getBody(todo);
HttpResponse response = await httpClient.post(
url,
headers: headers,
body: body,
);
return response;
}
}