Skip to content

Commit 66297f2

Browse files
committed
✨ Adds Discord notifications for bug issues
Adds a GitHub workflow to post notifications to Discord when a new bug issue is opened. - Uses issue labels and body content to identify bug-type issues. - Skips notifications if explicitly requested in the issue body. - Truncates the issue body to prevent overly long messages.
1 parent 9ef435a commit 66297f2

File tree

1 file changed

+30
-67
lines changed

1 file changed

+30
-67
lines changed

.github/workflows/issue-bug-to-discord.yml

Lines changed: 30 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,20 @@ on:
77

88
jobs:
99
notify_discord:
10-
# Bug-form issues only, and don't send if "Skip notify Discord" is checked
11-
if: ${{ contains(lower(github.event.issue.body), '### steps to reproduce') && !contains(lower(github.event.issue.body), '- [x] skip notify discord') }}
1210
runs-on: ubuntu-latest
1311

12+
# Run only for Bug issues (typed/label/hidden marker) and when the form didn't opt out of Discord
13+
if: >
14+
${{
15+
(
16+
(github.event.issue.issue_type && github.event.issue.issue_type.name == 'Bug') ||
17+
contains(github.event.issue.labels.*.name, 'bug') ||
18+
contains(github.event.issue.labels.*.name, 'Bug') ||
19+
contains(github.event.issue.body, 'issue-type=bug')
20+
)
21+
&& !contains(github.event.issue.body, 'Skip Discord')
22+
}}
23+
1424
steps:
1525
- name: Send Discord notification
1626
env:
@@ -22,82 +32,35 @@ jobs:
2232
ISSUE_USER: ${{ github.event.issue.user.login }}
2333
REPO_NAME: ${{ github.repository }}
2434
run: |
25-
extract_section () {
26-
# $1 = heading text (e.g. "Steps to reproduce")
27-
printf '%s\n' "$ISSUE_BODY" | awk -v heading="### $1" '
28-
$0 == heading {flag=1; next}
29-
/^### / && flag {flag=0}
30-
flag
31-
'
32-
}
33-
34-
STEPS=$(extract_section "Steps to reproduce")
35-
EXPECTED=$(extract_section "Expected result")
36-
ACTUAL=$(extract_section "Actual result")
37-
CONTEXT=$(extract_section "Extra context")
38-
39-
# Fallbacks if some sections are empty
40-
[ -z "$STEPS" ] && STEPS="(not provided)"
41-
[ -z "$EXPECTED" ] && EXPECTED="(not provided)"
42-
[ -z "$ACTUAL" ] && ACTUAL="(not provided)"
43-
[ -z "$CONTEXT" ] && CONTEXT="(none)"
44-
35+
# Trim body to avoid huge messages
4536
SHORT_BODY=$(printf '%s' "$ISSUE_BODY" | head -c 400)
4637
[ -z "$SHORT_BODY" ] && SHORT_BODY="(no description)"
4738
39+
# Build JSON payload for Discord
4840
payload=$(jq -n \
49-
--arg username "Gardens Bot" \
50-
--arg title "🐞 Bug #${ISSUE_NUMBER} – ${ISSUE_TITLE}" \
51-
--arg issue_url "$ISSUE_URL" \
52-
--arg repo "$REPO_NAME" \
53-
--arg author "$ISSUE_USER" \
54-
--arg steps "$STEPS" \
55-
--arg expected "$EXPECTED" \
56-
--arg actual "$ACTUAL" \
57-
--arg context "$CONTEXT" \
58-
--arg summary "$SHORT_BODY" \
59-
--arg timestamp "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
41+
--arg username "GitHub Bot" \
42+
--arg content "" \
43+
--arg title "🐞 New Bug issue in $REPO_NAME" \
44+
--arg desc "$(cat <<EOF
45+
**#${ISSUE_NUMBER} – $ISSUE_TITLE**
46+
**Author:** $ISSUE_USER
47+
**Link:** $ISSUE_URL
48+
49+
**Description (truncated):**
50+
$SHORT_BODY
51+
EOF
52+
)" \
6053
'{
6154
"username": $username,
55+
"content": $content,
6256
"embeds": [
6357
{
6458
"title": $title,
65-
"url": $issue_url,
66-
"color": 15158332,
67-
"description": ("Repository: **" + $repo + "**\nAuthor: **" + $author + "**"),
68-
"fields": [
69-
{
70-
"name": "📝 Summary",
71-
"value": ("> " + ($summary | gsub("\n"; "\n> ")))
72-
},
73-
{
74-
"name": "🐾 Steps to reproduce",
75-
"value": ("```" + "\n" + $steps + "\n```")
76-
},
77-
{
78-
"name": "🎯 Expected",
79-
"value": $expected
80-
},
81-
{
82-
"name": "💥 Actual",
83-
"value": $actual
84-
},
85-
{
86-
"name": "📎 Extra context",
87-
"value": $context
88-
},
89-
{
90-
"name": "🔗 Links",
91-
"value": ("[View issue](" + $issue_url + ")")
92-
}
93-
],
94-
"footer": {
95-
"text": "Gardens bug report"
96-
},
97-
"timestamp": $timestamp
59+
"description": $desc
9860
}
9961
]
100-
}')
62+
}'
63+
)
10164
10265
curl -X POST \
10366
-H "Content-Type: application/json" \

0 commit comments

Comments
 (0)