Skip to content

Commit c30b825

Browse files
authored
Merge branch 'main' into optimise-fortran-linting
2 parents 8a52f96 + 66e2729 commit c30b825

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

.github/workflows/check-cr-approved.yaml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ on:
66
permissions: read-all
77

88
jobs:
9-
check_approved:
9+
cr_check:
1010
runs-on: ubuntu-24.04
1111
timeout-minutes: 2
1212

1313
steps:
1414
- name: Check for Code Reviewer approval
1515
env:
1616
PR_BODY: ${{ github.event.pull_request.body }}
17-
PR_NUMBER: ${{ github.event.number }}
17+
PR_NUMBER: ${{ github.event.pull_request.number }}
1818
REPO: ${{ github.repository }}
1919
GH_TOKEN: ${{ github.token }}
2020
run: |
@@ -29,20 +29,18 @@ jobs:
2929
echo "Expected Code Reviewer: $CODE_REVIEWER"
3030
3131
# -- 2. Check the review status
32-
CR_APPROVED=$(gh pr view -R "$REPO" "$PR_NUMBER" --json "reviews" |
33-
jq -r --arg cr "$CODE_REVIEWER" ' .reviews[] |
34-
select((.author.login == $cr) and .state == "APPROVED") |
35-
.state')
32+
reviews=$(gh pr view -R "$REPO" "$PR_NUMBER" --json "reviews" | jq -r --arg cr "$CODE_REVIEWER" '
33+
[ .reviews[] | select(.author.login == $cr) ]')
3634
37-
if [[ "$CR_APPROVED" == "APPROVED" ]]; then
35+
# Check if any review is APPROVED
36+
approved=$(echo "$reviews" | jq -r '[ .[] | select(.state == "APPROVED") ] | length')
37+
38+
if [[ "$approved" -gt 0 ]]; then
3839
echo "✅ Success: The listed Code Reviewer ($CODE_REVIEWER) has approved this PR."
3940
else
40-
# Exit with failure if the specific reviewer has not yet approved
4141
echo "::error::The listed Code Reviewer ($CODE_REVIEWER) has not yet approved this PR."
4242
echo "Current reviews for this user:"
43-
gh pr view -R "$REPO" "$PR_NUMBER" --json "reviews" | jq -r --arg cr "$CODE_REVIEWER" '
44-
.reviews[] | select(.author.login == $cr) | "- \(.state)"'
45-
43+
echo "$reviews" | jq -r '.[] | "- \(.state)"'
4644
echo "::notice::This action may be bypassed by a reviewer with sufficient permissions if appropriate."
4745
exit 1
4846
fi

0 commit comments

Comments
 (0)