Notify Discord on Issue Events #86
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 Issue Events | |
| on: | |
| issues: | |
| types: [opened, closed] | |
| issue_comment: | |
| types: [created] | |
| jobs: | |
| notify-discord: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Send Discord Webhook | |
| env: | |
| DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} | |
| run: | | |
| sanitize() { | |
| echo "$1" | jq -Rsa . | |
| } | |
| if [[ "${{ github.event_name }}" == "issues" ]]; then | |
| ISSUE_TITLE=$(sanitize "${{ github.event.issue.title }}") | |
| ISSUE_BODY=$(sanitize "${{ github.event.issue.body }}") | |
| ISSUE_URL=$(sanitize "${{ github.event.issue.html_url }}") | |
| ISSUE_USER=$(sanitize "${{ github.event.issue.user.login }}") | |
| if [[ "${{ github.event.action }}" == "opened" ]]; then | |
| STATUS="opened" | |
| DESCRIPTION=$ISSUE_BODY | |
| elif [[ "${{ github.event.action }}" == "closed" ]]; then | |
| STATUS="closed" | |
| DESCRIPTION=$(sanitize "This issue has been closed.") | |
| fi | |
| PAYLOAD=$(jq -n \ | |
| --argjson title $ISSUE_TITLE \ | |
| --argjson url $ISSUE_URL \ | |
| --argjson description $DESCRIPTION \ | |
| --argjson user $ISSUE_USER \ | |
| '{ | |
| "embeds": [ | |
| { | |
| "title": $title, | |
| "url": $url, | |
| "description": $description, | |
| "color": 5814783, | |
| "author": { | |
| "name": $user | |
| } | |
| } | |
| ] | |
| }') | |
| elif [[ "${{ github.event_name }}" == "issue_comment" ]]; then | |
| ISSUE_TITLE=$(sanitize "${{ github.event.issue.title }}") | |
| ISSUE_URL=$(sanitize "${{ github.event.issue.html_url }}") | |
| COMMENT_BODY=$(sanitize "${{ github.event.comment.body }}") | |
| COMMENT_USER=$(sanitize "${{ github.event.comment.user.login }}") | |
| PAYLOAD=$(jq -n \ | |
| --argjson title "$(sanitize "[growly-group/docs-devscout] New comment on: ${ISSUE_TITLE}")" \ | |
| --argjson url $ISSUE_URL \ | |
| --argjson description $COMMENT_BODY \ | |
| --argjson user $COMMENT_USER \ | |
| '{ | |
| "embeds": [ | |
| { | |
| "title": $title, | |
| "url": $url, | |
| "description": $description, | |
| "color": 5814783, | |
| "author": { | |
| "name": $user | |
| } | |
| } | |
| ] | |
| }') | |
| fi | |
| curl -H "Content-Type: application/json" -X POST -d "$PAYLOAD" "$DISCORD_WEBHOOK" |