77
88jobs :
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