-
Notifications
You must be signed in to change notification settings - Fork 60
52 lines (44 loc) · 1.77 KB
/
pr_review_check.yml
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
name: PR Review Check
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
jobs:
check-review:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Check for PR review
uses: actions/github-script@v6
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.issue.number
});
const approvedReviews = reviews.filter(review => review.state === 'APPROVED');
if (approvedReviews.length === 0) {
core.setFailed('At least one approved review is required before merging.');
} else {
console.log(`${approvedReviews.length} approved reviews found.`);
}
- name: Retry on failure
if: failure()
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
console.log('Retrying check for approved reviews...');
const { data: reviews } = await github.rest.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const approvedReviews = reviews.filter(review => review.state === 'APPROVED');
if (approvedReviews.length === 0) {
core.setFailed('PR cannot be merged as no approved reviews are found.');
} else {
console.log(`${approvedReviews.length} approved reviews found on retry.`);
}