-
Notifications
You must be signed in to change notification settings - Fork 9
/
github_dsl.dart
427 lines (330 loc) · 9.95 KB
/
github_dsl.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
import 'package:danger_core/src/models/git_dsl.dart';
import 'package:json_annotation/json_annotation.dart'
if (dart.library.isolate) 'package:danger_core/src/mock_json_annotation.dart';
part 'github_dsl.g.dart';
enum GitHubPRState {
@JsonValue('closed')
closed,
@JsonValue('open')
open,
@JsonValue('locked')
locked,
@JsonValue('merged')
merged,
}
enum GitHubUserType {
@JsonValue('User')
user,
@JsonValue('Organization')
organization,
@JsonValue('Bot')
bot,
}
enum GitHubPRAuthorAssociation {
@JsonValue('COLLABORATOR')
collaborator,
@JsonValue('CONTRIBUTOR')
contributor,
@JsonValue('FIRST_TIMER')
firstTimer,
@JsonValue('FIRST_TIME_CONTRIBUTOR')
firstTimeContributor,
@JsonValue('MEMBER')
member,
@JsonValue('NONE')
none,
@JsonValue('OWNER')
owner,
}
enum GitHubReviewState {
@JsonValue('APPROVED')
approved,
@JsonValue('CHANGES_REQUESTED')
changesRequested,
@JsonValue('DISMISSED')
dimissed,
@JsonValue('REQUEST_CHANGES')
requestChanges,
@JsonValue('COMMENT')
comment,
@JsonValue('PENDING')
pending,
@JsonValue('COMMENTED')
commented,
}
@JsonSerializable()
class GitHubDSL {
/// The issue metadata for a code review session
final GitHubIssue issue;
/// The PR metadata for a code review session
final GitHubPRDSL pr;
/// The PR metadata specifically formatted for using with the GitHub API client
final GitHubAPIPR thisPR;
/// The github commit metadata for a code review session
final List<GitHubCommit> commits;
/// The reviews left on this pull request
final List<GitHubReview> reviews;
/// The people/teams requested to review this PR
@JsonKey(name: 'requested_reviewers')
final GitHubReviewers requested_reviewers;
GitHubDSL(
{this.issue,
this.pr,
this.thisPR,
this.commits,
this.reviews,
this.requested_reviewers});
factory GitHubDSL.fromJson(Map<String, dynamic> json) =>
_$GitHubDSLFromJson(json);
Map<String, dynamic> toJson() => _$GitHubDSLToJson(this);
}
@JsonSerializable()
class GitHubPRDSL {
/// The UUID for the PR
final int number;
/// The state for the PR
final GitHubPRState state;
/// Has the PR been locked to contributors only?
final bool locked;
/// The title of the PR
final String title;
/// The markdown body message of the PR
final String body;
/// ISO6801 Date string for when PR was created
@JsonKey(name: 'created_at')
final String createdAt;
/// ISO6801 Date string for when PR was updated
@JsonKey(name: 'updated_at')
final String updatedAt;
/// optional ISO6801 Date string for when PR was closed
@JsonKey(name: 'closed_at')
final String closedAt;
/// Optional ISO6801 Date string for when PR was merged.
@JsonKey(name: 'merged_at')
final String mergedAt;
/// Merge reference for the _other_ repo.
final GitHubMergeRef head;
/// Merge reference for _this_ repo.
final GitHubMergeRef base;
/// The User who submitted the PR
final GitHubUser user;
/// The User who is assigned the PR
final GitHubUser assignee;
/// The Users who are assigned to the PR
final List<GitHubUser> assignees;
/// Has the PR been merged yet?
final bool merged;
/// The number of comments on the PR
final int comments;
/// The number of review-specific comments on the PR
@JsonKey(name: 'review_comments')
final int reviewComments;
/// The number of commits in the PR
final int commits;
/// The number of additional lines in the PR
final int additions;
/// The number of deleted lines in the PR
final int deletions;
/// The number of changed files in the PR
@JsonKey(name: 'changed_files')
final int changedFiles;
/// The link back to this PR as user-facing
@JsonKey(name: 'html_url')
final String htmlUrl;
/// How does the PR author relate to this repo/org?
@JsonKey(name: 'author_association')
final GitHubPRAuthorAssociation authorAssociation;
GitHubPRDSL(
{this.number,
this.state,
this.locked,
this.title,
this.body,
this.createdAt,
this.updatedAt,
this.closedAt,
this.mergedAt,
this.head,
this.base,
this.user,
this.assignee,
this.assignees,
this.merged,
this.comments,
this.reviewComments,
this.commits,
this.additions,
this.deletions,
this.changedFiles,
this.htmlUrl,
this.authorAssociation});
factory GitHubPRDSL.fromJson(Map<String, dynamic> json) =>
_$GitHubPRDSLFromJson(json);
Map<String, dynamic> toJson() => _$GitHubPRDSLToJson(this);
}
@JsonSerializable()
class GitHubIssue {
/// The labels associated with this issue
final List<GitHubIssueLabel> labels;
GitHubIssue({this.labels});
factory GitHubIssue.fromJson(Map<String, dynamic> json) =>
_$GitHubIssueFromJson(json);
Map<String, dynamic> toJson() => _$GitHubIssueToJson(this);
}
@JsonSerializable()
class GitHubIssueLabel {
/// The identifying number of this label
final int id;
/// The URL that links to this label
final String url;
/// The name of the label
final String name;
/// The color associated with this label
final String color;
GitHubIssueLabel({this.id, this.url, this.name, this.color});
factory GitHubIssueLabel.fromJson(Map<String, dynamic> json) =>
_$GitHubIssueLabelFromJson(json);
Map<String, dynamic> toJson() => _$GitHubIssueLabelToJson(this);
}
@JsonSerializable()
class GitHubUser {
/// Generic UUID
final int id;
/// The handle for the user/org
final String login;
/// Whether the user is an org, or a user
final GitHubUserType type;
///The url for a users's image
@JsonKey(name: 'avatar_url')
final String avatarUrl;
///The href for a users's page
final String href;
GitHubUser({this.id, this.login, this.type, this.avatarUrl, this.href});
factory GitHubUser.fromJson(Map<String, dynamic> json) =>
_$GitHubUserFromJson(json);
Map<String, dynamic> toJson() => _$GitHubUserToJson(this);
}
@JsonSerializable()
class GitHubRepo {
/// Generic UUID
final int id;
/// The name of the repo, e.g. "Danger-JS"
final String name;
/// The full name of the owner + repo, e.g. "Danger/Danger-JS"
@JsonKey(name: 'full_name')
final String fullName;
/// The owner of the repo
final GitHubUser owner;
/// Is the repo publicly accessible?
final bool private;
/// The textual description of the repo
final String description;
/// Is the repo a fork?
final bool fork;
/// Is someone assigned to this PR?
final GitHubUser assignee;
/// Are there people assigned to this PR?
final List<GitHubUser> assignees;
/// The root web URL for the repo, e.g. https://github.com/artsy/emission
@JsonKey(name: 'html_url')
final String htmlUrl;
GitHubRepo(
{this.id,
this.name,
this.fullName,
this.owner,
this.private,
this.description,
this.fork,
this.assignee,
this.assignees,
this.htmlUrl});
factory GitHubRepo.fromJson(Map<String, dynamic> json) =>
_$GitHubRepoFromJson(json);
Map<String, dynamic> toJson() => _$GitHubRepoToJson(this);
}
@JsonSerializable()
class GitHubMergeRef {
/// The human display name for the merge reference, e.g. "artsy:master"
final String label;
/// The reference point for the merge, e.g. "master"
final String ref;
/// The reference point for the merge, e.g. "704dc55988c6996f69b6873c2424be7d1de67bbe"
final String sha;
/// The user that owns the merge reference e.g. "artsy"
final GitHubUser user;
/// The repo from whch the reference comes from
final GitHubRepo repo;
GitHubMergeRef({this.label, this.ref, this.sha, this.user, this.repo});
factory GitHubMergeRef.fromJson(Map<String, dynamic> json) =>
_$GitHubMergeRefFromJson(json);
Map<String, dynamic> toJson() => _$GitHubMergeRefToJson(this);
}
@JsonSerializable()
class GitHubAPIPR {
/// The repo owner
final String owner;
/// The repo name
final String repo;
/// The PR number
final int number;
GitHubAPIPR({this.owner, this.repo, this.number});
factory GitHubAPIPR.fromJson(Map<String, dynamic> json) =>
_$GitHubAPIPRFromJson(json);
Map<String, dynamic> toJson() => _$GitHubAPIPRToJson(this);
}
@JsonSerializable()
class GitHubCommit {
/// The raw commit metadata
final GitCommit commit;
/// The SHA for the commit
final String sha;
/// the url for the commit on GitHub
final String url;
/// The GitHub user who wrote the code
final GitHubUser author;
/// The GitHub user who shipped the code
final GitHubUser committer;
/// An array of parent commit shas
final List<dynamic> parents;
GitHubCommit(
{this.commit,
this.sha,
this.url,
this.author,
this.committer,
this.parents});
factory GitHubCommit.fromJson(Map<String, dynamic> json) =>
_$GitHubCommitFromJson(json);
Map<String, dynamic> toJson() => _$GitHubCommitToJson(this);
}
@JsonSerializable()
class GitHubReview {
/// The user requested to review, or the user who has completed the review
final GitHubUser user;
/// If there is a review, this provides the ID for it
final int id;
/// If there is a review, the body of the review
final String body;
/// If there is a review, the commit ID this review was made on
@JsonKey(name: 'commit_id')
final String commitId;
/// The state of the review
/// * APPROVED, REQUEST_CHANGES, COMMENT or PENDING
final GitHubReviewState state;
GitHubReview({this.user, this.id, this.body, this.commitId, this.state});
factory GitHubReview.fromJson(Map<String, dynamic> json) =>
_$GitHubReviewFromJson(json);
Map<String, dynamic> toJson() => _$GitHubReviewToJson(this);
}
@JsonSerializable()
class GitHubReviewers {
/// Users that have been requested
final List<GitHubUser> users;
/// Teams that have been requested
final List<dynamic> teams;
GitHubReviewers({this.users, this.teams});
factory GitHubReviewers.fromJson(Map<String, dynamic> json) =>
_$GitHubReviewersFromJson(json);
Map<String, dynamic> toJson() => _$GitHubReviewersToJson(this);
}