Skip to content

Commit 8df1e5b

Browse files
ci: add Slack notification for maintainer PRs
Add a notify job to the CI workflow that posts to Slack when an MCP team member opens a non-draft PR and CI passes. A random reviewer from a configured pool is tagged for review. Requires two repo secrets: - MAINTAINER_MAP: JSON with triggers (team members) and reviewers (notification pool) - SLACK_WEBHOOK_URL: Slack workflow webhook URL
1 parent 0fe16dd commit 8df1e5b

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

.github/workflows/main.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,47 @@ jobs:
2222
- uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2
2323
with:
2424
jobs: ${{ toJSON(needs) }}
25+
26+
notify:
27+
name: Notify maintainers
28+
runs-on: ubuntu-latest
29+
needs: [all-green]
30+
if: >-
31+
github.event_name == 'pull_request' &&
32+
!github.event.pull_request.draft &&
33+
needs.all-green.result == 'success'
34+
permissions: {}
35+
steps:
36+
- name: Notify Slack
37+
env:
38+
MAINTAINER_MAP: ${{ secrets.MAINTAINER_MAP }}
39+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
40+
PR_URL: ${{ github.event.pull_request.html_url }}
41+
PR_NUMBER: ${{ github.event.pull_request.number }}
42+
PR_TITLE: ${{ github.event.pull_request.title }}
43+
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
44+
run: |
45+
# Check if PR author is on the team (triggers list)
46+
if ! echo "$MAINTAINER_MAP" | jq -e --arg author "$PR_AUTHOR" '.triggers | index($author)' > /dev/null 2>&1; then
47+
echo "PR author $PR_AUTHOR is not on the team, skipping notification"
48+
exit 0
49+
fi
50+
51+
# Pick a random reviewer (excluding the PR author)
52+
OTHERS=$(echo "$MAINTAINER_MAP" | jq -r --arg author "$PR_AUTHOR" '[.reviewers | keys[] | select(. != $author)] | .[]')
53+
OTHERS_ARRAY=($OTHERS)
54+
if [ ${#OTHERS_ARRAY[@]} -eq 0 ]; then
55+
echo "No other reviewers to notify"
56+
exit 0
57+
fi
58+
REVIEWER=${OTHERS_ARRAY[$((RANDOM % ${#OTHERS_ARRAY[@]}))]}
59+
60+
SLACK_ID=$(echo "$MAINTAINER_MAP" | jq -r --arg user "$REVIEWER" '.reviewers[$user].slack // empty')
61+
62+
# Post to Slack (if reviewer has a Slack ID)
63+
if [ -n "$SLACK_ID" ] && [ -n "$SLACK_WEBHOOK_URL" ]; then
64+
SLACK_TEXT="${PR_URL} \"${PR_TITLE}\" by ${PR_AUTHOR}"
65+
curl -sf -X POST "$SLACK_WEBHOOK_URL" \
66+
-H 'Content-Type: application/json' \
67+
-d "$(jq -n --arg text "$SLACK_TEXT" --arg user_id "$SLACK_ID" '{text: $text, user_id: $user_id}')" || echo "::warning::Slack notification failed"
68+
fi

0 commit comments

Comments
 (0)