File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ name : PR Slack Notification
2+
3+ on :
4+ pull_request :
5+
6+ jobs :
7+ notify :
8+ name : Notify maintainers
9+ runs-on : ubuntu-latest
10+ if : >-
11+ !github.event.pull_request.draft
12+ permissions : {}
13+ steps :
14+ - name : Notify Slack
15+ env :
16+ MAINTAINER_MAP : ${{ secrets.MAINTAINER_MAP }}
17+ SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK_URL }}
18+ PR_URL : ${{ github.event.pull_request.html_url }}
19+ PR_NUMBER : ${{ github.event.pull_request.number }}
20+ PR_TITLE : ${{ github.event.pull_request.title }}
21+ PR_AUTHOR : ${{ github.event.pull_request.user.login }}
22+ run : |
23+ # Check if PR author is on the team (triggers list)
24+ if ! echo "$MAINTAINER_MAP" | jq -e --arg author "$PR_AUTHOR" '.triggers | index($author)' > /dev/null 2>&1; then
25+ echo "PR author $PR_AUTHOR is not on the team, skipping notification"
26+ exit 0
27+ fi
28+
29+ # Pick a random reviewer
30+ ALL_REVIEWERS=$(echo "$MAINTAINER_MAP" | jq -r '.reviewers | keys[]')
31+ REVIEWERS_ARRAY=($ALL_REVIEWERS)
32+ if [ ${#REVIEWERS_ARRAY[@]} -eq 0 ]; then
33+ echo "No reviewers configured"
34+ exit 0
35+ fi
36+ REVIEWER=${REVIEWERS_ARRAY[$((RANDOM % ${#REVIEWERS_ARRAY[@]}))]}
37+ SLACK_ID=$(echo "$MAINTAINER_MAP" | jq -r --arg user "$REVIEWER" '.reviewers[$user].slack')
38+
39+ # Post to Slack
40+ SLACK_TEXT="${PR_URL} \"${PR_TITLE}\" by ${PR_AUTHOR}"
41+ curl -sf -X POST "$SLACK_WEBHOOK_URL" \
42+ -H 'Content-Type: application/json' \
43+ -d "$(jq -n --arg text "$SLACK_TEXT" --arg user_id "$SLACK_ID" '{text: $text, user_id: $user_id}')" || echo "::warning::Slack notification failed"
You can’t perform that action at this time.
0 commit comments