Skip to content

Commit

Permalink
Added Code Rabbit Approval Check to pull-request.yml Workflow (#3008)
Browse files Browse the repository at this point in the history
* Update coderabbit approval

* Update .github/workflows/pull-request.yml

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Fix some issues

* Update code for testing in pr

* Fix issues related to if-fi

* Update pull-request.yml

* Update .github/workflows/pull-request.yml

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* intentionally failing coderabbit

* Fix some issues

* Update .github/workflows/pull-request.yml

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update pull-request.yml

* Update pull-request.yml

* Update pull-request.yml

* Fix issues and intentional coderabbit fail

* Intentional code rabbit fail

* Update coderabbit check in scripts folder

* Update .github/workflows/scripts/validate-coderabbit.yml

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update .github/workflows/scripts/validate-coderabbit.yml

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update needs for coderabbit

* Update scripts folder issue

* Fix issue in yml file

* Update .github/workflows/scripts/validate-coderabbit.sh

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update coderabbit suggestions

* Fix some issues

* Fix some path issues

* Fix some script issues

* Update .github/workflows/pull-request.yml

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Fix some issues

* Update .github/workflows/scripts/validate-coderabbit.sh

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update .github/workflows/scripts/validate-coderabbit.sh

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Fix github pagination

* Update .github/workflows/scripts/validate-coderabbit.sh

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update .github/workflows/scripts/validate-coderabbit.sh

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update .github/workflows/scripts/validate-coderabbit.sh

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Fix github pagination

* Fix some issues

* Removed debug statements

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
mandeepnh5 and coderabbitai[bot] authored Dec 31, 2024
1 parent a52c095 commit 1ef2d56
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,20 @@ jobs:
echo "Error: Pull request target branch must be 'develop-postgres'. Please refer PR_GUIDELINES.md"
echo "Error: Close this PR and try again."
exit 1
Validate-Coderabbit:
name: Validate CodeRabbit Approval
runs-on: ubuntu-latest
if: github.actor != 'dependabot[bot]'
needs: [Code-Quality-Checks, Test-Application, Start-App-Without-Docker, Docker-Start-Check]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Validate CodeRabbit.ai Approval
run: |
chmod +x $GITHUB_WORKSPACE/.github/workflows/scripts/validate-coderabbit.sh
$GITHUB_WORKSPACE/.github/workflows/scripts/validate-coderabbit.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_REPOSITORY: ${{ github.repository }}
29 changes: 29 additions & 0 deletions .github/workflows/scripts/validate-coderabbit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

echo "Step 1: Fetching all PR reviews..."

response=$(curl -s -f -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/reviews?per_page=1000") || {
echo "Error: Failed to fetch reviews from GitHub API"
exit 1
}

latest_reviews=$(echo "$response" | jq -c '[.[]] | group_by(.user.login) | map(max_by(.submitted_at))') || {
echo "Error: Failed to process reviews JSON"
exit 1
}

if [ "$latest_reviews" = "null" ] || [ -z "$latest_reviews" ]; then
echo "Error: Invalid reviews data"
exit 1
fi

echo "Step 2: Checking approval status of 'coderabbitai[bot]'..."
approval_state=$(echo "$latest_reviews" | jq -r '[.[] | select(.user.login == "coderabbitai[bot]" and .state == "APPROVED")] | length')

if [[ "$approval_state" =~ ^[0-9]+$ ]] && [[ $approval_state -gt 0 ]]; then
echo "Success: PR approved by CodeRabbit.ai."
else
echo "Error: PR is not approved by CodeRabbit.ai."
exit 1
fi

0 comments on commit 1ef2d56

Please sign in to comment.