refactor: encapsulate handle_message params into MessageContext struc… #17
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: Notify Discord | ||
| on: | ||
| pull_request: | ||
| types: [opened, reopened] | ||
| issues: | ||
| types: [opened, reopened] | ||
| jobs: | ||
| notify: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Send to Discord | ||
| env: | ||
| DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} | ||
| EVENT_NAME: ${{ github.event_name }} | ||
| EVENT_ACTION: ${{ github.event.action }} | ||
| PR_TITLE: ${{ github.event.pull_request.title }} | ||
| PR_URL: ${{ github.event.pull_request.html_url }} | ||
| PR_AUTHOR: ${{ github.event.pull_request.user.login }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| ISSUE_TITLE: ${{ github.event.issue.title }} | ||
| ISSUE_URL: ${{ github.event.issue.html_url }} | ||
| ISSUE_AUTHOR: ${{ github.event.issue.user.login }} | ||
| ISSUE_NUMBER: ${{ github.event.issue.number }} | ||
| REPO: ${{ github.repository }} | ||
| run: | | ||
| [ -z "$DISCORD_WEBHOOK_URL" ] && { echo "::warning::DISCORD_WEBHOOK_URL not set"; exit 0; } | ||
| if [ "$EVENT_NAME" = "pull_request" ]; then | ||
| TITLE="$PR_TITLE" | ||
| URL="$PR_URL" | ||
| AUTHOR="$PR_AUTHOR" | ||
| NUM="$PR_NUMBER" | ||
| TYPE="pr_${EVENT_ACTION}" | ||
| LABEL="PR #${NUM}" | ||
| else | ||
| TITLE="$ISSUE_TITLE" | ||
| URL="$ISSUE_URL" | ||
| AUTHOR="$ISSUE_AUTHOR" | ||
| NUM="$ISSUE_NUMBER" | ||
| TYPE="issue_${EVENT_ACTION}" | ||
| LABEL="Issue #${NUM}" | ||
| fi | ||
| PAYLOAD=$(jq -n \ | ||
| --arg content "[GH-EVENT] repo:${REPO} action:${TYPE} ${LABEL} | ||
| **${TITLE}** | ||
| by ${AUTHOR} | ||
| ${URL}" \ | ||
| '{"content": $content}') | ||
| curl --fail-with-body -s -H "Content-Type: application/json" -d "$PAYLOAD" "$DISCORD_WEBHOOK_URL" | ||