-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
37 lines (30 loc) · 1.08 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
const core = require('@actions/core');
const github = require('@actions/github');
const axios = require('axios');
try {
const statuses = {
"started": "❕",
"failure": "❗",
"success": "✅",
"cancelled": "❕"
};
const status = core.getInput('status');
if(!statuses[status]) throw Error("Status not found!");
const botId = core.getInput("token");
if(!botId) throw Error("Token not found!");
const chatId = core.getInput("to");
if(!chatId) throw Error("Chat Id not found");
const branch = core.getInput("branch");
if(!branch) throw Error("Branch not found");
let apiUrl = "https://api.telegram.org/bot{botId}/sendMessage".replace("{botId}", botId);
const { owner, repo } = github.context.repo;
const runId = github.context.payload.workflow_run.id;
const link = `https://github.com/${owner}/${repo}/actions/runs/${runId}`;
axios.post(apiUrl, {
"chat_id": chatId,
"text": `${statuses[status]} Build ${status}, branch: ${branch} [Details](${link})` ,
"parse_mode": "MarkdownV2"
}).then(r => console.log(r));
} catch (error) {
core.setFailed(error.message);
}