-
-
Notifications
You must be signed in to change notification settings - Fork 740
157 lines (150 loc) · 6.54 KB
/
Copy pathnotify-discord-issues.yml
File metadata and controls
157 lines (150 loc) · 6.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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: |
# Determine data source based on trigger type
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
ISSUE_NUMBER="${{ steps.issue-info.outputs.number }}"
ISSUE_TITLE="${{ steps.issue-info.outputs.title }}"
ISSUE_URL="${{ steps.issue-info.outputs.html_url }}"
AUTHOR_LOGIN="${{ steps.issue-info.outputs.author_login }}"
AUTHOR_URL="${{ steps.issue-info.outputs.author_html_url }}"
ISSUE_STATE="${{ steps.issue-info.outputs.state }}"
ISSUE_LABELS="${{ steps.issue-info.outputs.labels }}"
CREATED_AT="${{ steps.issue-info.outputs.created_at }}"
else
ISSUE_NUMBER="${{ github.event.issue.number }}"
ISSUE_TITLE="${{ github.event.issue.title }}"
ISSUE_URL="${{ github.event.issue.html_url }}"
AUTHOR_LOGIN="${{ github.event.issue.user.login }}"
AUTHOR_URL="${{ github.event.issue.user.html_url }}"
ISSUE_STATE="${{ github.event.issue.state }}"
ISSUE_LABELS="${{ github.event.issue.labels[0].name && join(github.event.issue.labels.*.name, ', ') || 'None' }}"
CREATED_AT="${{ github.event.issue.created_at }}"
fi
# 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 }}: #${ISSUE_NUMBER}",
"description": "${ISSUE_TITLE}",
"url": "${ISSUE_URL}",
"color": ${{ steps.action-info.outputs.color }},
"thumbnail": {
"url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
},
"fields": [
{
"name": "📋 Issue #",
"value": "\`#${ISSUE_NUMBER}\`",
"inline": true
},
{
"name": "👤 Author",
"value": "[${AUTHOR_LOGIN}](${AUTHOR_URL})",
"inline": true
},
{
"name": "📁 Repository",
"value": "[${{ github.event.repository.name }}](${{ github.event.repository.html_url }})",
"inline": true
},
{
"name": "🏷️ Labels",
"value": "${ISSUE_LABELS}",
"inline": true
},
{
"name": "📊 State",
"value": "\`${ISSUE_STATE}\`",
"inline": true
},
{
"name": "🔗 View Issue",
"value": "[Issue Page](${ISSUE_URL})",
"inline": true
}
],
"timestamp": "${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 }}"