Skip to content

Commit 3714b7b

Browse files
committed
Fix the bot pull requests
1 parent 5ee18b5 commit 3714b7b

1 file changed

Lines changed: 61 additions & 12 deletions

File tree

.github/workflows/ci.yml

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ jobs:
145145
run: |
146146
set -euo pipefail
147147
API_URL="https://api.telegram.org/bot${TG_TOKEN}/sendMessage"
148-
MSG="\<b\>New Pull Request\</b\>
149-
Repo: \<code\>${REPO}\</code\>
150-
By: \<b\>${ACTOR}\</b\>
151-
PR: \<b\>#${PR_NUM}\</b\> — ${PR_TITLE}
152-
Branch: \<code\>${HEAD_BRANCH}\</code\> → \<code\>${BASE_BRANCH}\</code\>
153-
Link: ${PR_URL}"
148+
MSG="<b>New Pull Request</b>
149+
Repo: <code>${REPO}</code>
150+
By: <b>${ACTOR}</b>
151+
PR: <b>#${PR_NUM}</b> — ${PR_TITLE}
152+
Branch: <code>${HEAD_BRANCH}</code> → <code>${BASE_BRANCH}</code>
153+
Link: ${PR_URL}"
154154
echo "Token length: ${#TG_TOKEN}, Chat ID: ${CHAT_ID}"
155155
HTTP_CODE=$(curl -sS -w "%{http_code}" -o /tmp/resp.json "$API_URL" \
156156
-d "chat_id=${CHAT_ID}" \
@@ -160,6 +160,55 @@ Link: ${PR_URL}"
160160
echo "Telegram response:"; cat /tmp/resp.json; echo; echo "HTTP ${HTTP_CODE}"
161161
[ "$HTTP_CODE" = "200" ] || exit 1
162162
163+
notify-telegram-tests-passed:
164+
name: Notify Telegram (Tests Passed)
165+
runs-on: ubuntu-latest
166+
needs: [lint, test]
167+
if: ${{ success() && secrets.TELEGRAM_BOT_TOKEN != '' && secrets.TELEGRAM_CHAT_ID != '' }}
168+
steps:
169+
- name: Send Telegram message (tests passed)
170+
env:
171+
TG_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
172+
CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
173+
REPO: ${{ github.repository }}
174+
ACTOR: ${{ github.actor }}
175+
EVENT: ${{ github.event_name }}
176+
REF: ${{ github.ref }}
177+
SHA: ${{ github.sha }}
178+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
179+
run: |
180+
set -euo pipefail
181+
API_URL="https://api.telegram.org/bot${TG_TOKEN}/sendMessage"
182+
183+
# Format message based on event type
184+
if [ "$EVENT" = "pull_request" ]; then
185+
PR_NUM="${{ github.event.pull_request.number }}"
186+
PR_TITLE="${{ github.event.pull_request.title }}"
187+
PR_URL="${{ github.event.pull_request.html_url }}"
188+
MSG="✅ <b>Tests Passed</b>
189+
Repo: <code>${REPO}</code>
190+
By: <b>${ACTOR}</b>
191+
PR: <b>#${PR_NUM}</b> — ${PR_TITLE}
192+
Link: ${PR_URL}
193+
Run: ${RUN_URL}"
194+
else
195+
BRANCH="${REF#refs/heads/}"
196+
MSG="✅ <b>Tests Passed</b>
197+
Repo: <code>${REPO}</code>
198+
By: <b>${ACTOR}</b>
199+
Branch: <code>${BRANCH}</code>
200+
Commit: <code>${SHA:0:7}</code>
201+
Run: ${RUN_URL}"
202+
fi
203+
204+
HTTP_CODE=$(curl -sS -w "%{http_code}" -o /tmp/resp.json "$API_URL" \
205+
-d "chat_id=${CHAT_ID}" \
206+
-d "parse_mode=HTML" \
207+
-d "disable_web_page_preview=true" \
208+
--data-urlencode "text=${MSG}")
209+
echo "Telegram response:"; cat /tmp/resp.json; echo; echo "HTTP ${HTTP_CODE}"
210+
[ "$HTTP_CODE" = "200" ] || exit 1
211+
163212
notify-telegram-merged:
164213
name: Notify Telegram (PR merged)
165214
runs-on: ubuntu-latest
@@ -182,12 +231,12 @@ Link: ${PR_URL}"
182231
run: |
183232
set -euo pipefail
184233
API_URL="https://api.telegram.org/bot${TG_TOKEN}/sendMessage"
185-
MSG="✅ \<b\>PR Merged\</b\>
186-
Repo: \<code\>${REPO}\</code\>
187-
By: \<b\>${ACTOR}\</b\>
188-
PR: \<b\>#${PR_NUM}\</b\> — ${PR_TITLE}
189-
Branch: \<code\>${HEAD_BRANCH}\</code\> → \<code\>${BASE_BRANCH}\</code\>
190-
Link: ${PR_URL}"
234+
MSG="✅ <b>PR Merged</b>
235+
Repo: <code>${REPO}</code>
236+
By: <b>${ACTOR}</b>
237+
PR: <b>#${PR_NUM}</b> — ${PR_TITLE}
238+
Branch: <code>${HEAD_BRANCH}</code> → <code>${BASE_BRANCH}</code>
239+
Link: ${PR_URL}"
191240
HTTP_CODE=$(curl -sS -w "%{http_code}" -o /tmp/resp.json "$API_URL" \
192241
-d "chat_id=${CHAT_ID}" \
193242
-d "parse_mode=HTML" \

0 commit comments

Comments
 (0)