fix the skipped part #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Notify Telegram on PR | ||
| on: | ||
| pull_request: | ||
| types: [opened, reopened, ready_for_review] | ||
| jobs: | ||
| notify: | ||
| runs-on: ubuntu-latest | ||
| # Skip if secrets are missing (e.g., forked PRs) | ||
| if: ${{ secrets.TELEGRAM_BOT_TOKEN != '' && secrets.TELEGRAM_CHAT_ID != '' }} | ||
| steps: | ||
| - name: Send Telegram message | ||
| env: | ||
| TG_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} | ||
| CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} | ||
| REPO: ${{ github.repository }} | ||
| ACTOR: ${{ github.actor }} | ||
| PR_NUM: ${{ github.event.pull_request.number }} | ||
| PR_TITLE: ${{ github.event.pull_request.title }} | ||
| PR_URL: ${{ github.event.pull_request.html_url }} | ||
| BASE_BRANCH: ${{ github.event.pull_request.base.ref }} | ||
| HEAD_BRANCH: ${{ github.event.pull_request.head.ref }} | ||
| run: | | ||
| set -euo pipefail | ||
| API_URL="https://api.telegram.org/bot${TG_TOKEN}/sendMessage" | ||
| MSG="\<b\>New Pull Request\</b\> | ||
| Repo: \<code\>${REPO}\</code\> | ||
| By: \<b\>${ACTOR}\</b\> | ||
| PR: \<b\>#${PR_NUM}\</b\> — ${PR_TITLE} | ||
| Branch: \<code\>${HEAD_BRANCH}\</code\> → \<code\>${BASE_BRANCH}\</code\> | ||
| Link: ${PR_URL}" | ||
| # Show short debug (lengths only; won’t leak secrets) | ||
| echo "Token length: ${#TG_TOKEN}, Chat ID: ${CHAT_ID}" | ||
| # Send and capture HTTP code + body | ||
| HTTP_CODE=$(curl -sS -w "%{http_code}" -o /tmp/resp.json "$API_URL" \ | ||
| -d "chat_id=${CHAT_ID}" \ | ||
| -d "parse_mode=HTML" \ | ||
| -d "disable_web_page_preview=true" \ | ||
| --data-urlencode "text=${MSG}") | ||
| echo "Telegram response:" | ||
| cat /tmp/resp.json | ||
| echo | ||
| echo "HTTP ${HTTP_CODE}" | ||
| # Fail if Telegram didn’t return 200 | ||
| [ "$HTTP_CODE" = "200" ] || exit 1 | ||