Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/pr-notify.yml
Original file line number Diff line number Diff line change
@@ -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"