Repository navigation
Expand file tree
/
Copy pathissueish.js
More file actions
104 lines (85 loc) · 2.17 KB
/
Copy pathissueish.js
File metadata and controls
104 lines (85 loc) · 2.17 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
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
import {URL} from 'url';
import moment from 'moment';
import {
buildStatusFromStatusContext,
buildStatusFromCheckResult,
} from './build-status';
import {GHOST_USER} from '../helpers';
export default class Issueish {
constructor(data) {
const author = data.author || GHOST_USER;
this.number = data.number;
this.title = data.title;
this.url = new URL(data.url);
this.authorLogin = author.login;
this.authorAvatarURL = new URL(author.avatarUrl);
this.createdAt = moment(data.createdAt, moment.ISO_8601);
this.headRefName = data.headRefName;
this.headRepositoryID = data.repository.id;
this.latestCommit = null;
this.statusContexts = [];
this.checkRuns = [];
if (data.commits.nodes.length > 0) {
this.latestCommit = data.commits.nodes[0].commit;
}
if (this.latestCommit && this.latestCommit.status) {
this.statusContexts = this.latestCommit.status.contexts;
}
}
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;
}
getLatestCommit() {
return this.latestCommit;
}
setCheckRuns(runsBySuite) {
this.checkRuns = [];
for (const [, runs] of runsBySuite) {
for (const checkRun of runs) {
this.checkRuns.push(checkRun);
}
}
}
getStatusCounts() {
const buildStatuses = [];
for (const context of this.statusContexts) {
buildStatuses.push(buildStatusFromStatusContext(context));
}
for (const checkRun of this.checkRuns) {
buildStatuses.push(buildStatusFromCheckResult(checkRun));
}
const counts = {
pending: 0,
failure: 0,
success: 0,
neutral: 0,
};
for (const {classSuffix} of buildStatuses) {
counts[classSuffix]++;
}
return counts;
}
}