Talawa-API Pull Request Review #439
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: Talawa-API Pull Request Review | |
on: | |
pull_request_review: | |
types: [submitted] | |
jobs: | |
Check-CodeRabbit-Approval: | |
name: Check CodeRabbit Approval for Talawa-API | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: read | |
steps: | |
- name: Check CodeRabbit approval using GitHub Script | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
// List all reviews for the current pull request | |
const { data: reviews } = await github.rest.pulls.listReviews({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.payload.pull_request.number | |
}); | |
// Filter reviews by a user whose login includes "coderabbit" (case-insensitive) | |
const codeRabbitReviews = reviews.filter(review => | |
review.user.login.toLowerCase().includes('coderabbit') | |
); | |
// Fail if no CodeRabbit reviews are found | |
if (codeRabbitReviews.length === 0) { | |
core.setFailed('ERROR: CodeRabbit has not reviewed this PR.'); | |
return; | |
} | |
// Sort reviews by submission time in descending order | |
codeRabbitReviews.sort((a, b) => new Date(b.submitted_at) - new Date(a.submitted_at)); | |
const latestReview = codeRabbitReviews[0]; | |
// Check if the latest CodeRabbit review is "APPROVED" | |
if (latestReview.state !== 'APPROVED') { | |
core.setFailed('ERROR: CodeRabbit approval is required before merging this PR.'); | |
} else { | |
console.log('Success: CodeRabbit has approved this PR for Talawa-API.'); | |
} |