Repository navigation
Expand file tree
/
Copy pathissueish.js
More file actions
65 lines (54 loc) · 1.42 KB
/
Copy pathissueish.js
File metadata and controls
65 lines (54 loc) · 1.42 KB
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
import {URL} from 'url';
import moment from 'moment';
import {category} from '../views/pr-statuses-view';
export default class Issueish {
constructor(data) {
this.number = data.number;
this.title = data.title;
this.url = new URL(data.url);
this.authorLogin = data.author.login;
this.authorAvatarURL = new URL(data.author.avatarUrl);
this.createdAt = moment(data.createdAt, moment.ISO_8601);
this.headRefName = data.headRefName;
this.headRepositoryID = data.repository.id;
this.statusContexts = data.commits.nodes.reduce((acc, node) => {
const status = node.commit.status;
if (status !== null) {
acc.push(...status.contexts);
}
return acc;
}, []);
}
getNumber() {
return this.number;
}
getTitle() {
return this.title;
}
getGitHubURL() {
return this.url.toString();
}
getAuthorLogin() {
return this.authorLogin;
}
getAuthorAvatarURL(size = 32) {
const u = new URL(this.authorAvatarURL.toString());
u.searchParams.set('s', size);
return u.toString();
}
getCreatedAt() {
return this.createdAt;
}
getHeadRefName() {
return this.headRefName;
}
getHeadRepositoryID() {
return this.headRepositoryID;
}
getStatusCounts() {
return this.statusContexts.reduce((acc, context) => {
acc[category(context.state).toLowerCase()]++;
return acc;
}, {pending: 0, failure: 0, success: 0});
}
}