notify-discord-issues.yml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. case "${{ github.event.action }}" in
  37. "opened")
  38. echo "color=15158332" >> $GITHUB_OUTPUT # Red
  39. echo "emoji=🔴" >> $GITHUB_OUTPUT
  40. echo "action_text=Opened" >> $GITHUB_OUTPUT
  41. ;;
  42. "reopened")
  43. echo "color=16776960" >> $GITHUB_OUTPUT # Yellow
  44. echo "emoji=🟡" >> $GITHUB_OUTPUT
  45. echo "action_text=Reopened" >> $GITHUB_OUTPUT
  46. ;;
  47. "closed")
  48. echo "color=5763719" >> $GITHUB_OUTPUT # Green
  49. echo "emoji=🟢" >> $GITHUB_OUTPUT
  50. echo "action_text=Closed" >> $GITHUB_OUTPUT
  51. ;;
  52. esac
  53. - name: Create Discord webhook payload
  54. run: |
  55. # Create a temporary JSON file
  56. cat > discord_payload.json << 'EOF'
  57. {
  58. "avatar_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
  59. "embeds": [
  60. {
  61. "title": "${{ steps.action-info.outputs.emoji }} Issue ${{ steps.action-info.outputs.action_text }}: #${{ github.event.issue.number }}",
  62. "description": "${{ github.event.issue.title }}",
  63. "url": "${{ github.event.issue.html_url }}",
  64. "color": ${{ steps.action-info.outputs.color }},
  65. "thumbnail": {
  66. "url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
  67. },
  68. "fields": [
  69. {
  70. "name": "📋 Issue #",
  71. "value": "`#${{ github.event.issue.number }}`",
  72. "inline": true
  73. },
  74. {
  75. "name": "👤 Author",
  76. "value": "[${{ github.event.issue.user.login }}](${{ github.event.issue.user.html_url }})",
  77. "inline": true
  78. },
  79. {
  80. "name": "📁 Repository",
  81. "value": "[${{ github.event.repository.name }}](${{ github.event.repository.html_url }})",
  82. "inline": true
  83. },
  84. {
  85. "name": "🏷️ Labels",
  86. "value": "${{ github.event.issue.labels[0].name && join(github.event.issue.labels.*.name, ', ') || 'None' }}",
  87. "inline": true
  88. },
  89. {
  90. "name": "📊 State",
  91. "value": "`${{ github.event.issue.state }}`",
  92. "inline": true
  93. },
  94. {
  95. "name": "🔗 View Issue",
  96. "value": "[Issue Page](${{ github.event.issue.html_url }})",
  97. "inline": true
  98. }
  99. ],
  100. "timestamp": "${{ github.event.issue.created_at }}",
  101. "footer": {
  102. "text": "Workout Cool • Issue ${{ steps.action-info.outputs.action_text }}",
  103. "icon_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
  104. }
  105. }
  106. ]
  107. }
  108. EOF
  109. - name: Send Discord notification
  110. run: |
  111. curl -H "Content-Type: application/json" \
  112. -d @discord_payload.json \
  113. "${{ secrets.DISCORD_ISSUES_WEBHOOK }}"