From 5945e0145697380a4334622e1e0820590106a08d Mon Sep 17 00:00:00 2001 From: Sven Klemm Date: Fri, 18 Oct 2024 23:16:46 +0200 Subject: [PATCH] Fix approval count workflow When queried from within action context .authorAssociation is not filled in as MEMBER but CONTRIBUTOR instead so adjust to query to take that into account. --- .github/workflows/pr-approvals.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-approvals.yaml b/.github/workflows/pr-approvals.yaml index 84b4b3a5dff..f78e7b37951 100644 --- a/.github/workflows/pr-approvals.yaml +++ b/.github/workflows/pr-approvals.yaml @@ -5,6 +5,7 @@ name: PR Approval Check "on": pull_request: + types: [opened, synchronize, reopened, edited, auto_merge_enabled, auto_merge_disabled] branches: [main] jobs: @@ -27,9 +28,7 @@ jobs: # Get the list of modified files in this pull request files=$(gh pr view $PR_NUMBER --json files --jq '.files.[].path | select(startswith(".github") | not)') # Get the number of approvals in this pull request - approvals=$(gh pr view $PR_NUMBER --json reviews --jq '[.reviews.[] | select(.authorAssociation == "MEMBER" and .state == "APPROVED")] | length') - - gh pr view $PR_NUMBER --json reviews --jq '[.reviews.[] | select(.authorAssociation == "MEMBER" and .state == "APPROVED")]' + approvals=$(gh pr view $PR_NUMBER --json reviews --jq '[.reviews.[] | select((.authorAssociation == "MEMBER" or .authorAssociation == "CONTRIBUTOR") and .state == "APPROVED")] | length') if [[ $approvals -lt 2 ]] && [[ "${files}" ]] ; then echo "This pull request requires 2 approvals before merging."