|
22 | 22 | - uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2 |
23 | 23 | with: |
24 | 24 | 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