Skip to content

Commit 9ef435a

Browse files
committed
✨ Adds Discord notifications for bug reports
Adds a new workflow to send notifications to Discord when a new bug-type issue is opened. - Improves the Discord notification format to include structured information from the issue body, such as steps to reproduce, expected result, actual result, and extra context. - Adds a check to prevent notifications if the issue body contains a "skip notify Discord" marker. - Extracts relevant sections from the issue body using `awk` for cleaner formatting in the Discord message. - Uses `jq` to construct the JSON payload for the Discord webhook.
1 parent 8147085 commit 9ef435a

File tree

1 file changed

+67
-30
lines changed

1 file changed

+67
-30
lines changed

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

Lines changed: 67 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,10 @@ 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') }}
1012
runs-on: ubuntu-latest
1113

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-
2414
steps:
2515
- name: Send Discord notification
2616
env:
@@ -32,35 +22,82 @@ jobs:
3222
ISSUE_USER: ${{ github.event.issue.user.login }}
3323
REPO_NAME: ${{ github.repository }}
3424
run: |
35-
# Trim body to avoid huge messages
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+
3645
SHORT_BODY=$(printf '%s' "$ISSUE_BODY" | head -c 400)
3746
[ -z "$SHORT_BODY" ] && SHORT_BODY="(no description)"
3847
39-
# Build JSON payload for Discord
4048
payload=$(jq -n \
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-
)" \
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")" \
5360
'{
5461
"username": $username,
55-
"content": $content,
5662
"embeds": [
5763
{
5864
"title": $title,
59-
"description": $desc
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
6098
}
6199
]
62-
}'
63-
)
100+
}')
64101
65102
curl -X POST \
66103
-H "Content-Type: application/json" \

0 commit comments

Comments
 (0)