-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
21 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,12 @@ 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') | ||
approvals=$(gh pr view $PR_NUMBER --json reviews --jq '[.reviews.[] | select((.authorAssociation == "MEMBER" or .authorAssociation == "CONTRIBUTOR") and .state == "APPROVED")] | length') | ||
gh pr view $PR_NUMBER --json reviews --jq '[.reviews.[] | select(.authorAssociation == "MEMBER" and .state == "APPROVED")]' | ||
gh pr view $PR_NUMBER --json reviews --jq '[.reviews.[] | select((.authorAssociation == "MEMBER" or .authorAssociation == "CONTRIBUTOR") and .state == "APPROVED")] | length' | ||
gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/timescale/timescaledb/pulls/$PR_NUMBER/reviews | ||
gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/timescale/timescaledb/pulls/$PR_NUMBER/reviews --jq 'map(select(.author_association == "MEMBER" and .state == "APPROVED")) | length' | ||
if [[ $approvals -lt 2 ]] && [[ "${files}" ]] ; then | ||
echo "This pull request requires 2 approvals before merging." | ||
|
@@ -42,3 +46,18 @@ jobs: | |
fi | ||
fi | ||
check_try: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: octokit/[email protected] | ||
id: approval_count | ||
with: | ||
route: GET /repos/${{ github.repository }}/pulls/${{ github.event.review.number }}/reviews | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
- id: test_variables | ||
run: | | ||
JSON_RESPONSE='${{ steps.approval_count.outputs.data }}' | ||
CURRENT_APPROVALS_COUNT=$(echo $JSON_RESPONSE | jq -c '[.[] | select(.state | contains("APPROVED")) ] | length') | ||
echo "Current approvals count: $CURRENT_APPROVALS_COUNT" |