forked from cemkiy/action-slacker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
96 lines (88 loc) · 2.61 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
91
92
93
94
95
96
const core = require('@actions/core');
const slack_webhook = core.getInput('slack_webhook', {
required: true
});
const slack = require('slack-notify')(slack_webhook);
slack.onError = function (err) {
core.error(`Error ${err}, action may still succeed though`);
};
// most @actions toolkit packages have async methods
async function run() {
try {
let attachment = {};
attachment.fallback = core.getInput('fallback', {
required: false
});
attachment.color = core.getInput('color', {
required: false
});
attachment.pretext = core.getInput('pretext', {
required: false
});
attachment.author_name = core.getInput('author_name', {
required: false
});
attachment.author_link = core.getInput('author_link', {
required: false
});
attachment.author_icon = core.getInput('author_icon', {
required: false
});
attachment.title = core.getInput('title', {
required: false
});
attachment.title_link = core.getInput('title_link', {
required: false
});
attachment.text = core.getInput('text', {
required: false
});
attachment.image_url = core.getInput('image_url', {
required: false
});
attachment.thumb_url = core.getInput('thumb_url', {
required: false
});
attachment.footer = core.getInput('footer', {
required: false
});
attachment.footer_icon = core.getInput('footer_icon', {
required: false
});
const channel = core.getInput('channel', {
required: true
});
const icon_url = core.getInput('icon_url', {
required: true
});
const username = core.getInput('username', {
required: true
});
const default_attachment = {
"title": `${process.env.GITHUB_REPOSITORY}`,
"title_link": `https://github.com/${process.env.GITHUB_REPOSITORY}`,
"color": attachment.color,
"text": `${process.env.GITHUB_REF}`,
"author_name": `${process.env.GITHUB_ACTOR}`,
"author_link": `https://github.com/${process.env.GITHUB_ACTOR}`,
"author_icon": `https://github.com/${process.env.GITHUB_ACTOR}.png`,
"footer": `action -> ${process.env.GITHUB_EVENT_NAME}`,
"thumb_url":"https://avatars0.githubusercontent.com/u/44036562?s=200&v=4"
}
var final_attachment = {};
if (attachment.length == 0) {
final_attachment = default_attachment;
} else {
final_attachment = attachment;
}
slack.send({
channel: channel,
icon_url: icon_url,
username: username,
attachments: [ final_attachment ]
});
} catch (error) {
core.setFailed(error.message);
}
}
run()