notify-discord-issues.yml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. # Determine data source based on trigger type
  73. if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
  74. ISSUE_NUMBER="${{ steps.issue-info.outputs.number }}"
  75. ISSUE_TITLE="${{ steps.issue-info.outputs.title }}"
  76. ISSUE_URL="${{ steps.issue-info.outputs.html_url }}"
  77. AUTHOR_LOGIN="${{ steps.issue-info.outputs.author_login }}"
  78. AUTHOR_URL="${{ steps.issue-info.outputs.author_html_url }}"
  79. ISSUE_STATE="${{ steps.issue-info.outputs.state }}"
  80. ISSUE_LABELS="${{ steps.issue-info.outputs.labels }}"
  81. CREATED_AT="${{ steps.issue-info.outputs.created_at }}"
  82. else
  83. ISSUE_NUMBER="${{ github.event.issue.number }}"
  84. ISSUE_TITLE="${{ github.event.issue.title }}"
  85. ISSUE_URL="${{ github.event.issue.html_url }}"
  86. AUTHOR_LOGIN="${{ github.event.issue.user.login }}"
  87. AUTHOR_URL="${{ github.event.issue.user.html_url }}"
  88. ISSUE_STATE="${{ github.event.issue.state }}"
  89. ISSUE_LABELS="${{ github.event.issue.labels[0].name && join(github.event.issue.labels.*.name, ', ') || 'None' }}"
  90. CREATED_AT="${{ github.event.issue.created_at }}"
  91. fi
  92. # Create a temporary JSON file
  93. cat > discord_payload.json << EOF
  94. {
  95. "avatar_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
  96. "embeds": [
  97. {
  98. "title": "${{ steps.action-info.outputs.emoji }} Issue ${{ steps.action-info.outputs.action_text }}: #${ISSUE_NUMBER}",
  99. "description": "${ISSUE_TITLE}",
  100. "url": "${ISSUE_URL}",
  101. "color": ${{ steps.action-info.outputs.color }},
  102. "thumbnail": {
  103. "url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
  104. },
  105. "fields": [
  106. {
  107. "name": "📋 Issue #",
  108. "value": "\`#${ISSUE_NUMBER}\`",
  109. "inline": true
  110. },
  111. {
  112. "name": "👤 Author",
  113. "value": "[${AUTHOR_LOGIN}](${AUTHOR_URL})",
  114. "inline": true
  115. },
  116. {
  117. "name": "📁 Repository",
  118. "value": "[${{ github.event.repository.name }}](${{ github.event.repository.html_url }})",
  119. "inline": true
  120. },
  121. {
  122. "name": "🏷️ Labels",
  123. "value": "${ISSUE_LABELS}",
  124. "inline": true
  125. },
  126. {
  127. "name": "📊 State",
  128. "value": "\`${ISSUE_STATE}\`",
  129. "inline": true
  130. },
  131. {
  132. "name": "🔗 View Issue",
  133. "value": "[Issue Page](${ISSUE_URL})",
  134. "inline": true
  135. }
  136. ],
  137. "timestamp": "${CREATED_AT}",
  138. "footer": {
  139. "text": "Workout Cool • Issue ${{ steps.action-info.outputs.action_text }}",
  140. "icon_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
  141. }
  142. }
  143. ]
  144. }
  145. EOF
  146. - name: Send Discord notification
  147. run: |
  148. curl -H "Content-Type: application/json" \
  149. -d @discord_payload.json \
  150. "${{ secrets.DISCORD_ISSUES_WEBHOOK }}"