diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 4708e39869..aeb134c0f6 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -462,3 +462,20 @@ jobs: 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 }} \ No newline at end of file diff --git a/.github/workflows/scripts/validate-coderabbit.sh b/.github/workflows/scripts/validate-coderabbit.sh new file mode 100644 index 0000000000..bba002c24b --- /dev/null +++ b/.github/workflows/scripts/validate-coderabbit.sh @@ -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 \ No newline at end of file