Skip to content

Commit 040939c

Browse files
committed
feat: testing workflows for telegram commits
Signed-off-by: https://github.com/Someshdiwan <[email protected]>
1 parent 0723b92 commit 040939c

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

.github/workflows/telegram-commits.yml

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ permissions:
1111
jobs:
1212
send:
1313
runs-on: ubuntu-latest
14-
environment: SANDBOX # uses TG_BOT_TOKEN and TG_CHAT_ID
14+
environment: SANDBOX # TG_BOT_TOKEN + TG_CHAT_ID
1515
steps:
16-
- name: Checkout repo
16+
- name: Checkout
1717
uses: actions/checkout@v4
1818
with:
1919
fetch-depth: 50
@@ -31,57 +31,51 @@ jobs:
3131
REPO_URL="${{ github.server_url }}/${{ github.repository }}"
3232
COMMIT_BASE="${{ github.server_url }}/${{ github.repository }}/commit"
3333
34-
# Escape minimal HTML for Telegram parse_mode=HTML
3534
esc() { sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g'; }
3635
37-
# Last 10 commits: subject, short hash, author, full hash for link
3836
mapfile -t LINES < <(git log -n 10 --pretty=format:'%s%x1f%h%x1f%an%x1f%H' || true)
3937
4038
if [[ ${#LINES[@]} -eq 0 ]]; then
41-
COMMITS_HTML="- (no commit messages found)"
39+
COMMITS_HTML="(no commit messages found)"
4240
else
4341
COMMITS_HTML=""
4442
for row in "${LINES[@]}"; do
4543
IFS=$'\x1f' read -r subj short author full <<<"$row"
4644
subj_esc="$(printf '%s' "$subj" | esc)"
4745
author_esc="$(printf '%s' "$author" | esc)"
48-
COMMITS_HTML+=$'- ' # bullet
49-
COMMITS_HTML+="<a href=\"${COMMIT_BASE}/${full}\">${subj_esc}</a> "
50-
COMMITS_HTML+="(<code>${short}</code>) by ${author_esc}\n"
46+
# bullet line with HTML breaks
47+
COMMITS_HTML+=$'• '
48+
COMMITS_HTML+="<a href=\"${COMMIT_BASE}/${full}\">${subj_esc}</a> (<code>${short}</code>) by ${author_esc}<br>"
5149
done
5250
fi
5351
54-
HEADER="<b>📣 Last 10 commits</b>\n"
55-
META="Repo: <a href=\"${REPO_URL}\">${REPO}</a>\nBy: ${ACTOR}\nRef: <code>${REF_NAME}</code>\nRun: <a href=\"${RUN_URL}\">view run</a>\n\n"
56-
FOOTER="\nRepo: <a href=\"${REPO_URL}\">${REPO_URL}</a>"
52+
HEADER="<b>📣 Last 10 commits</b><br>"
53+
META="Repo: <a href=\"${REPO_URL}\">${REPO}</a><br>By: ${ACTOR}<br>Ref: <code>${REF_NAME}</code><br>Run: <a href=\"${RUN_URL}\">view run</a><br><br>"
54+
FOOTER="<br>Repo: <a href=\"${REPO_URL}\">${REPO_URL}</a>"
5755
5856
MESSAGE="${HEADER}${META}${COMMITS_HTML}${FOOTER}"
5957
6058
{
61-
echo "text<<EOF"
59+
echo "text<<'EOF'"
6260
echo "$MESSAGE"
6361
echo "EOF"
6462
} >> "$GITHUB_OUTPUT"
6563
66-
- name: Send to Telegram
64+
- name: Send to Telegram (HTML)
65+
shell: bash
6766
env:
6867
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }}
6968
TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }}
7069
TEXT: ${{ steps.msg.outputs.text }}
71-
shell: bash
7270
run: |
7371
set -euo pipefail
74-
if [[ -z "${TG_BOT_TOKEN:-}" || -z "${TG_CHAT_ID:-}" ]]; then
75-
echo "❌ Telegram secrets missing"; exit 1
76-
fi
72+
[[ -n "${TG_BOT_TOKEN:-}" && -n "${TG_CHAT_ID:-}" ]] || { echo "Missing TG secrets"; exit 1; }
7773
78-
# Send as HTML so links and <code> render nicely
7974
curl -sS -X POST "https://api.telegram.org/bot${TG_BOT_TOKEN}/sendMessage" \
8075
-H 'Content-Type: application/json' \
8176
-d "$(jq -n \
82-
--arg chat_id "$TG_CHAT_ID" \
83-
--arg text "$TEXT" \
84-
--arg pm "HTML" \
85-
'{chat_id:$chat_id, text:$text, parse_mode:$pm, disable_web_page_preview:true}')"
77+
--arg chat_id "$TG_CHAT_ID" \
78+
--arg text "$TEXT" \
79+
'{chat_id:$chat_id, text:$text, parse_mode:"HTML", disable_web_page_preview:true}')"
8680
87-
echo "✅ Posted last 10 commits to Telegram channel."
81+
echo "✅ Posted to Telegram."

0 commit comments

Comments
 (0)