-
Notifications
You must be signed in to change notification settings - Fork 0
61 lines (52 loc) · 2.09 KB
/
telegram.yml
File metadata and controls
61 lines (52 loc) · 2.09 KB
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
name: Telegram Notification
on:
push:
jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Send Telegram Message
env:
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }}
TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }}
TG_THREAD_ID: ${{ secrets.TG_THREAD_ID }}
run: |
REPO_NAME="${GITHUB_REPOSITORY#*/}"
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
COMMIT_COUNT=$(jq '.commits | length' "$GITHUB_EVENT_PATH")
if [ "$COMMIT_COUNT" -eq "0" ]; then
echo "No new commits detected."
exit 0
fi
HEADER="<b>⚡️<a href=\"https://github.com/$GITHUB_REPOSITORY/tree/$BRANCH_NAME\">[$REPO_NAME:$BRANCH_NAME]</a></b> $COMMIT_COUNT new commit(s)"
COMMITS_LIST=$(jq -r '
[
.commits[] |
"<code><a href=\"\(.url)\">\(.id[0:7])</a></code> " +
(
.message
| gsub("&"; "&") | gsub("<"; "<") | gsub(">"; ">")
| gsub("\n\n"; "\n")
| split("\n")
| .[0] |= . + ":"
| join("\n")
) +
"\n\nby <a href=\"https://github.com/\(.author.username)\">\(.author.name)</a>" +
"\n<a href=\"\(.url)\">View commit →</a>"
] | join("\n\n------------------------------------------------------\n\n")
' "$GITHUB_EVENT_PATH")
FINAL_TEXT="<blockquote>$HEADER"$'\n'"$COMMITS_LIST</blockquote>"
jq -n \
--arg chat_id "$TG_CHAT_ID" \
--arg thread_id "$TG_THREAD_ID" \
--arg text "$FINAL_TEXT" \
'{
chat_id: $chat_id,
message_thread_id: $thread_id,
parse_mode: "HTML",
disable_web_page_preview: true,
text: $text
}' > payload.json
curl -s -X POST "https://api.telegram.org/bot$TG_BOT_TOKEN/sendMessage" \
-H "Content-Type: application/json" \
-d @payload.json