CodeRabbit Review Validation #31
Workflow file for this run
This file contains hidden or 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
name: CodeRabbit Review Validation | |
on: | |
pull_request_review: | |
types: [submitted] | |
jobs: | |
Check-CodeRabbit-Approval: | |
name: Check CodeRabbit Approval | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: read | |
steps: | |
- name: Check CodeRabbit approval | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const { data: reviews } = await github.rest.pulls.listReviews({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.payload.pull_request.number | |
}); | |
const codeRabbitReviews = reviews.filter(review => | |
review.user.login.toLowerCase().includes('coderabbit') || review.user.login.toLowerCase().includes('coderabbitai') | |
); | |
if (codeRabbitReviews.length === 0) { | |
core.setFailed('CodeRabbit has not reviewed this PR.'); | |
return; | |
} | |
codeRabbitReviews.sort((a, b) => new Date(b.submitted_at) - new Date(a.submitted_at)); | |
const latestReview = codeRabbitReviews[0]; | |
if (latestReview.state !== 'APPROVED') { | |
core.setFailed('CodeRabbit approval is required before merging this PR'); | |
} else { | |
console.log('CodeRabbit has approved this PR'); | |
} |