Skip to content

Commit f33eb86

Browse files
Update send-team-memebrs.yml
1 parent c2e6931 commit f33eb86

1 file changed

Lines changed: 28 additions & 35 deletions

File tree

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,41 @@
1-
name: Send Team Members to Webhook
1+
name: Send Reviewers to Webhook
22

33
on:
44
pull_request:
55
types: [labeled]
6-
6+
77
jobs:
8-
send_team_members:
8+
send_reviewers:
99
runs-on: ubuntu-latest
1010

1111
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
1613
run: |
17-
# Configuration
18-
TEAM_SLUG="possession-claim-backend"
19-
ORG_NAME="hmcts"
2014
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+
4437
curl -X POST "$WEBHOOK_URL" \
4538
-H "Content-Type: application/json" \
46-
-d '{"text": "test message"}'
39+
-d "$PAYLOAD"
4740
48-
echo "Sent to webhook successfully!"
41+
echo "Sent reviewers to webhook successfully!"

0 commit comments

Comments
 (0)