✨ Adds Discord notifications for bug reports #15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Report Bug-type issues to Discord | ||
|
Check failure on line 1 in .github/workflows/issue-bug-to-discord.yml
|
||
| on: | ||
| issues: | ||
| types: | ||
| - opened | ||
| jobs: | ||
| notify_discord: | ||
| # Bug-form issues only, and don't send if "Skip notify Discord" is checked | ||
| if: ${{ contains(lower(github.event.issue.body), '### steps to reproduce') && !contains(lower(github.event.issue.body), '- [x] skip notify discord') }} | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Send Discord notification | ||
| env: | ||
| DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} | ||
| ISSUE_TITLE: ${{ github.event.issue.title }} | ||
| ISSUE_URL: ${{ github.event.issue.html_url }} | ||
| ISSUE_NUMBER: ${{ github.event.issue.number }} | ||
| ISSUE_BODY: ${{ github.event.issue.body }} | ||
| ISSUE_USER: ${{ github.event.issue.user.login }} | ||
| REPO_NAME: ${{ github.repository }} | ||
| run: | | ||
| extract_section () { | ||
| # $1 = heading text (e.g. "Steps to reproduce") | ||
| printf '%s\n' "$ISSUE_BODY" | awk -v heading="### $1" ' | ||
| $0 == heading {flag=1; next} | ||
| /^### / && flag {flag=0} | ||
| flag | ||
| ' | ||
| } | ||
| STEPS=$(extract_section "Steps to reproduce") | ||
| EXPECTED=$(extract_section "Expected result") | ||
| ACTUAL=$(extract_section "Actual result") | ||
| CONTEXT=$(extract_section "Extra context") | ||
| # Fallbacks if some sections are empty | ||
| [ -z "$STEPS" ] && STEPS="(not provided)" | ||
| [ -z "$EXPECTED" ] && EXPECTED="(not provided)" | ||
| [ -z "$ACTUAL" ] && ACTUAL="(not provided)" | ||
| [ -z "$CONTEXT" ] && CONTEXT="(none)" | ||
| SHORT_BODY=$(printf '%s' "$ISSUE_BODY" | head -c 400) | ||
| [ -z "$SHORT_BODY" ] && SHORT_BODY="(no description)" | ||
| payload=$(jq -n \ | ||
| --arg username "Gardens Bot" \ | ||
| --arg title "🐞 Bug #${ISSUE_NUMBER} – ${ISSUE_TITLE}" \ | ||
| --arg issue_url "$ISSUE_URL" \ | ||
| --arg repo "$REPO_NAME" \ | ||
| --arg author "$ISSUE_USER" \ | ||
| --arg steps "$STEPS" \ | ||
| --arg expected "$EXPECTED" \ | ||
| --arg actual "$ACTUAL" \ | ||
| --arg context "$CONTEXT" \ | ||
| --arg summary "$SHORT_BODY" \ | ||
| --arg timestamp "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \ | ||
| '{ | ||
| "username": $username, | ||
| "embeds": [ | ||
| { | ||
| "title": $title, | ||
| "url": $issue_url, | ||
| "color": 15158332, | ||
| "description": ("Repository: **" + $repo + "**\nAuthor: **" + $author + "**"), | ||
| "fields": [ | ||
| { | ||
| "name": "📝 Summary", | ||
| "value": ("> " + ($summary | gsub("\n"; "\n> "))) | ||
| }, | ||
| { | ||
| "name": "🐾 Steps to reproduce", | ||
| "value": ("```" + "\n" + $steps + "\n```") | ||
| }, | ||
| { | ||
| "name": "🎯 Expected", | ||
| "value": $expected | ||
| }, | ||
| { | ||
| "name": "💥 Actual", | ||
| "value": $actual | ||
| }, | ||
| { | ||
| "name": "📎 Extra context", | ||
| "value": $context | ||
| }, | ||
| { | ||
| "name": "🔗 Links", | ||
| "value": ("[View issue](" + $issue_url + ")") | ||
| } | ||
| ], | ||
| "footer": { | ||
| "text": "Gardens bug report" | ||
| }, | ||
| "timestamp": $timestamp | ||
| } | ||
| ] | ||
| }') | ||
| curl -X POST \ | ||
| -H "Content-Type: application/json" \ | ||
| -d "$payload" \ | ||
| "$DISCORD_WEBHOOK_URL" | ||