Skip to content

Instantly share code, notes, and snippets.

@Juan-Severiano
Created August 27, 2025 13:47
Show Gist options
  • Select an option

  • Save Juan-Severiano/12f4cf47e05b874d770da4abac0f0c18 to your computer and use it in GitHub Desktop.

Select an option

Save Juan-Severiano/12f4cf47e05b874d770da4abac0f0c18 to your computer and use it in GitHub Desktop.
name: Discord Notifications
on:
issues:
types: [opened, closed, labeled, reopened]
pull_request:
types: [opened, closed, merged, reopened]
push:
jobs:
notify-discord:
runs-on: ubuntu-latest
steps:
- name: Send message to Discord
run: |
WEBHOOK_URL="${{ secrets.DISCORD_WEBHOOK_URL }}"
EVENT_TYPE="${GITHUB_EVENT_NAME}"
CONTENT=""
if [ "$EVENT_TYPE" = "issues" ]; then
TITLE="🟢 Issue ${GITHUB_EVENT_ACTION}: ${{ github.event.issue.title }}"
URL="${{ github.event.issue.html_url }}"
AUTHOR="${{ github.event.issue.user.login }}"
COLOR=3066993
LABELS=$(echo "${{ toJSON(github.event.issue.labels) }}" | jq -r '.[].name' | paste -sd ", ")
CONTENT="{\"embeds\":[{\"title\":\"$TITLE\",\"url\":\"$URL\",\"author\":{\"name\":\"$AUTHOR\",\"url\":\"https://github.com/$AUTHOR\"},\"color\":$COLOR,\"fields\":[{\"name\":\"Labels\",\"value\":\"$LABELS\",\"inline\":true}]}]}"
elif [ "$EVENT_TYPE" = "pull_request" ]; then
TITLE="🔵 PR ${GITHUB_EVENT_ACTION}: ${{ github.event.pull_request.title }}"
URL="${{ github.event.pull_request.html_url }}"
AUTHOR="${{ github.event.pull_request.user.login }}"
COLOR=3447003
LABELS=$(echo "${{ toJSON(github.event.pull_request.labels) }}" | jq -r '.[].name' | paste -sd ", ")
CONTENT="{\"embeds\":[{\"title\":\"$TITLE\",\"url\":\"$URL\",\"author\":{\"name\":\"$AUTHOR\",\"url\":\"https://github.com/$AUTHOR\"},\"color\":$COLOR,\"fields\":[{\"name\":\"Labels\",\"value\":\"$LABELS\",\"inline\":true}]}]}"
elif [ "$EVENT_TYPE" = "push" ]; then
COMMIT_MSG=$(jq -r '.head_commit.message' $GITHUB_EVENT_PATH)
COMMIT_URL=$(jq -r '.head_commit.url' $GITHUB_EVENT_PATH)
AUTHOR=$(jq -r '.head_commit.author.username' $GITHUB_EVENT_PATH)
TITLE="🟠 Novo commit por $AUTHOR"
COLOR=15105570
CONTENT="{\"embeds\":[{\"title\":\"$TITLE\",\"url\":\"$COMMIT_URL\",\"description\":\"$COMMIT_MSG\",\"color\":$COLOR}]}"
fi
curl -H "Content-Type: application/json" -X POST -d "$CONTENT" "$WEBHOOK_URL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment