forked from kohchihao/tele-status
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (45 loc) · 1.34 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
require('dotenv').config;
const Bot = require('node-telegram-bot-api');
const {
INPUT_STATUS: status,
INPUT_TOKEN: tgToken,
INPUT_CHAT: chatId,
INPUT_IU_TITLE: title,
INPUT_IU_NUM: num,
INPUT_IU_ACTOR: actor,
INPUT_IU_BODY: body,
INPUT_PR_NUM: prNum,
INPUT_PR_STATE: prState,
INPUT_PR_TITLE: prTitle,
INPUT_PR_BODY: prBody,
GITHUB_EVENT_NAME: ghEvent,
GITHUB_REPOSITORY: repo,
GITHUB_ACTOR: ghActor, // the actor that trigger the workflow
GITHUB_SHA: sha,
GITHUB_WORKFLOW: ghWorkflow,
INPUT_PR_COMMIT_MESSAGE: prCommitMessage,
INPUT_PR_BRANCH_NAME: prBranchName
} = process.env;
const bot = new Bot(tgToken);
const buildPrContent = () => {
let message =
'-------------------------------------\n' +
`Workflow build <b>${status}!</b>\n` +
`Title: ${prTitle}\n` +
`Branch: ${prBranchName}\n` +
`User: ${ghActor}\n` +
'<b>Commit Msg:</b>\n' +
`${prCommitMessage}\n\n` +
`<a href="https://github.com/${repo}/commit/${sha}/checks">Job Log here</a>\n` +
`<a href="https://github.com/${repo}/pull/${prNum}">Link to issue/PR</a>\n` +
'--------------------------------------';
return message;
};
const evresp = (gevent) => {
switch (gevent) {
case 'pull_request':
return buildPrContent();
}
};
const output = evresp(ghEvent);
bot.sendMessage(chatId, output, { parse_mode: 'html' });