Repository navigation
Expand file tree
/
Copy pathbuild-status.js
More file actions
83 lines (69 loc) · 1.69 KB
/
Copy pathbuild-status.js
File metadata and controls
83 lines (69 loc) · 1.69 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
// Commit or pull request build status, unified from those derived from the Checks API and the Status API.
const DEFAULT = {
icon: 'unverified',
classSuffix: 'pending',
};
const PENDING = {
icon: 'primitive-dot',
classSuffix: 'pending',
};
const SUCCESS = {
icon: 'check',
classSuffix: 'success',
};
const FAILURE = {
icon: 'x',
classSuffix: 'failure',
};
const ERROR = {
icon: 'alert',
classSuffix: 'failure',
};
const ACTION_REQUIRED = {
icon: 'bell',
classSuffix: 'failure',
};
const NEUTRAL = {
icon: 'dash',
classSuffix: 'neutral',
};
const STATUS_CONTEXT_MAP = {
EXPECTED: PENDING, PENDING, SUCCESS, ERROR, FAILURE,
};
export function buildStatusFromStatusContext({state}) {
return STATUS_CONTEXT_MAP[state] || DEFAULT;
}
const PENDING_CHECK_STATUSES = new Set(['QUEUED', 'IN_PROGRESS', 'REQUESTED']);
const COMPLETED_CHECK_CONCLUSION_MAP = {
SUCCESS, FAILURE, TIMED_OUT: ERROR, CANCELLED: ERROR, ACTION_REQUIRED, NEUTRAL,
};
export function buildStatusFromCheckResult({status, conclusion}) {
if (PENDING_CHECK_STATUSES.has(status)) {
return PENDING;
} else if (status === 'COMPLETED') {
return COMPLETED_CHECK_CONCLUSION_MAP[conclusion] || DEFAULT;
} else {
return DEFAULT;
}
}
const STATUS_PRIORITY = [
DEFAULT,
NEUTRAL,
SUCCESS,
PENDING,
FAILURE,
ERROR,
ACTION_REQUIRED,
];
export function combineBuildStatuses(...statuses) {
let highestPriority = 0;
let highestPriorityStatus = NEUTRAL;
for (const status of statuses) {
const priority = STATUS_PRIORITY.indexOf(status);
if (priority > highestPriority) {
highestPriority = priority;
highestPriorityStatus = status;
}
}
return highestPriorityStatus;
}