created separate files #58
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 Enforcement (Reusable) | |
| on: | |
| workflow_call: | |
| # Direct trigger for this repository | |
| 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 with retry logic | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const maxRetries = 3; | |
| const retryDelay = 20000; // 20 seconds between retries | |
| async function checkApproval(attempt) { | |
| console.log(`Attempt ${attempt}/${maxRetries}: Checking CodeRabbit approval...`); | |
| // List all reviews for the PR | |
| 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 that have a user login containing "coderabbit" (case-insensitive) | |
| // and exclude COMMENTED states. | |
| const codeRabbitReviews = reviews.filter(review => | |
| (review.user.login.toLowerCase().includes('coderabbit') || | |
| review.user.login.toLowerCase().includes('coderabbitai')) && | |
| review.state !== 'COMMENTED' | |
| ); | |
| // Log found reviews for debugging | |
| console.log(`Found ${codeRabbitReviews.length} CodeRabbit reviews (excluding COMMENTED)`); | |
| if (codeRabbitReviews.length > 0) { | |
| // Sort reviews by submitted_at date in descending order | |
| codeRabbitReviews.sort((a, b) => new Date(b.submitted_at) - new Date(a.submitted_at)); | |
| const latestReview = codeRabbitReviews[0]; | |
| console.log(`Latest review state: ${latestReview.state}, submitted at: ${latestReview.submitted_at}`); | |
| if (latestReview.state === 'APPROVED') { | |
| console.log('✅ Success: CodeRabbit has approved this PR.'); | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| // Retry loop | |
| for (let attempt = 1; attempt <= maxRetries; attempt++) { | |
| const approved = await checkApproval(attempt); | |
| if (approved) { | |
| process.exit(0); // Success | |
| } | |
| if (attempt < maxRetries) { | |
| console.log(`⏳ Waiting ${retryDelay/1000} seconds before retry...`); | |
| await new Promise(resolve => setTimeout(resolve, retryDelay)); | |
| } | |
| } | |
| // All retries exhausted | |
| core.setFailed('❌ ERROR: CodeRabbit approval not found after ' + maxRetries + ' attempts. Please ensure CodeRabbit has approved this PR.'); |