forked from andymckay/cancel-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cancel.js
40 lines (35 loc) · 961 Bytes
/
cancel.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
const core = require("@actions/core");
const https = require('https');
const options = {
hostname: 'api.github.com',
path: `/repos/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}/cancel`,
headers: {
'Authorization': `token ${process.env.INPUT_TOKEN}`,
'Content-Type': 'application/json',
'User-Agent': 'actions/cancel-action'
},
method: 'POST'
}
const req = https.request(options, (res) => {
res.on('data', (data) => {
if (res.statusCode != 202) {
let parsed = JSON.parse(data)
console.log(`Error: ${parsed.message}`)
process.exit(1)
} else {
console.log('Cancelled successfully.')
process.exit(0)
}
})
})
req.on('error', (error) => {
console.log(`HTTP Error: ${error}`)
process.exit(1)
})
const outputMessage = () => {
const message = core.getInput("message");
console.log(message);
core.setOutput("message", message);
};
outputMessage();
req.end();