-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcheck-runs.js
92 lines (84 loc) · 2.53 KB
/
check-runs.js
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
const queueCheckRun = async (context, token, owner, repo, ref, checkRunName, title, summary) => {
const githubApiRequest = require('./github-api-request')
// is there an existing check-run we can re-use?
const { check_runs } = await githubApiRequest(
context,
token,
'GET',
`/repos/${owner}/${repo}/commits/${ref}/check-runs`
)
const filtered = check_runs
.filter(e => e.name === checkRunName && e.conclusion === null).map(e => {
return {
id: e.id,
status: e.status
}
})
if (filtered.length > 0) {
// ensure that the check_run is set to status "in progress"
if (filtered[0].status !== 'queued') {
console.log(await githubApiRequest(
context,
token,
'PATCH',
`/repos/${owner}/${repo}/check-runs/${filtered[0].id}`, {
status: 'queued'
}
))
}
return filtered[0].id
}
const { id } = await githubApiRequest(
context,
token,
'POST',
`/repos/${owner}/${repo}/check-runs`, {
name: checkRunName,
head_sha: ref,
status: 'queued',
output: {
title,
summary
}
}
)
return id
}
const updateCheckRun = async (context, token, owner, repo, checkRunId, parameters) => {
const githubApiRequest = require('./github-api-request')
await githubApiRequest(
context,
token,
'PATCH',
`/repos/${owner}/${repo}/check-runs/${checkRunId}`,
parameters
)
}
const cancelWorkflowRun = async (context, token, owner, repo, workflowRunId) => {
const githubApiRequest = require('./github-api-request')
const answer = await githubApiRequest(
context,
token,
'POST',
`/repos/${owner}/${repo}/actions/runs/${workflowRunId}/cancel`
)
console.log(answer)
}
const listCheckRunsForCommit = async (context, token, owner, repo, rev, checkRunName) => {
const githubApiRequest = require('./github-api-request')
const answer = await githubApiRequest(
context,
token,
'GET',
`/repos/${owner}/${repo}/commits/${rev}/check-runs?per_page=100${
checkRunName ? `&check_name=${checkRunName}` : ''
}`
)
return answer.check_runs
}
module.exports = {
queueCheckRun,
updateCheckRun,
cancelWorkflowRun,
listCheckRunsForCommit
}