diff --git a/.github/workflows/pr-slack-notification.yml b/.github/workflows/pr-slack-notification.yml new file mode 100644 index 0000000..d030c45 --- /dev/null +++ b/.github/workflows/pr-slack-notification.yml @@ -0,0 +1,42 @@ +name: PR Slack Notification + +on: + workflow_call: + secrets: + slack_webhook_url: + required: true + +permissions: {} + +jobs: + notify: + runs-on: ubuntu-latest + steps: + - name: Post to Slack + env: + SLACK_WEBHOOK_URL: ${{ secrets.slack_webhook_url }} + PR_AUTHOR: ${{ github.event.pull_request.user.login }} + PR_NUMBER: ${{ github.event.pull_request.number }} + PR_TITLE: ${{ github.event.pull_request.title }} + PR_URL: ${{ github.event.pull_request.html_url }} + REPOSITORY: ${{ github.repository }} + run: | + set -o pipefail + + jq -n \ + --arg author "$PR_AUTHOR" \ + --arg number "$PR_NUMBER" \ + --arg repository "$REPOSITORY" \ + --arg title "$PR_TITLE" \ + --arg url "$PR_URL" \ + '{ + text: "Pull request notification", + blocks: [ + {type: "section", text: {type: "mrkdwn", text: ("*Pull request:* <" + $url + "|" + $repository + " #" + $number + ">")}}, + {type: "section", text: {type: "plain_text", text: ($title + " — by @" + $author), emoji: true}} + ] + }' | + curl --fail-with-body --silent --show-error \ + --header 'Content-type: application/json' \ + --data @- \ + "$SLACK_WEBHOOK_URL"