This repository was archived by the owner on Sep 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
90 lines (79 loc) · 2.17 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const github = require('@actions/github');
const core = require('@actions/core')
const axios = require('axios')
async function run() {
try {
const github_context = github.context.payload
const discord_webhook_url = core.getInput('webhook_url', { required: true });
const os = core.getInput('os', { required: true });
const node_version = core.getInput('node_version', { required: true });
const build_status = core.getInput('build_status');
const workflow_name = core.getInput('workflow_name', { required: true });
let build_status_color;
if (build_status) {
build_status_color = 0x2cbe4e
} else {
build_status_color = 0xcb2431
}
const commit_message = github_context.head_commit.message
console.log("Log commit message");
console.log(commit_message);
console.log("Log build status color");
console.log(build_status_color);
const data = {
username: workflow_name,
avatar_url: "https://i.imgur.com/u6mj8bs.png",
embeds: [
{
title: commit_message,
url: github_context.head_commit.url,
author: {
name: github_context.sender.login,
icon_url: github_context.sender.avatar_url,
url: github_context.sender.html_url
},
fields: [
{
name: "Branch",
value: os
},
{
name: "Commit ID",
value: github_context.head_commit.id
},
{
name: "OS",
value: os,
inline: true
},
{
name: "Node version",
value: node_version
}
],
timestamp: new Date(),
footer: {
text: "GitHub Action"
}
}
]
};
axios({
method: "post",
url: discord_webhook_url,
responseType: 'json',
data
})
.then(function (response) {
console.log("**Notified!**");
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}
catch (error) {
core.setFailed(error.message);
}
}
run()