-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
56 lines (52 loc) · 1.2 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
const https = require("https");
const core = require("@actions/core")
const input = {
value1: core.getInput("value1"),
value2: core.getInput("value2"),
value3: core.getInput("value3"),
key: core.getInput("key"),
event: core.getInput("event")
};
if(!input.key || !input.event){
core.setFailed(`Miss required param key or event!`)
return;
}
const output = {
};
if(input.value1){
output.value1 = input.value1
}
if(input.value2){
output.value2 = input.value2
}
if(input.value3){
output.value3 = input.value3
}
const requestPayload = JSON.stringify(output);
const body = Buffer.from(requestPayload, 'utf-8');
core.debug(`requestPayload: ${requestPayload}`);
const requestOption = {
port: 443,
method: "POST",
headers: {
"Content-Type": "application/json",
"Content-Length": body.length
}
};
core.debug(`requestOption: ${JSON.stringify(requestOption,null,2)}`);
const webhookUrl = `https://maker.ifttt.com/trigger/${input.event}/with/key/${input.key}`
const requestNode = https.request(
webhookUrl,
requestOption,
(result) => {
core.debug(`Status Code: ${result.statusCode}`);
}
);
requestNode.on(
"error",
(error) => {
core.setFailed(error);
}
);
requestNode.write(body);
requestNode.end();