@@ -161,30 +161,46 @@ jobs:
161161 env :
162162 ALLOWED_APPROVERS : ${{ vars.SOUP_APPROVERS }}
163163 run : |
164- APPROVED_BY="${{ github.event.review.user.login }}"
164+ PR_NUMBER="${{ github.event.pull_request.number }}"
165+ REPO="${{ github.repository }}"
166+
167+ echo "Fetching all approvers for PR #$PR_NUMBER in $REPO..."
168+
169+ ALL_APPROVERS=$(curl -s -H "Authorization: Bearer $GH_API_TOKEN" \
170+ "https://api.github.com/repos/$REPO/pulls/$PR_NUMBER/reviews" \
171+ | jq -r '.[] | select(.state == "APPROVED") | .user.login' | sort -u)
172+
173+ if [ -z "$ALL_APPROVERS" ]; then
174+ echo "::warning::No approvals found yet for PR #$PR_NUMBER"
175+ exit 1
176+ fi
177+
178+ echo "Found approvers: $ALL_APPROVERS"
165179
166180 if [ -n "$ALLOWED_APPROVERS" ]; then
167- echo "Checking if $APPROVED_BY is in allowed approvers list... "
181+ echo "Checking allowed approvers list: $ALLOWED_APPROVERS "
168182
169183 IFS=',' read -ra APPROVER_LIST <<< "$ALLOWED_APPROVERS"
170- APPROVER_FOUND=false
171184
172- for approver in "${APPROVER_LIST[@]}"; do
173- if [ "$(echo "$approver" | xargs)" = "$APPROVED_BY" ]; then
174- APPROVER_FOUND=true
175- break
176- fi
185+ AUTHORIZED_APPROVERS=()
186+ for approver in $ALL_APPROVERS; do
187+ for allowed in "${APPROVER_LIST[@]}"; do
188+ if [ "$(echo "$allowed" | xargs)" = "$approver" ]; then
189+ AUTHORIZED_APPROVERS+=("$approver")
190+ fi
191+ done
177192 done
178193
179- if [ "$APPROVER_FOUND" = false ]; then
180- echo "::error::❌ $APPROVED_BY is not in the allowed approvers list: $ALLOWED_APPROVERS"
194+ if [ ${#AUTHORIZED_APPROVERS[@]} -eq 0 ]; then
195+ echo "::error::❌ None of the approvers ($ALL_APPROVERS) are in the allowed list: $ALLOWED_APPROVERS"
181196 echo "Approval will not be recorded."
182197 exit 1
183198 fi
184199
185- echo "✅ $APPROVED_BY is authorized to approve soups "
200+ echo "✅ Authorized approvers found: ${AUTHORIZED_APPROVERS[*]} "
186201 else
187202 echo "⚠️ No ALLOWED_APPROVERS configured - allowing all approvals"
203+ AUTHORIZED_APPROVERS=($ALL_APPROVERS)
188204 fi
189205
190206 APPROVED_ON=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
@@ -201,7 +217,10 @@ jobs:
201217 continue
202218 fi
203219
204- APPROVER_INFO=$(curl -s -H "Authorization: Bearer $GH_API_TOKEN" "https://api.github.com/users/$APPROVED_BY")
220+ APPROVED_BY="${AUTHORIZED_APPROVERS[0]}"
221+
222+ APPROVER_INFO=$(curl -s -H "Authorization: Bearer $GH_API_TOKEN" \
223+ "https://api.github.com/users/$APPROVED_BY")
205224 APPROVER_NAME=$(echo "$APPROVER_INFO" | jq -r '.name // empty')
206225 if [ -z "$APPROVER_NAME" ]; then
207226 APPROVER_NAME="$APPROVED_BY"
0 commit comments