Skip to content

Commit 7692255

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 7692255

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

.github/workflows/main.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,44 @@ 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
52+
ALL_REVIEWERS=$(echo "$MAINTAINER_MAP" | jq -r '.reviewers | keys[]')
53+
REVIEWERS_ARRAY=($ALL_REVIEWERS)
54+
if [ ${#REVIEWERS_ARRAY[@]} -eq 0 ]; then
55+
echo "No reviewers configured"
56+
exit 0
57+
fi
58+
REVIEWER=${REVIEWERS_ARRAY[$((RANDOM % ${#REVIEWERS_ARRAY[@]}))]}
59+
SLACK_ID=$(echo "$MAINTAINER_MAP" | jq -r --arg user "$REVIEWER" '.reviewers[$user].slack')
60+
61+
# Post to Slack
62+
SLACK_TEXT="${PR_URL} \"${PR_TITLE}\" by ${PR_AUTHOR}"
63+
curl -sf -X POST "$SLACK_WEBHOOK_URL" \
64+
-H 'Content-Type: application/json' \
65+
-d "$(jq -n --arg text "$SLACK_TEXT" --arg user_id "$SLACK_ID" '{text: $text, user_id: $user_id}')" || echo "::warning::Slack notification failed"

0 commit comments

Comments
 (0)