Skip to content

Cache apt packages in the buildsystem #61

Cache apt packages in the buildsystem

Cache apt packages in the buildsystem #61

name: Notify Chat on issue open/close
on:
issues:
types: [opened, closed, reopened]
permissions:
issues: read
jobs:
notify-telegram:
runs-on: ubuntu-latest
steps:
- name: Build Telegram message
id: build
env:
NUMBER: ${{ github.event.issue.number }}
TITLE: ${{ github.event.issue.title }}
BODY: ${{ github.event.issue.body }}
USER: ${{ github.event.issue.user.login }}
URL: ${{ github.event.issue.html_url }}
ACTION: ${{ github.event.action }}
ACTOR: ${{ github.actor }}
REPO: ${{ github.repository }}
run: |
set -euo pipefail
# Collect labels via jq from the event JSON
labels=$(jq -r '[.issue.labels[]?.name] | if length > 0 then join(", ") else "(none)" end' "$GITHUB_EVENT_PATH")
# HTML-escape a string
esc() { printf '%s' "$1" | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g'; }
# Truncate body
body_text="$BODY"
if [ "${#body_text}" -gt 800 ]; then
body_text="${body_text:0:800}...(truncated)"
fi
repo_url="https://github.com/${REPO}"
repo_link="<a href=\"${repo_url}\">$(esc "$REPO")</a>"
issue_link="<a href=\"$(esc "$URL")\">$(esc "#${NUMBER}: ${TITLE}")</a>"
if [ "$ACTION" = "opened" ]; then
header="<b>New issue opened</b>"
meta="Repo: ${repo_link}"$'\n'"Issue: ${issue_link}"$'\n'"Author: $(esc "$USER")"$'\n'"Labels: $(esc "$labels")"
elif [ "$ACTION" = "reopened" ]; then
header="<b>Issue reopened</b>"
meta="Repo: ${repo_link}"$'\n'"Issue: ${issue_link}"$'\n'"Reopened by: $(esc "$ACTOR")"$'\n'"Labels: $(esc "$labels")"
else
header="<b>Issue closed</b>"
meta="Repo: ${repo_link}"$'\n'"Issue: ${issue_link}"$'\n'"Closed by: $(esc "$ACTOR")"$'\n'"Labels: $(esc "$labels")"
fi
body_escaped="$(esc "$body_text")"
final="${header}"$'\n'"${meta}"$'\n\n'"${body_escaped}"
# Write multiline output using heredoc syntax with random delimiter
delim="EOF_$(openssl rand -hex 8)"
{
echo "msg<<${delim}"
printf '%s\n' "$final"
echo "${delim}"
} >> "$GITHUB_OUTPUT"
- name: Send Telegram notification
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
MSG: ${{ steps.build.outputs.msg }}
run: |
if [ -z "${TELEGRAM_BOT_TOKEN}" ] || [ -z "${TELEGRAM_CHAT_ID}" ]; then
echo "Missing TELEGRAM_BOT_TOKEN or TELEGRAM_CHAT_ID — skipping."
exit 0
fi
curl -sS --fail -X POST \
"https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
-d "chat_id=${TELEGRAM_CHAT_ID}" \
-d "parse_mode=HTML" \
--data-urlencode "text=${MSG}"