Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Code Rabbit Approval Check to pull-request.yml Workflow #3008

Merged
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
02049cc
Update coderabbit approval
mandeepnh5 Dec 28, 2024
b5d8c8e
Update .github/workflows/pull-request.yml
mandeepnh5 Dec 28, 2024
dbe1183
Merge branch 'develop-postgres' into coderabbit-workflow
mandeepnh5 Dec 28, 2024
ac05f7e
Fix some issues
mandeepnh5 Dec 28, 2024
54914b8
Update code for testing in pr
mandeepnh5 Dec 28, 2024
6579d01
Fix issues related to if-fi
mandeepnh5 Dec 28, 2024
d027c8c
Merge branch 'develop-postgres' into coderabbit-workflow
mandeepnh5 Dec 29, 2024
47b1c9c
Update pull-request.yml
mandeepnh5 Dec 29, 2024
df0ee04
Update .github/workflows/pull-request.yml
mandeepnh5 Dec 29, 2024
c5e1dd5
Merge branch 'develop-postgres' into coderabbit-workflow
mandeepnh5 Dec 29, 2024
9b88bf0
intentionally failing coderabbit
mandeepnh5 Dec 29, 2024
30d1e41
Fix some issues
mandeepnh5 Dec 29, 2024
b6f6efa
Update .github/workflows/pull-request.yml
mandeepnh5 Dec 29, 2024
c59204d
Update pull-request.yml
mandeepnh5 Dec 29, 2024
4b5ffce
Merge branch 'develop-postgres' into coderabbit-workflow
mandeepnh5 Dec 29, 2024
aa3afd6
Update pull-request.yml
mandeepnh5 Dec 29, 2024
4c1efc5
Update pull-request.yml
mandeepnh5 Dec 29, 2024
ac8c24a
Fix issues and intentional coderabbit fail
mandeepnh5 Dec 29, 2024
32c8fae
Intentional code rabbit fail
mandeepnh5 Dec 29, 2024
1a93441
Update coderabbit check in scripts folder
mandeepnh5 Dec 29, 2024
64f46a9
Update .github/workflows/scripts/validate-coderabbit.yml
mandeepnh5 Dec 29, 2024
12bdd8e
Update .github/workflows/scripts/validate-coderabbit.yml
mandeepnh5 Dec 29, 2024
5b4115d
Update needs for coderabbit
mandeepnh5 Dec 29, 2024
ea995d1
Update scripts folder issue
mandeepnh5 Dec 29, 2024
f421a47
Fix issue in yml file
mandeepnh5 Dec 29, 2024
1097ba3
Update .github/workflows/scripts/validate-coderabbit.sh
mandeepnh5 Dec 29, 2024
6b3de90
Update coderabbit suggestions
mandeepnh5 Dec 29, 2024
d16ea25
Fix some issues
mandeepnh5 Dec 29, 2024
b164507
Merge branch 'develop-postgres' into coderabbit-workflow
mandeepnh5 Dec 29, 2024
e2b579b
Fix some path issues
mandeepnh5 Dec 29, 2024
0dadb1a
Fix some script issues
mandeepnh5 Dec 29, 2024
d9ef72e
Update .github/workflows/pull-request.yml
mandeepnh5 Dec 29, 2024
8375a9d
Fix some issues
mandeepnh5 Dec 29, 2024
c2acb0e
Update .github/workflows/scripts/validate-coderabbit.sh
mandeepnh5 Dec 29, 2024
935e8a5
Update .github/workflows/scripts/validate-coderabbit.sh
mandeepnh5 Dec 29, 2024
e8574d2
Fix github pagination
mandeepnh5 Dec 29, 2024
188e10f
Update .github/workflows/scripts/validate-coderabbit.sh
mandeepnh5 Dec 29, 2024
b6360b8
Update .github/workflows/scripts/validate-coderabbit.sh
mandeepnh5 Dec 29, 2024
44d9953
Update .github/workflows/scripts/validate-coderabbit.sh
mandeepnh5 Dec 29, 2024
6868f3f
Merge branch 'develop-postgres' into coderabbit-workflow
mandeepnh5 Dec 29, 2024
2504d44
Fix github pagination
mandeepnh5 Dec 31, 2024
62822f6
Fix some issues
mandeepnh5 Dec 31, 2024
9f3896a
Removed debug statements
mandeepnh5 Dec 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
##############################################################################

Check warning on line 1 in .github/workflows/pull-request.yml

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

File ignored by default.
##############################################################################
#
# NOTE!
Expand Down Expand Up @@ -462,3 +462,20 @@
run: |
echo "Error: Pull request target branch must be 'develop-postgres'. Please refer PR_GUIDELINES.md"
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 }}
mandeepnh5 marked this conversation as resolved.
Show resolved Hide resolved
70 changes: 70 additions & 0 deletions .github/workflows/scripts/validate-coderabbit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

Check warning on line 1 in .github/workflows/scripts/validate-coderabbit.sh

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

File ignored by default.
echo "Step 1: Checking CodeRabbit.ai approval..."

if [ -z "${GITHUB_TOKEN:-}" ]; then
echo "Error: GITHUB_TOKEN environment variable is not set"
exit 1
fi
mandeepnh5 marked this conversation as resolved.
Show resolved Hide resolved

if [ -z "${PR_NUMBER:-}" ]; then
echo "Error: PR_NUMBER environment variable is not set"
exit 1
fi

if [ -z "${GITHUB_REPOSITORY:-}" ]; then
echo "Error: GITHUB_REPOSITORY environment variable is not set"
exit 1
fi

echo "Fetching PR reviews from GitHub API..."
rate_limit=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/rate_limit")
remaining=$(echo "$rate_limit" | jq '.rate.remaining')

if [ "$remaining" -lt 1 ]; then
echo "Error: GitHub API rate limit exceeded. Please try again later."
exit 1
fi

reviews=$(curl -s -f -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/reviews")

if [ $? -ne 0 ]; then
echo "Error: Failed to fetch PR reviews."
exit 1
fi

echo "Checking if the response is valid JSON..."
if ! echo "$reviews" | jq . >/dev/null 2>&1; then
echo "Error: Invalid JSON response from GitHub API."
echo "Response received: $reviews"
exit 1
fi

echo "Parsing the latest review by each user..."
if [ "$(echo "$reviews" | jq '. | length')" -eq 0 ]; then
echo "Error: No reviews found for this PR"
exit 1
fi

if [ "${JQ_DEBUG:-}" = "1" ]; then
echo "Debug: Running jq command on reviews:"
echo "$reviews" | jq '.'
fi

latest_reviews=$(echo "$reviews" | jq -c '[.[]] | group_by(.user.login) | map(max_by(.submitted_at))')

echo "Printing all latest review user logins and states:"
echo "$latest_reviews" | jq -r '.[] | "User: \(.user.login), State: \(.state)"'
palisadoes marked this conversation as resolved.
Show resolved Hide resolved

echo "Checking approval status of 'coderabbitai[bot]'..."
approval_state=$(echo "$latest_reviews" | jq -r '[.[] | select(.user.login == "coderabbitai[bot]" and .state == "APPROVED")] | length')
palisadoes marked this conversation as resolved.
Show resolved Hide resolved

echo "Approval count for CodeRabbit.ai: $approval_state"

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
Loading