-
Notifications
You must be signed in to change notification settings - Fork 8
65 lines (54 loc) · 1.94 KB
/
Copy pathpull-request-review.yml
File metadata and controls
65 lines (54 loc) · 1.94 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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: Wait for review status propagation
run: sleep 30s
shell: bash
- name: Check CodeRabbit approval
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo;
const pull_number = context.payload.pull_request.number;
// Fetch all PR reviews
const { data: reviews } = await github.rest.pulls.listReviews({
owner,
repo,
pull_number
});
// Identify CodeRabbit reviews (case-insensitive) and ignore COMMENTED
const codeRabbitReviews = reviews.filter(review =>
review.user?.login &&
(
review.user.login.toLowerCase().includes('coderabbit') ||
review.user.login.toLowerCase().includes('coderabbitai')
) &&
review.state !== 'COMMENTED'
);
if (codeRabbitReviews.length === 0) {
core.setFailed('ERROR: CodeRabbit has not reviewed this PR.');
return;
}
// Sort newest → oldest
codeRabbitReviews.sort(
(a, b) => new Date(b.submitted_at) - new Date(a.submitted_at)
);
const latestReview = codeRabbitReviews[0];
if (latestReview.state !== 'APPROVED') {
core.setFailed(
'ERROR: CodeRabbit approval is required before merging this PR.'
);
} else {
console.log('Success: CodeRabbit has approved this PR.');
}