|
15 | 15 | - uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2 |
16 | 16 | with: |
17 | 17 | jobs: ${{ toJSON(needs) }} |
| 18 | + |
| 19 | + notify: |
| 20 | + name: Notify maintainers |
| 21 | + runs-on: ubuntu-latest |
| 22 | + needs: [all-green] |
| 23 | + if: >- |
| 24 | + !github.event.pull_request.draft && |
| 25 | + needs.all-green.result == 'success' |
| 26 | + permissions: {} |
| 27 | + steps: |
| 28 | + - name: Notify Slack |
| 29 | + env: |
| 30 | + MAINTAINER_MAP: ${{ secrets.MAINTAINER_MAP }} |
| 31 | + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |
| 32 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 33 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 34 | + PR_TITLE: ${{ github.event.pull_request.title }} |
| 35 | + PR_AUTHOR: ${{ github.event.pull_request.user.login }} |
| 36 | + run: | |
| 37 | + # Check if PR author is on the team (triggers list) |
| 38 | + if ! echo "$MAINTAINER_MAP" | jq -e --arg author "$PR_AUTHOR" '.triggers | index($author)' > /dev/null 2>&1; then |
| 39 | + echo "PR author $PR_AUTHOR is not on the team, skipping notification" |
| 40 | + exit 0 |
| 41 | + fi |
| 42 | +
|
| 43 | + # Pick a random reviewer |
| 44 | + ALL_REVIEWERS=$(echo "$MAINTAINER_MAP" | jq -r '.reviewers | keys[]') |
| 45 | + REVIEWERS_ARRAY=($ALL_REVIEWERS) |
| 46 | + if [ ${#REVIEWERS_ARRAY[@]} -eq 0 ]; then |
| 47 | + echo "No reviewers configured" |
| 48 | + exit 0 |
| 49 | + fi |
| 50 | + REVIEWER=${REVIEWERS_ARRAY[$((RANDOM % ${#REVIEWERS_ARRAY[@]}))]} |
| 51 | + SLACK_ID=$(echo "$MAINTAINER_MAP" | jq -r --arg user "$REVIEWER" '.reviewers[$user].slack') |
| 52 | +
|
| 53 | + # Post to Slack |
| 54 | + SLACK_TEXT="${PR_URL} \"${PR_TITLE}\" by ${PR_AUTHOR}" |
| 55 | + curl -sf -X POST "$SLACK_WEBHOOK_URL" \ |
| 56 | + -H 'Content-Type: application/json' \ |
| 57 | + -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