From b0611de1b3f019bc14e638abcfcd21f7cdeecb70 Mon Sep 17 00:00:00 2001 From: Felix Weinberger Date: Fri, 27 Feb 2026 13:00:32 +0000 Subject: [PATCH] Add PR Slack notification workflow Standalone workflow that notifies a random reviewer on Slack when a non-draft PR is opened. Uses MAINTAINER_MAP and SLACK_WEBHOOK_URL repo secrets to determine team members and post notifications. --- .github/workflows/pr-notify.yml | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/pr-notify.yml diff --git a/.github/workflows/pr-notify.yml b/.github/workflows/pr-notify.yml new file mode 100644 index 000000000..63aaa2c52 --- /dev/null +++ b/.github/workflows/pr-notify.yml @@ -0,0 +1,44 @@ +name: PR Slack Notification + +on: + pull_request: + types: [opened, ready_for_review] + +jobs: + notify: + name: Notify maintainers + runs-on: ubuntu-latest + if: >- + !github.event.pull_request.draft + permissions: {} + steps: + - name: Notify Slack + env: + MAINTAINER_MAP: ${{ secrets.MAINTAINER_MAP }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + PR_URL: ${{ github.event.pull_request.html_url }} + PR_NUMBER: ${{ github.event.pull_request.number }} + PR_TITLE: ${{ github.event.pull_request.title }} + PR_AUTHOR: ${{ github.event.pull_request.user.login }} + run: | + # Check if PR author is on the team (triggers list) + if ! echo "$MAINTAINER_MAP" | jq -e --arg author "$PR_AUTHOR" '.triggers | index($author)' > /dev/null 2>&1; then + echo "PR author $PR_AUTHOR is not on the team, skipping notification" + exit 0 + fi + + # Pick a random reviewer + ALL_REVIEWERS=$(echo "$MAINTAINER_MAP" | jq -r '.reviewers | keys[]') + REVIEWERS_ARRAY=($ALL_REVIEWERS) + if [ ${#REVIEWERS_ARRAY[@]} -eq 0 ]; then + echo "No reviewers configured" + exit 0 + fi + REVIEWER=${REVIEWERS_ARRAY[$((RANDOM % ${#REVIEWERS_ARRAY[@]}))]} + SLACK_ID=$(echo "$MAINTAINER_MAP" | jq -r --arg user "$REVIEWER" '.reviewers[$user].slack') + + # Post to Slack + SLACK_TEXT="${PR_URL} \"${PR_TITLE}\" by ${PR_AUTHOR}" + curl -sf -X POST "$SLACK_WEBHOOK_URL" \ + -H 'Content-Type: application/json' \ + -d "$(jq -n --arg text "$SLACK_TEXT" --arg user_id "$SLACK_ID" '{text: $text, user_id: $user_id}')" || echo "::warning::Slack notification failed"