-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
50 lines (44 loc) · 1.47 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
const core = require("@actions/core");
const { SlackMessage } = require("./src/SlackMessage");
const { SlackGateway } = require("./src/SlackGateway");
const initializeMessage = require("./src/initializeMessage");
const reportJobStatus = require("./src/reportJobStatus");
const appendHeaderLink = require("./src/appendHeaderLink");
const getActionParams = require("./src/getActionParams");
const useCaseMap = {
trigger: async (slackMessage, params) => {
const messageTs = await initializeMessage(slackMessage)(
{ name: params.senderName, avatar: params.senderAvatar },
params.runUrl,
params.header
);
core.setOutput("messageTs", messageTs);
},
update: async (slackMessage, params) => {
await reportJobStatus(slackMessage)({
job: params.job,
runId: params.runId,
status: "in_progress",
});
},
link: async (slackMessage, params) => {
await appendHeaderLink(slackMessage)({
url: params.link,
text: params.link_text,
});
},
};
const execute = async function () {
const params = await getActionParams();
const slackGateway = new SlackGateway(params.token);
const slackMessage = new SlackMessage(slackGateway, {
channel: params.channel,
ts: params.messageTs,
});
if (!useCaseMap[params.type])
throw new Error(
`type can be "trigger" or "update". You provided "${params.type}"`
);
await useCaseMap[params.type](slackMessage, params);
};
execute().catch((e) => core.setFailed(e.message));