-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (49 loc) · 1.88 KB
/
index.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
// For more information on building apps:
// https://probot.github.io/docs/
// To get your app running against GitHub, see:
// https://probot.github.io/docs/development/
/**
* This is the main entrypoint to your Probot app
* @param {import('probot').Application} app
*/
module.exports = app => {
// app.on('issues.opened', async context => {
// app.log(context)
// const issueComment = context.issue({ body: 'Thanks for opening this issue!' })
// return context.github.issues.createComment(issueComment)
// })
app.on("check_run.completed", async context => {
const repo = context.payload.repository;
const owner = repo.owner.login;
const check_suite = context.payload.check_run.check_suite
if (check_suite.app.slug != "github-actions") {
return
}
const workflow_runs = (await context.github.actions.listRepoWorkflowRuns({
owner: owner,
repo: repo.name,
author: context.payload.sender.login
})).data.workflow_runs;
// TODO: There may be a race condition in retrieving the
// artifacts; sometimes the result is an empty list, but will
// succeed when run after a short break.
const artifacts = (await context.github.actions.listWorkflowRunArtifacts({
owner: owner,
repo: repo.name,
run_id: workflow_runs[0].id
})).data.artifacts;
app.log(check_suite.pull_requests)
// TODO: The check_suite event is not guaranteed to have associated pull requests
for (const pull of check_suite.pull_requests) {
app.log(pull)
const message = `Draft PDF in [${artifacts[0].name}.zip](https://github.com/${owner}/${repo.name}/suites/${check_suite.id}/artifacts/${artifacts[0].id})`
app.log(message)
return context.github.issues.createComment({
owner: owner,
repo: repo.name,
issue_number: pull.number,
body: message
});
}
});
};