BMAD-METHOD/.github/workflows/discord.yaml

222 lines
8.8 KiB
YAML

name: Discord Notification
on:
pull_request:
types: [opened, closed, reopened, ready_for_review]
release:
types: [published]
create:
delete:
issue_comment:
types: [created]
pull_request_review:
types: [submitted]
pull_request_review_comment:
types: [created]
issues:
types: [opened, closed, reopened]
env:
MAX_BODY_LENGTH: 300
jobs:
# Pull Request events
pull_request:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Notify Discord
env:
WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
ACTION: ${{ github.event.action }}
MERGED: ${{ github.event.pull_request.merged }}
PR_NUM: ${{ github.event.pull_request.number }}
PR_URL: ${{ github.event.pull_request.html_url }}
PR_TITLE: ${{ github.event.pull_request.title }}
PR_USER: ${{ github.event.pull_request.user.login }}
PR_BODY: ${{ github.event.pull_request.body }}
run: |
# escape markdown special chars
esc() { sed 's/[\\*_[\]()~`>]/\\&/g'; }
if [ "$ACTION" = "opened" ]; then ICON="🔀"; LABEL="New PR"
elif [ "$ACTION" = "closed" ] && [ "$MERGED" = "true" ]; then ICON="🎉"; LABEL="Merged"
elif [ "$ACTION" = "closed" ]; then ICON="❌"; LABEL="Closed"
elif [ "$ACTION" = "reopened" ]; then ICON="🔄"; LABEL="Reopened"
else ICON="📋"; LABEL="Ready"; fi
TITLE=$(echo "$PR_TITLE" | esc)
BODY=$(echo "$PR_BODY" | tr '\n\r' ' ' | head -c $MAX_BODY_LENGTH | esc)
[ ${#PR_BODY} -gt $MAX_BODY_LENGTH ] && BODY="${BODY}..."
[ -n "$BODY" ] && BODY=" · $BODY"
MSG="$ICON **[$LABEL #$PR_NUM: $TITLE](<$PR_URL>)**"$'\n'"by @$PR_USER$BODY"
jq -n --arg content "$MSG" '{content: $content}' | curl -X POST "$WEBHOOK" -H "Content-Type: application/json" -d @-
# Issue events
issues:
if: github.event_name == 'issues'
runs-on: ubuntu-latest
steps:
- name: Notify Discord
env:
WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
ACTION: ${{ github.event.action }}
ISSUE_NUM: ${{ github.event.issue.number }}
ISSUE_URL: ${{ github.event.issue.html_url }}
ISSUE_TITLE: ${{ github.event.issue.title }}
ISSUE_USER: ${{ github.event.issue.user.login }}
ISSUE_BODY: ${{ github.event.issue.body }}
run: |
# escape markdown special chars
esc() { sed 's/[\\*_[\]()~`>]/\\&/g'; }
if [ "$ACTION" = "opened" ]; then ICON="🐛"; LABEL="New Issue"
elif [ "$ACTION" = "closed" ]; then ICON="✅"; LABEL="Closed"
else ICON="🔄"; LABEL="Reopened"; fi
TITLE=$(echo "$ISSUE_TITLE" | esc)
BODY=$(echo "$ISSUE_BODY" | tr '\n\r' ' ' | head -c $MAX_BODY_LENGTH | esc)
[ ${#ISSUE_BODY} -gt $MAX_BODY_LENGTH ] && BODY="${BODY}..."
[ -n "$BODY" ] && BODY=" · $BODY"
MSG="$ICON **[$LABEL #$ISSUE_NUM: $TITLE](<$ISSUE_URL>)**"$'\n'"by @$ISSUE_USER$BODY"
jq -n --arg content "$MSG" '{content: $content}' | curl -X POST "$WEBHOOK" -H "Content-Type: application/json" -d @-
# Issue comment
issue_comment:
if: github.event_name == 'issue_comment'
runs-on: ubuntu-latest
steps:
- name: Notify Discord
env:
WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
IS_PR: ${{ github.event.issue.pull_request && 'true' || 'false' }}
ISSUE_NUM: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
COMMENT_URL: ${{ github.event.comment.html_url }}
COMMENT_USER: ${{ github.event.comment.user.login }}
COMMENT_BODY: ${{ github.event.comment.body }}
run: |
# escape markdown special chars
esc() { sed 's/[\\*_[\]()~`>]/\\&/g'; }
[ "$IS_PR" = "true" ] && TYPE="PR" || TYPE="Issue"
TITLE=$(echo "$ISSUE_TITLE" | esc)
BODY=$(echo "$COMMENT_BODY" | tr '\n\r' ' ' | head -c $MAX_BODY_LENGTH | esc)
[ ${#COMMENT_BODY} -gt $MAX_BODY_LENGTH ] && BODY="${BODY}..."
MSG="💬 **[Comment on $TYPE #$ISSUE_NUM: $TITLE](<$COMMENT_URL>)**"$'\n'"@$COMMENT_USER: $BODY"
jq -n --arg content "$MSG" '{content: $content}' | curl -X POST "$WEBHOOK" -H "Content-Type: application/json" -d @-
# PR Review
pull_request_review:
if: github.event_name == 'pull_request_review'
runs-on: ubuntu-latest
steps:
- name: Notify Discord
env:
WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
STATE: ${{ github.event.review.state }}
PR_NUM: ${{ github.event.pull_request.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
REVIEW_URL: ${{ github.event.review.html_url }}
REVIEW_USER: ${{ github.event.review.user.login }}
REVIEW_BODY: ${{ github.event.review.body }}
run: |
# escape markdown special chars
esc() { sed 's/[\\*_[\]()~`>]/\\&/g'; }
if [ "$STATE" = "approved" ]; then ICON="✅"; LABEL="Approved"
elif [ "$STATE" = "changes_requested" ]; then ICON="🔧"; LABEL="Changes Requested"
else ICON="👀"; LABEL="Reviewed"; fi
TITLE=$(echo "$PR_TITLE" | esc)
BODY=$(echo "$REVIEW_BODY" | tr '\n\r' ' ' | head -c $MAX_BODY_LENGTH | esc)
[ ${#REVIEW_BODY} -gt $MAX_BODY_LENGTH ] && BODY="${BODY}..."
[ -n "$BODY" ] && BODY=": $BODY"
MSG="$ICON **[$LABEL PR #$PR_NUM: $TITLE](<$REVIEW_URL>)**"$'\n'"@$REVIEW_USER$BODY"
jq -n --arg content "$MSG" '{content: $content}' | curl -X POST "$WEBHOOK" -H "Content-Type: application/json" -d @-
# PR Review comment
pull_request_review_comment:
if: github.event_name == 'pull_request_review_comment'
runs-on: ubuntu-latest
steps:
- name: Notify Discord
env:
WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
PR_NUM: ${{ github.event.pull_request.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
COMMENT_URL: ${{ github.event.comment.html_url }}
COMMENT_USER: ${{ github.event.comment.user.login }}
COMMENT_BODY: ${{ github.event.comment.body }}
run: |
# escape markdown special chars
esc() { sed 's/[\\*_[\]()~`>]/\\&/g'; }
TITLE=$(echo "$PR_TITLE" | esc)
BODY=$(echo "$COMMENT_BODY" | tr '\n\r' ' ' | head -c $MAX_BODY_LENGTH | esc)
[ ${#COMMENT_BODY} -gt $MAX_BODY_LENGTH ] && BODY="${BODY}..."
MSG="💭 **[Review Comment PR #$PR_NUM: $TITLE](<$COMMENT_URL>)**"$'\n'"@$COMMENT_USER: $BODY"
jq -n --arg content "$MSG" '{content: $content}' | curl -X POST "$WEBHOOK" -H "Content-Type: application/json" -d @-
# Release
release:
if: github.event_name == 'release'
runs-on: ubuntu-latest
steps:
- name: Notify Discord
env:
WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
TAG: ${{ github.event.release.tag_name }}
NAME: ${{ github.event.release.name }}
URL: ${{ github.event.release.html_url }}
RELEASE_BODY: ${{ github.event.release.body }}
run: |
# escape markdown special chars
esc() { sed 's/[\\*_[\]()~`>]/\\&/g'; }
REL_NAME=$(echo "$NAME" | esc)
BODY=$(echo "$RELEASE_BODY" | tr '\n\r' ' ' | head -c $MAX_BODY_LENGTH | esc)
[ ${#RELEASE_BODY} -gt $MAX_BODY_LENGTH ] && BODY="${BODY}..."
[ -n "$BODY" ] && BODY=" · $BODY"
MSG="🚀 **[Release $TAG: $REL_NAME](<$URL>)**"$'\n'"$BODY"
jq -n --arg content "$MSG" '{content: $content}' | curl -X POST "$WEBHOOK" -H "Content-Type: application/json" -d @-
# Branch/tag created
create:
if: github.event_name == 'create'
runs-on: ubuntu-latest
steps:
- name: Notify Discord
env:
WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
REF_TYPE: ${{ github.event.ref_type }}
REF: ${{ github.event.ref }}
ACTOR: ${{ github.actor }}
REPO_URL: ${{ github.event.repository.html_url }}
run: |
[ "$REF_TYPE" = "branch" ] && ICON="🌿" || ICON="🏷️"
MSG="$ICON **${REF_TYPE^} created: [$REF](<$REPO_URL/tree/$REF>)** by @$ACTOR"
jq -n --arg content "$MSG" '{content: $content}' | curl -X POST "$WEBHOOK" -H "Content-Type: application/json" -d @-
# Branch/tag deleted
delete:
if: github.event_name == 'delete'
runs-on: ubuntu-latest
steps:
- name: Notify Discord
env:
WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
REF_TYPE: ${{ github.event.ref_type }}
REF: ${{ github.event.ref }}
ACTOR: ${{ github.actor }}
run: |
MSG="🗑️ **${REF_TYPE^} deleted: $REF** by @$ACTOR"
jq -n --arg content "$MSG" '{content: $content}' | curl -X POST "$WEBHOOK" -H "Content-Type: application/json" -d @-