name: Discord Issue Notification on: issues: types: [opened, reopened, closed] workflow_dispatch: inputs: issue_number: description: "Issue number" required: true type: string jobs: Discord: runs-on: ubuntu-latest name: Discord Issue Notifier steps: - uses: actions/checkout@v4 if: github.event_name == 'workflow_dispatch' - name: Get issue info for manual trigger id: issue-info if: github.event_name == 'workflow_dispatch' run: | ISSUE_INFO=$(gh issue view ${{ github.event.inputs.issue_number }} --json number,title,url,author,state,labels,createdAt) echo "number=$(echo "$ISSUE_INFO" | jq -r '.number')" >> $GITHUB_OUTPUT echo "title=$(echo "$ISSUE_INFO" | jq -r '.title')" >> $GITHUB_OUTPUT echo "html_url=$(echo "$ISSUE_INFO" | jq -r '.url')" >> $GITHUB_OUTPUT echo "author_login=$(echo "$ISSUE_INFO" | jq -r '.author.login')" >> $GITHUB_OUTPUT echo "author_html_url=https://github.com/$(echo "$ISSUE_INFO" | jq -r '.author.login')" >> $GITHUB_OUTPUT echo "state=$(echo "$ISSUE_INFO" | jq -r '.state')" >> $GITHUB_OUTPUT echo "created_at=$(echo "$ISSUE_INFO" | jq -r '.createdAt')" >> $GITHUB_OUTPUT echo "labels=$(echo "$ISSUE_INFO" | jq -r '.labels | map(.name) | join(", ") // "None"')" >> $GITHUB_OUTPUT env: GH_TOKEN: ${{ github.token }} - name: Determine action color and emoji id: action-info run: | if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then # For manual trigger, use the current state case "${{ steps.issue-info.outputs.state }}" in "OPEN") echo "color=15158332" >> $GITHUB_OUTPUT # Red echo "emoji=🔴" >> $GITHUB_OUTPUT echo "action_text=Open" >> $GITHUB_OUTPUT ;; "CLOSED") echo "color=5763719" >> $GITHUB_OUTPUT # Green echo "emoji=🟢" >> $GITHUB_OUTPUT echo "action_text=Closed" >> $GITHUB_OUTPUT ;; esac else # For automatic trigger, use the action case "${{ github.event.action }}" in "opened") echo "color=15158332" >> $GITHUB_OUTPUT # Red echo "emoji=🔴" >> $GITHUB_OUTPUT echo "action_text=Opened" >> $GITHUB_OUTPUT ;; "reopened") echo "color=16776960" >> $GITHUB_OUTPUT # Yellow echo "emoji=🟡" >> $GITHUB_OUTPUT echo "action_text=Reopened" >> $GITHUB_OUTPUT ;; "closed") echo "color=5763719" >> $GITHUB_OUTPUT # Green echo "emoji=🟢" >> $GITHUB_OUTPUT echo "action_text=Closed" >> $GITHUB_OUTPUT ;; esac fi - name: Create Discord webhook payload run: | # Create a temporary JSON file cat > discord_payload.json << 'EOF' { "avatar_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png", "embeds": [ { "title": "${{ steps.action-info.outputs.emoji }} Issue ${{ steps.action-info.outputs.action_text }}: #${{ github.event.issue.number }}", "description": "${{ github.event.issue.title }}", "url": "${{ github.event.issue.html_url }}", "color": ${{ steps.action-info.outputs.color }}, "thumbnail": { "url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" }, "fields": [ { "name": "📋 Issue #", "value": "`#${{ github.event.issue.number }}`", "inline": true }, { "name": "👤 Author", "value": "[${{ github.event.issue.user.login }}](${{ github.event.issue.user.html_url }})", "inline": true }, { "name": "📁 Repository", "value": "[${{ github.event.repository.name }}](${{ github.event.repository.html_url }})", "inline": true }, { "name": "🏷️ Labels", "value": "${{ github.event.issue.labels[0].name && join(github.event.issue.labels.*.name, ', ') || 'None' }}", "inline": true }, { "name": "📊 State", "value": "`${{ github.event.issue.state }}`", "inline": true }, { "name": "🔗 View Issue", "value": "[Issue Page](${{ github.event.issue.html_url }})", "inline": true } ], "timestamp": "${{ github.event.issue.created_at }}", "footer": { "text": "Workout Cool • Issue ${{ steps.action-info.outputs.action_text }}", "icon_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" } } ] } EOF - name: Send Discord notification run: | curl -H "Content-Type: application/json" \ -d @discord_payload.json \ "${{ secrets.DISCORD_ISSUES_WEBHOOK }}"