-
Notifications
You must be signed in to change notification settings - Fork 28
49 lines (43 loc) · 1.86 KB
/
Copy pathpull-request-review.yml
File metadata and controls
49 lines (43 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
name: Pull Request Review
on:
pull_request_review:
types: [submitted, edited, dismissed]
jobs:
Check-CodeRabbit-Approval:
name: Check CodeRabbit Approval
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 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'
);
// Fail if no CodeRabbit reviews are found
if (codeRabbitReviews.length === 0) {
core.setFailed('ERROR: CodeRabbit has not reviewed this PR.');
return;
}
// 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];
// Fail if the latest review from CodeRabbit is not "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.');
}