-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
73 lines (67 loc) · 1.7 KB
/
index.js
File metadata and controls
73 lines (67 loc) · 1.7 KB
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
67
68
69
70
71
72
73
import querystring from 'querystring';
import axios from 'axios';
const core = require('@actions/core');
/**
* Message formatting styles
* @type {string[]}
*/
const PARSE_MODE_STYLES = [
'',
'html',
'markdown'
]
try {
/**
* Webhook url
* @type {string}
*/
const webhook = core.getInput('webhook');
if (!webhook) {
throw new Error('`webhook` param is missing');
}
/**
* Message to send
* @type {string}
*/
const message = core.getInput('message');
if (!message) {
throw new Error('`message` param is missing');
}
/**
* Message formatting style
* @type {string}
*/
const parse_mode = core.getInput('parse_mode');
if (parse_mode && !PARSE_MODE_STYLES.includes(parse_mode.toLowerCase())) {
throw new Error(`Bad \`parse_mode\` param. Use one of the following: ${PARSE_MODE_STYLES.join(', ')}`);
}
/**
* Disables link previews for links in this message
* @type {string|boolean}
*/
const disable_web_page_preview = core.getInput('disable_web_page_preview') || false;
/**
* Send message request
*/
axios({
method: 'POST',
url: webhook,
data: querystring.stringify({
message,
parse_mode,
disable_web_page_preview,
})
})
.then(response => {
/**
* Return response body and status code
*/
core.setOutput("response-body", response.data);
core.setOutput("response-code", response.status);
})
.catch(error => {
core.setFailed(error.message);
});
} catch (error) {
core.setFailed(error.message);
}