-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (56 loc) · 1.39 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
const fs = require("fs");
const core = require("@actions/core");
const axios = require("axios");
function sendChangLog() {
// 机器人webhook
const url =
core.getInput("webhook_url");
// 读取版本更新日志
let data = fs.readFileSync(core.getInput("file_path"), "utf8");
const secondIndex = data.indexOf("\n## ", 5);
if (secondIndex !== -1) data = data.substring(2, secondIndex);
// 请求参数配置
const options = {
headers: {
"Content-Type": "application/json;charset=utf-8"
},
// markdown 消息类型
data: JSON.stringify({
msg_type: "interactive",
card: {
config: {
wide_screen_mode: true
},
elements: [
{
tag: "markdown",
content: data
}
],
header: {
template: "blue",
title: {
content: core.getInput("title"),
tag: "plain_text"
}
}
}
})
};
axios
.post(url, options.data, {headers: new axios.AxiosHeaders(options.headers)})
.then((res) => {
if (res.status === 200) {
console.log("发送消息成功");
console.log(res.data)
} else {
console.error("发送消息失败");
core.setFailed(res.data);
}
})
.catch((err) => {
console.error("发送消息失败");
core.setFailed(err);
});
}
sendChangLog();