-
Notifications
You must be signed in to change notification settings - Fork 2
47 lines (44 loc) · 1.67 KB
/
review_pr.yaml
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
name: Comment on Stale Approved PRs
on:
workflow_dispatch:
jobs:
comment-on-stale-prs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const awaitingReviewLabel = "awaiting-review";
const prs = await github.rest.pulls.list({
owner,
repo,
});
for (const pr of prs.data) {
const prNumber = pr.number;
console.log(`PR number: ${prNumber}`);
console.log("PR details: ", pr);
const reviews = await github.rest.pulls.listReviews({
owner,
repo,
pr.number
});
const approvedReview = reviews.data.find(review => review.state === "APPROVED");
if (approvedReview) {
const fiveDaysAgo = new Date();
fiveDaysAgo.setDate(fiveDaysAgo.getDate() - 5);
if (new Date(approvedReview.submitted_at) < fiveDaysAgo) {
console.log('approved pr: ',pr.number)
const commentBody = "This PR has been approved for more than 5 days but still has the 'awaiting-review' label. Please review and merge or close the PR.";
await github.rest.issues.createComment({
owner,
repo,
issue_number: pr.number,
body: commentBody
});
}
}
}