|
1 | | -name: Send Team Members to Webhook |
| 1 | +name: Send Reviewers to Webhook |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | pull_request: |
5 | 5 | types: [labeled] |
6 | | - |
| 6 | + |
7 | 7 | jobs: |
8 | | - send_team_members: |
| 8 | + send_reviewers: |
9 | 9 | runs-on: ubuntu-latest |
10 | 10 |
|
11 | 11 | steps: |
12 | | - - name: Checkout repository |
13 | | - uses: actions/checkout@v3 |
14 | | - |
15 | | - - name: Fetch team members and send to webhook |
| 12 | + - name: Send assigned reviewers to webhook |
16 | 13 | run: | |
17 | | - # Configuration |
18 | | - TEAM_SLUG="possession-claim-backend" |
19 | | - ORG_NAME="hmcts" |
20 | 14 | WEBHOOK_URL="${{ secrets.WEBHOOK_URL }}" |
21 | | -
|
22 | | - # Fetch team members - let's see the raw response |
23 | | - echo "Fetching members from: https://api.github.com/orgs/$ORG_NAME/teams/$TEAM_SLUG/members" |
24 | | - |
25 | | - RESPONSE=$(curl -sH "Authorization: token ${{ secrets.ORG_ACCESS_TOKEN }}" \ |
26 | | - "https://api.github.com/orgs/$ORG_NAME/teams/$TEAM_SLUG/members") |
27 | | - |
28 | | - # Debug: print the raw response |
29 | | - echo "Raw API Response:" |
30 | | - echo "$RESPONSE" |
31 | | - |
32 | | - # Check if it's valid JSON and an array |
33 | | - if echo "$RESPONSE" | jq -e 'type == "array"' > /dev/null 2>&1; then |
34 | | - echo "Response is a valid array" |
35 | | - USERNAMES=$(echo "$RESPONSE" | jq -r '.[].login' | paste -sd "," -) |
36 | | - echo "Found users: $USERNAMES" |
37 | | - else |
38 | | - echo "ERROR: Response is not an array. Likely an API error:" |
39 | | - echo "$RESPONSE" | jq '.' |
40 | | - exit 1 |
41 | | - fi |
42 | | - |
43 | | - # Send to webhook (hardcoded for testing) |
| 15 | + |
| 16 | + # Get individual reviewers |
| 17 | + REVIEWERS=$(echo '${{ toJson(github.event.pull_request.requested_reviewers) }}' | jq -r '.[].login' | paste -sd "," -) |
| 18 | + |
| 19 | + # Get team reviewers (if teams were assigned) |
| 20 | + TEAM_REVIEWERS=$(echo '${{ toJson(github.event.pull_request.requested_teams) }}' | jq -r '.[].name' | paste -sd "," -) |
| 21 | + |
| 22 | + # Combine both |
| 23 | + ALL_REVIEWERS="${REVIEWERS}${TEAM_REVIEWERS:+,}${TEAM_REVIEWERS}" |
| 24 | + |
| 25 | + echo "Assigned reviewers: $ALL_REVIEWERS" |
| 26 | + |
| 27 | + # Build the message |
| 28 | + PR_TITLE="${{ github.event.pull_request.title }}" |
| 29 | + PR_URL="${{ github.event.pull_request.html_url }}" |
| 30 | + PR_AUTHOR="${{ github.event.pull_request.user.login }}" |
| 31 | + |
| 32 | + MESSAGE="New PR review requested: '$PR_TITLE' by @$PR_AUTHOR - Reviewers: $ALL_REVIEWERS - $PR_URL" |
| 33 | + |
| 34 | + # Send to webhook |
| 35 | + PAYLOAD=$(jq -n --arg text "$MESSAGE" '{"text": $text}') |
| 36 | + |
44 | 37 | curl -X POST "$WEBHOOK_URL" \ |
45 | 38 | -H "Content-Type: application/json" \ |
46 | | - -d '{"text": "test message"}' |
| 39 | + -d "$PAYLOAD" |
47 | 40 | |
48 | | - echo "Sent to webhook successfully!" |
| 41 | + echo "Sent reviewers to webhook successfully!" |
0 commit comments