diff --git a/.github/workflows/pr-slack-notification.yml b/.github/workflows/pr-slack-notification.yml new file mode 100644 index 0000000..4e6fb6b --- /dev/null +++ b/.github/workflows/pr-slack-notification.yml @@ -0,0 +1,39 @@ +name: Slack notification + +on: + pull_request: + types: [opened, reopened, ready_for_review] + +permissions: + contents: read + +jobs: + notify-slack: + name: Send + if: ${{ !github.event.pull_request.draft }} + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Send PR link + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_TECH_WEBHOOK_URL }} + PR_REPO: ${{ github.event.repository.name }} + PR_NUMBER: ${{ github.event.pull_request.number }} + PR_AUTHOR: ${{ github.event.pull_request.user.login }} + PR_URL: ${{ github.event.pull_request.html_url }} + run: | + if [ -z "$SLACK_WEBHOOK_URL" ]; then + echo "SLACK_TECH_WEBHOOK_URL is not configured; skipping Slack notification." + exit 0 + fi + + curl --fail --silent --show-error \ + -X POST \ + -H 'Content-type: application/json' \ + --data "$(jq -n \ + --arg repo "$PR_REPO" \ + --arg number "$PR_NUMBER" \ + --arg author "$PR_AUTHOR" \ + --arg url "$PR_URL" \ + '{text: ("New " + $repo + " PR: <" + $url + "|#" + $number + "> by " + $author)}')" \ + "$SLACK_WEBHOOK_URL"