-
Notifications
You must be signed in to change notification settings - Fork 3
79 lines (68 loc) · 2.62 KB
/
telegram-commits.yml
File metadata and controls
79 lines (68 loc) · 2.62 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# .github/workflows/telegram-last-10.yml
name: Telegram – Last 10 Commits (Clean Text)
on:
push:
branches: ["**"]
workflow_dispatch:
permissions:
contents: read
jobs:
send:
runs-on: ubuntu-latest
environment: SANDBOX # must have TG_BOT_TOKEN and TG_CHAT_ID
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 50 # enough for recent history
- name: Build message (plain text)
id: msg
shell: bash
run: |
set -euo pipefail
REPO="${{ github.repository }}"
ACTOR="${{ github.actor }}"
REF_NAME="${{ github.ref_name }}"
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
REPO_URL="${{ github.server_url }}/${{ github.repository }}"
ACTOR_URL="https://github.com/${ACTOR}"
# Get last 10 commit subjects + short hashes
mapfile -t LINES < <(git log -n 10 --pretty=format:'%s%x1f%h' || true)
if [[ ${#LINES[@]} -eq 0 ]]; then
COMMITS="- (no commit messages found)"
else
COMMITS=""
for row in "${LINES[@]}"; do
IFS=$'\x1f' read -r subj short <<<"$row"
COMMITS+="- ${subj} (${short}) by ${ACTOR_URL}"$'\n'
done
# trim final newline
COMMITS="${COMMITS%$'\n'}"
fi
{
printf 'text<<MSGEOF\n'
printf '📣 Last 10 commits\n'
printf 'Repo: %s\n' "$REPO"
printf 'By: %s\n' "$ACTOR"
printf 'Ref: %s\n' "$REF_NAME"
printf 'Run: %s\n\n' "$RUN_URL"
printf '%s\n\n' "$COMMITS"
printf 'Repo: %s\n' "$REPO_URL"
printf 'MSGEOF\n'
} >> "$GITHUB_OUTPUT"
- name: Send to Telegram (plain text)
shell: bash
env:
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }}
TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }}
TEXT: ${{ steps.msg.outputs.text }}
run: |
set -euo pipefail
[[ -n "${TG_BOT_TOKEN:-}" && -n "${TG_CHAT_ID:-}" ]] || { echo "Missing TG secrets"; exit 1; }
# No parse_mode -> Telegram treats as plain text. Newlines stay intact.
curl -sS -X POST "https://api.telegram.org/bot${TG_BOT_TOKEN}/sendMessage" \
-H 'Content-Type: application/json' \
-d "$(jq -n --arg chat_id "$TG_CHAT_ID" --arg text "$TEXT" \
'{chat_id:$chat_id, text:$text, disable_web_page_preview:true}')" \
| jq -e '.ok == true' >/dev/null
echo "✅ Posted last 10 commits to Telegram."