notify-discord-issues.yml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. name: Discord Issue Notification
  2. on:
  3. issues:
  4. types: [opened, reopened, closed]
  5. workflow_dispatch:
  6. inputs:
  7. issue_number:
  8. description: "Issue number"
  9. required: true
  10. type: string
  11. jobs:
  12. Discord:
  13. runs-on: ubuntu-latest
  14. name: Discord Issue Notifier
  15. steps:
  16. - uses: actions/checkout@v4
  17. if: github.event_name == 'workflow_dispatch'
  18. - name: Get issue info for manual trigger
  19. id: issue-info
  20. if: github.event_name == 'workflow_dispatch'
  21. run: |
  22. ISSUE_INFO=$(gh issue view ${{ github.event.inputs.issue_number }} --json number,title,url,author,state,labels,createdAt)
  23. echo "number=$(echo "$ISSUE_INFO" | jq -r '.number')" >> $GITHUB_OUTPUT
  24. echo "title=$(echo "$ISSUE_INFO" | jq -r '.title')" >> $GITHUB_OUTPUT
  25. echo "html_url=$(echo "$ISSUE_INFO" | jq -r '.url')" >> $GITHUB_OUTPUT
  26. echo "author_login=$(echo "$ISSUE_INFO" | jq -r '.author.login')" >> $GITHUB_OUTPUT
  27. echo "author_html_url=https://github.com/$(echo "$ISSUE_INFO" | jq -r '.author.login')" >> $GITHUB_OUTPUT
  28. echo "state=$(echo "$ISSUE_INFO" | jq -r '.state')" >> $GITHUB_OUTPUT
  29. echo "created_at=$(echo "$ISSUE_INFO" | jq -r '.createdAt')" >> $GITHUB_OUTPUT
  30. echo "labels=$(echo "$ISSUE_INFO" | jq -r '.labels | map(.name) | join(", ") // "None"')" >> $GITHUB_OUTPUT
  31. env:
  32. GH_TOKEN: ${{ github.token }}
  33. - name: Determine action color and emoji
  34. id: action-info
  35. run: |
  36. if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
  37. # For manual trigger, use the current state
  38. case "${{ steps.issue-info.outputs.state }}" in
  39. "OPEN")
  40. echo "color=15158332" >> $GITHUB_OUTPUT # Red
  41. echo "emoji=🔴" >> $GITHUB_OUTPUT
  42. echo "action_text=Open" >> $GITHUB_OUTPUT
  43. ;;
  44. "CLOSED")
  45. echo "color=5763719" >> $GITHUB_OUTPUT # Green
  46. echo "emoji=🟢" >> $GITHUB_OUTPUT
  47. echo "action_text=Closed" >> $GITHUB_OUTPUT
  48. ;;
  49. esac
  50. else
  51. # For automatic trigger, use the action
  52. case "${{ github.event.action }}" in
  53. "opened")
  54. echo "color=15158332" >> $GITHUB_OUTPUT # Red
  55. echo "emoji=🔴" >> $GITHUB_OUTPUT
  56. echo "action_text=Opened" >> $GITHUB_OUTPUT
  57. ;;
  58. "reopened")
  59. echo "color=16776960" >> $GITHUB_OUTPUT # Yellow
  60. echo "emoji=🟡" >> $GITHUB_OUTPUT
  61. echo "action_text=Reopened" >> $GITHUB_OUTPUT
  62. ;;
  63. "closed")
  64. echo "color=5763719" >> $GITHUB_OUTPUT # Green
  65. echo "emoji=🟢" >> $GITHUB_OUTPUT
  66. echo "action_text=Closed" >> $GITHUB_OUTPUT
  67. ;;
  68. esac
  69. fi
  70. - name: Create Discord webhook payload
  71. run: |
  72. # Create a temporary JSON file
  73. cat > discord_payload.json << 'EOF'
  74. {
  75. "avatar_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
  76. "embeds": [
  77. {
  78. "title": "${{ steps.action-info.outputs.emoji }} Issue ${{ steps.action-info.outputs.action_text }}: #${{ github.event.issue.number }}",
  79. "description": "${{ github.event.issue.title }}",
  80. "url": "${{ github.event.issue.html_url }}",
  81. "color": ${{ steps.action-info.outputs.color }},
  82. "thumbnail": {
  83. "url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
  84. },
  85. "fields": [
  86. {
  87. "name": "📋 Issue #",
  88. "value": "`#${{ github.event.issue.number }}`",
  89. "inline": true
  90. },
  91. {
  92. "name": "👤 Author",
  93. "value": "[${{ github.event.issue.user.login }}](${{ github.event.issue.user.html_url }})",
  94. "inline": true
  95. },
  96. {
  97. "name": "📁 Repository",
  98. "value": "[${{ github.event.repository.name }}](${{ github.event.repository.html_url }})",
  99. "inline": true
  100. },
  101. {
  102. "name": "🏷️ Labels",
  103. "value": "${{ github.event.issue.labels[0].name && join(github.event.issue.labels.*.name, ', ') || 'None' }}",
  104. "inline": true
  105. },
  106. {
  107. "name": "📊 State",
  108. "value": "`${{ github.event.issue.state }}`",
  109. "inline": true
  110. },
  111. {
  112. "name": "🔗 View Issue",
  113. "value": "[Issue Page](${{ github.event.issue.html_url }})",
  114. "inline": true
  115. }
  116. ],
  117. "timestamp": "${{ github.event.issue.created_at }}",
  118. "footer": {
  119. "text": "Workout Cool • Issue ${{ steps.action-info.outputs.action_text }}",
  120. "icon_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
  121. }
  122. }
  123. ]
  124. }
  125. EOF
  126. - name: Send Discord notification
  127. run: |
  128. curl -H "Content-Type: application/json" \
  129. -d @discord_payload.json \
  130. "${{ secrets.DISCORD_ISSUES_WEBHOOK }}"