-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
66 lines (60 loc) · 1.63 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
58
59
60
61
62
63
64
65
66
const {Toolkit} = require("actions-toolkit");
const fetch = require("node-fetch");
const httpError = require("http-errors");
const updateStatus = ({
state,
description,
targetURL,
context,
repo,
owner,
sha,
token
}) =>
fetch(`https://api.github.com/repos/${owner}/${repo}/statuses/${sha}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `token ${token}`
},
body: JSON.stringify({
state,
description,
context,
target_url: targetURL
})
});
const VALID_STATES = ["pending", "success", "error", "failure"];
Toolkit.run(
async tools => {
try {
const argsList = tools.arguments._;
if (argsList.length < 2)
throw new Error("Invalid usage: requires context and state arguments");
const state = argsList[1];
if (!VALID_STATES.includes(state))
throw new Error(
`Invalid state argument: must be one of ${VALID_STATES}`
);
const args = {
context: argsList[0],
state,
description: "A wild action appeared",
targetURL: "https://bit.ly/4kb77v",
repo: tools.context.repo.repo,
owner: tools.context.repo.owner,
sha: tools.context.sha
};
tools.log("Payload:");
tools.log(args);
const response = await updateStatus({...args, token: tools.token});
tools.log.success("Got response:");
tools.log.success(response);
if (!response.ok) throw httpError(response.status);
tools.exit.success("Status updated");
} catch (error) {
tools.exit.failure(error);
}
},
{secrets: ["GITHUB_TOKEN"]}
);