Debian Codegraph @

.github/workflows/telegram-notify.yml

raw symbols SCIP
1 name: Telegram Notify
2
3 on:
4 # pull_request_target runs in the context of the *target* repo, so Secrets
5 # are always available even when the PR comes from a fork.
6 # Safe here because we never checkout untrusted code — we only read event metadata.
7 pull_request_target:
8 types:
9 - opened
10 issues:
11 types:
12 - opened
13
14 # This workflow only sends notifications; no repo permissions needed.
15 # Restricting to empty permissions limits blast radius if the workflow is exploited.
16 permissions: {}
17
18 jobs:
19 notify:
20 if: github.repository == 'BYVoid/OpenCC' # Only run in the official repo; forks lack the required Secrets
21 runs-on: ubuntu-24.04
22 timeout-minutes: 1
23
24 steps:
25 - name: Build message and send to Telegram
26 env:
27 BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
28 CHAT_ID: ${{ secrets.CHAT_ID }}
29 EVENT_NAME: ${{ github.event_name }}
30 REPO: ${{ github.repository }}
31 ACTOR: ${{ github.actor }}
32 # PR fields (empty string when event is 'issues')
33 PR_NUMBER: ${{ github.event.pull_request.number }}
34 PR_TITLE: ${{ github.event.pull_request.title }}
35 PR_URL: ${{ github.event.pull_request.html_url }}
36 # Issue fields (empty string when event is 'pull_request_target')
37 ISSUE_NUMBER: ${{ github.event.issue.number }}
38 ISSUE_TITLE: ${{ github.event.issue.title }}
39 ISSUE_URL: ${{ github.event.issue.html_url }}
40 run: |
41 if [ "$EVENT_NAME" = "pull_request_target" ]; then
42 TEXT="$(printf 'New PR in %s\n#%s %s\nby @%s\n%s' \
43 "$REPO" "$PR_NUMBER" "$PR_TITLE" "$ACTOR" "$PR_URL")"
44 else
45 TEXT="$(printf 'New Issue in %s\n#%s %s\nby @%s\n%s' \
46 "$REPO" "$ISSUE_NUMBER" "$ISSUE_TITLE" "$ACTOR" "$ISSUE_URL")"
47 fi
48
49 RESPONSE=$(curl -s \
50 -X POST \
51 "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
52 --data-urlencode "chat_id=${CHAT_ID}" \
53 --data-urlencode "text=${TEXT}" \
54 --data-urlencode "disable_web_page_preview=true")
55
56 echo "$RESPONSE"
57 echo "$RESPONSE" | jq -e '.ok == true' > /dev/null || \
58 { echo "Telegram API error: $RESPONSE"; exit 1; }