discord-monitor.yml

 1name: Flotpane Activity Monitor
 2
 3on:
 4  push:
 5  issues:
 6    types: [opened, edited, deleted, closed, reopened]
 7  pull_request_target:
 8    types: [opened, edited, closed, reopened]
 9  issue_comment:
10    types: [created, deleted]
11  fork:
12  watch:
13    types: [started] # This triggers when someone stars the repo
14  discussion:
15    types: [created, answered]
16
17jobs:
18  discord-audit-log:
19    name: Send Discord Audit Log
20    runs-on: ubuntu-latest
21    steps:
22      - name: Parse Event and Send Webhook
23        env:
24          DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL_AUDIT_LOG }}
25        run: |
26          EVENT_NAME="${{ github.event_name }}"
27          ACTOR="${{ github.actor }}"
28          REPO="${{ github.repository }}"
29          ACTION="${{ github.event.action }}"
30
31          # Default fallback URL
32          URL="https://github.com/$REPO"
33
34          # Customize Title and URL based on the specific event
35          if [ "$EVENT_NAME" == "issues" ]; then
36            TITLE="🐛 Issue $ACTION in $REPO"
37            URL="${{ github.event.issue.html_url }}"
38          elif [ "$EVENT_NAME" == "pull_request" ]; then
39            TITLE="🔄 Pull Request $ACTION in $REPO"
40            URL="${{ github.event.pull_request.html_url }}"
41          elif [ "$EVENT_NAME" == "push" ]; then
42            TITLE="⬆️ Code Pushed to $REPO"
43            URL="${{ github.event.compare }}" # Links to the commit comparison
44          elif [ "$EVENT_NAME" == "issue_comment" ]; then
45            TITLE="💬 Comment $ACTION on an Issue/PR"
46            URL="${{ github.event.comment.html_url }}"
47          elif [ "$EVENT_NAME" == "watch" ]; then
48            TITLE="⭐ Repo Starred!"
49          elif [ "$EVENT_NAME" == "fork" ]; then
50            TITLE="🍴 Repo Forked!"
51          elif [ "$EVENT_NAME" == "discussion" ]; then
52            TITLE="🗣️ Discussion $ACTION"
53            URL="${{ github.event.discussion.html_url }}"
54          else
55            TITLE="🔔 Activity ($EVENT_NAME) in $REPO"
56          fi
57
58          # Use jq to safely build the JSON payload (prevents special characters from breaking the script)
59          # Color is set to 0 (Pitch Black) to match the Flotpane branding
60          jq -n \
61            --arg title "$TITLE" \
62            --arg url "$URL" \
63            --arg desc "**User:** \`$ACTOR\` triggered \`$EVENT_NAME\`.\n\n[**View this activity on GitHub**]($url)" \
64            '{
65              username: "Flotpane Monitor",
66              avatar_url: "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
67              embeds: [{
68                title: $title,
69                url: $url,
70                description: $desc,
71                color: 0
72              }]
73            }' | curl -H "Content-Type: application/json" -d @- $DISCORD_WEBHOOK_URL