Skip to content

Commit

Permalink
Fix issue with PR approval workflow
Browse files Browse the repository at this point in the history
Remove event information from workflow and count the number of files
rather than try to test for them.
  • Loading branch information
mkindahl committed Dec 2, 2024
1 parent 9198f3d commit e40a4d3
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions .github/workflows/pr-approvals.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,25 @@ jobs:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.number }}
run: |
echo "Event is: "
cat <<EOF
${{ toJSON(github.event) }}
EOF
echo "PR number is $PR_NUMBER"
echo "$BODY" | egrep -qsi '^disable-check:.*\<approval-count\>'
if [[ $? -ne 0 ]]; then
# Get the list of modified files in this pull request
echo "Modified files: "
gh pr view $PR_NUMBER --json files
# Get modified files, but exclude those that are workflow
# files or are related to Hypercore table access
# method. These require only a single reviewer.
files=$(gh pr view $PR_NUMBER --json files --jq '.files.[].path | select(startswith(".github") or test("hypercore|columnar_scan") | not)')
# Get the number of modified files, but exclude those that
# are workflow files or are related to Hypercore table
# access method. These require only a single reviewer.
files=$(gh pr view $PR_NUMBER --json files --jq '[.files.[].path | select(startswith(".github") or test("hypercore|columnar_scan") | not)] | length')
# Get the number of approvals in this pull request
echo "Reviews: "
gh pr view $PR_NUMBER --json reviews
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 "Approvals:"
gh pr view $PR_NUMBER --json reviews --jq ' [.reviews.[] | select(( .authorAssociation == "NONE" or .authorAssociation == "MEMBER" or .authorAssociation == "CONTRIBUTOR" ) and .state == "APPROVED")] | length'

Check failure on line 43 in .github/workflows/pr-approvals.yaml

View workflow job for this annotation

GitHub Actions / Check YAML code in tree

43:211 [line-length] line too long (220 > 210 characters)
approvals=$(gh pr view $PR_NUMBER --json reviews --jq '[.reviews.[] | select((.authorAssociation == "NONE" or .authorAssociation == "MEMBER" or .authorAssociation == "CONTRIBUTOR") and .state == "APPROVED")] | length')

Check failure on line 44 in .github/workflows/pr-approvals.yaml

View workflow job for this annotation

GitHub Actions / Check YAML code in tree

44:211 [line-length] line too long (230 > 210 characters)
echo "approvals: $approvals, files: $files"
if [[ "$approvals -lt 2 -a $files -gt 0" ]] ; then
echo "This pull request requires 2 approvals before merging."
echo
echo "For trivial changes, you may disable this check by adding this trailer to the pull request message:"
Expand Down

0 comments on commit e40a4d3

Please sign in to comment.