forked from adafruit/circuitpython-action-library-ci-failed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (33 loc) · 1.73 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
const core = require('@actions/core');
const github = require('@actions/github');
async function run() {
const token = core.getInput('token');
const octokit = github.getOctokit(token);
const repo = github.context.payload.repository;
const workflow_run = github.context.payload.workflow_run;
const issue = workflow_run.pull_requests[0];
// Use a reaction to track if we've replied already. 201 is returned
// the first time we set it. 200 if it was already created. This saves
// us from having to look through all of the existing comments.
try {
const result = await octokit.reactions.createForIssue({
issue_number: issue.number,
owner: repo.owner.login,
repo: repo.name,
content: 'eyes'
});
if (result.status == 201) {
octokit.issues.createComment({
issue_number: issue.number,
owner: repo.owner.login,
repo: repo.name,
body: "👋 Thanks for this pull request! Unfortunately, it looks like the automated continuous integration (CI) [test(s) failed](" + workflow_run.html_url + "). These can be tricky to fix so we've written a guide on how to fix them locally. It has pages about [running pre-commit locally](https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code) and another about [building the docs locally with sphinx](https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs). Thanks for contributing to CircuitPython! If you have more questions, feel free to join [the Adafruit Discord](https://adafru.it/discord) and post in #circuitpython-dev."
});
} else {
console.log("Already commented");
}
} catch (err) {
core.setFailed(err.message);
}
}
run();