From 6631ebcf49174126391087fe98b9eca78b0ec51a Mon Sep 17 00:00:00 2001 From: Zane Schepke Date: Tue, 21 Oct 2025 15:13:39 -0400 Subject: [PATCH] ci: fix notifications --- .github/workflows/notifications.yml | 136 ++++++++++++++++++++-------- 1 file changed, 96 insertions(+), 40 deletions(-) diff --git a/.github/workflows/notifications.yml b/.github/workflows/notifications.yml index 498866b8..cd06a457 100644 --- a/.github/workflows/notifications.yml +++ b/.github/workflows/notifications.yml @@ -10,64 +10,120 @@ jobs: notify: runs-on: ubuntu-latest steps: - - name: Send to Telegram + - name: Send to Telegram - New Issue + if: github.event_name == 'issues' && github.event.action == 'opened' + env: + TITLE: ${{ github.event.issue.title }} + NUMBER: ${{ github.event.issue.number }} + USER: ${{ github.event.issue.user.login }} + BODY: ${{ github.event.issue.body || 'No body provided' }} + URL: ${{ github.event.issue.html_url }} run: | - if [[ "${{ github.event_name }}" == "issues" && "${{ github.event.action }}" == "opened" ]]; then - TITLE="${{ github.event.issue.title }}" - NUMBER=${{ github.event.issue.number }} - USER="${{ github.event.issue.user.login }}" - BODY="${{ github.event.issue.body || 'No body provided' }}" - BODY_TRUNC="${BODY:0:200}" # Truncate to avoid spam - URL="${{ github.event.issue.html_url }}" - TEXT=$(echo -e "🆕 New Issue #$NUMBER: *$TITLE* by $USER\n\n$BODY_TRUNC\n\n[View Issue]($URL)") - elif [[ "${{ github.event_name }}" == "issues" && "${{ github.event.action }}" == "closed" ]]; then - TITLE="${{ github.event.issue.title }}" - NUMBER=${{ github.event.issue.number }} - USER="${{ github.event.issue.user.login }}" - URL="${{ github.event.issue.html_url }}" - TEXT=$(echo -e "✅ Issue Closed #$NUMBER: *$TITLE* by $USER\n\n[View Issue]($URL)") - elif [[ "${{ github.event_name }}" == "release" && "${{ github.event.action }}" == "published" ]]; then - NAME="${{ github.event.release.name }}" - TAG="${{ github.event.release.tag_name }}" - BODY="${{ github.event.release.body || 'No notes provided' }}" - BODY_TRUNC="${BODY:0:200}" # Truncate to avoid spam - URL="${{ github.event.release.html_url }}" - TEXT=$(echo -e "🚀 New Release *$NAME* ($TAG)\n\n$BODY_TRUNC\n\n[View Release]($URL)") - fi - + BODY_TRUNC="${BODY:0:200}" # Truncate to avoid spam + TEXT=$(echo -e "🆕 New Issue #$NUMBER: *$TITLE* by $USER\n\n$BODY_TRUNC\n\n[View Issue]($URL)") curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage" \ -d chat_id="${{ vars.TELEGRAM_CHAT_ID }}" \ ${{ vars.TELEGRAM_THREAD_ID && format('-d message_thread_id="{0}"', vars.TELEGRAM_THREAD_ID) || '' }} \ -d parse_mode="Markdown" \ --data-urlencode "text=$TEXT" - - name: Send to Matrix + - name: Send to Telegram - Closed Issue + if: github.event_name == 'issues' && github.event.action == 'closed' + env: + TITLE: ${{ github.event.issue.title }} + NUMBER: ${{ github.event.issue.number }} + USER: ${{ github.event.issue.user.login }} + URL: ${{ github.event.issue.html_url }} run: | - PLAIN_MESSAGE="" - HTML_MESSAGE="" - if [[ "${{ github.event_name }}" == "issues" && "${{ github.event.action }}" == "opened" ]]; then - PLAIN_MESSAGE=$(echo -e "🆕 New Issue #${{ github.event.issue.number }}: ${{ github.event.issue.title }} by ${{ github.event.issue.user.login }}\n\n${{ github.event.issue.body || 'No body provided' }}\n\nView Issue: ${{ github.event.issue.html_url }}") - HTML_MESSAGE=$(echo -e "

🆕 New Issue #${{ github.event.issue.number }}: ${{ github.event.issue.title }} by ${{ github.event.issue.user.login }}

${{ github.event.issue.body || 'No body provided' }}

View Issue

") - elif [[ "${{ github.event_name }}" == "issues" && "${{ github.event.action }}" == "closed" ]]; then - PLAIN_MESSAGE=$(echo -e "✅ Issue Closed #${{ github.event.issue.number }}: ${{ github.event.issue.title }} by ${{ github.event.issue.user.login }}\n\nView Issue: ${{ github.event.issue.html_url }}") - HTML_MESSAGE=$(echo -e "

✅ Issue Closed #${{ github.event.issue.number }}: ${{ github.event.issue.title }} by ${{ github.event.issue.user.login }}

View Issue

") - elif [[ "${{ github.event_name }}" == "release" && "${{ github.event.action }}" == "published" ]]; then - PLAIN_MESSAGE=$(echo -e "🚀 New Release ${{ github.event.release.name }} (${{ github.event.release.tag_name }})\n\n${{ github.event.release.body || 'No notes provided' }}\n\nView Release: ${{ github.event.release.html_url }}") - HTML_MESSAGE=$(echo -e "

🚀 New Release ${{ github.event.release.name }} (${{ github.event.release.tag_name }})

${{ github.event.release.body || 'No notes provided' }}

View Release

") - fi + TEXT=$(echo -e "✅ Issue Closed #$NUMBER: *$TITLE* by $USER\n\n[View Issue]($URL)") + curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage" \ + -d chat_id="${{ vars.TELEGRAM_CHAT_ID }}" \ + ${{ vars.TELEGRAM_THREAD_ID && format('-d message_thread_id="{0}"', vars.TELEGRAM_THREAD_ID) || '' }} \ + -d parse_mode="Markdown" \ + --data-urlencode "text=$TEXT" + - name: Send to Telegram - New Release + if: github.event_name == 'release' && github.event.action == 'published' + env: + NAME: ${{ github.event.release.name }} + TAG: ${{ github.event.release.tag_name }} + BODY: ${{ github.event.release.body || 'No notes provided' }} + URL: ${{ github.event.release.html_url }} + run: | + BODY_TRUNC="${BODY:0:200}" # Truncate to avoid spam + TEXT=$(echo -e "🚀 New Release *$NAME* ($TAG)\n\n$BODY_TRUNC\n\n[View Release]($URL)") + curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage" \ + -d chat_id="${{ vars.TELEGRAM_CHAT_ID }}" \ + ${{ vars.TELEGRAM_THREAD_ID && format('-d message_thread_id="{0}"', vars.TELEGRAM_THREAD_ID) || '' }} \ + -d parse_mode="Markdown" \ + --data-urlencode "text=$TEXT" + + - name: Send to Matrix - New Issue + if: github.event_name == 'issues' && github.event.action == 'opened' + env: + NUMBER: ${{ github.event.issue.number }} + TITLE: ${{ github.event.issue.title }} + USER: ${{ github.event.issue.user.login }} + BODY: ${{ github.event.issue.body || 'No body provided' }} + URL: ${{ github.event.issue.html_url }} + run: | + PLAIN_MESSAGE=$(echo -e "🆕 New Issue #$NUMBER: $TITLE by $USER\n\n$BODY\n\nView Issue: $URL") + HTML_MESSAGE=$(echo -e "

🆕 New Issue #$NUMBER: $TITLE by $USER

$BODY

View Issue

") PLAIN_MESSAGE="${PLAIN_MESSAGE:0:220}" - PAYLOAD=$(jq -n --arg body "$PLAIN_MESSAGE" --arg formatted "$HTML_MESSAGE" '{ "msgtype": "m.text", "body": $body, "format": "org.matrix.custom.html", "formatted_body": $formatted }') - TXN_ID="${{ github.run_id }}-${{ github.run_attempt }}" - curl -s -X PUT "https://${{ vars.MATRIX_HOMESERVER }}/_matrix/client/v3/rooms/${{ vars.MATRIX_ROOM_ID }}/send/m.room.message/$TXN_ID" \ -H "Authorization: Bearer ${{ secrets.MATRIX_ACCESS_TOKEN }}" \ -H "Content-Type: application/json" \ -d "$PAYLOAD" + + - name: Send to Matrix - Closed Issue + if: github.event_name == 'issues' && github.event.action == 'closed' + env: + NUMBER: ${{ github.event.issue.number }} + TITLE: ${{ github.event.issue.title }} + USER: ${{ github.event.issue.user.login }} + URL: ${{ github.event.issue.html_url }} + run: | + PLAIN_MESSAGE=$(echo -e "✅ Issue Closed #$NUMBER: $TITLE by $USER\n\nView Issue: $URL") + HTML_MESSAGE=$(echo -e "

✅ Issue Closed #$NUMBER: $TITLE by $USER

View Issue

") + PLAIN_MESSAGE="${PLAIN_MESSAGE:0:220}" + PAYLOAD=$(jq -n --arg body "$PLAIN_MESSAGE" --arg formatted "$HTML_MESSAGE" '{ + "msgtype": "m.text", + "body": $body, + "format": "org.matrix.custom.html", + "formatted_body": $formatted + }') + TXN_ID="${{ github.run_id }}-${{ github.run_attempt }}" + curl -s -X PUT "https://${{ vars.MATRIX_HOMESERVER }}/_matrix/client/v3/rooms/${{ vars.MATRIX_ROOM_ID }}/send/m.room.message/$TXN_ID" \ + -H "Authorization: Bearer ${{ secrets.MATRIX_ACCESS_TOKEN }}" \ + -H "Content-Type: application/json" \ + -d "$PAYLOAD" + + - name: Send to Matrix - New Release + if: github.event_name == 'release' && github.event.action == 'published' + env: + NAME: ${{ github.event.release.name }} + TAG: ${{ github.event.release.tag_name }} + BODY: ${{ github.event.release.body || 'No notes provided' }} + URL: ${{ github.event.release.html_url }} + run: | + PLAIN_MESSAGE=$(echo -e "🚀 New Release $NAME ($TAG)\n\n$BODY\n\nView Release: $URL") + HTML_MESSAGE=$(echo -e "

🚀 New Release $NAME ($TAG)

$BODY

View Release

") + PLAIN_MESSAGE="${PLAIN_MESSAGE:0:220}" + PAYLOAD=$(jq -n --arg body "$PLAIN_MESSAGE" --arg formatted "$HTML_MESSAGE" '{ + "msgtype": "m.text", + "body": $body, + "format": "org.matrix.custom.html", + "formatted_body": $formatted + }') + TXN_ID="${{ github.run_id }}-${{ github.run_attempt }}" + curl -s -X PUT "https://${{ vars.MATRIX_HOMESERVER }}/_matrix/client/v3/rooms/${{ vars.MATRIX_ROOM_ID }}/send/m.room.message/$TXN_ID" \ + -H "Authorization: Bearer ${{ secrets.MATRIX_ACCESS_TOKEN }}" \ + -H "Content-Type: application/json" \ + -d "$PAYLOAD" \ No newline at end of file