Skip to content

Comment on Stale Approved PRs #3

Comment on Stale Approved PRs

Comment on Stale Approved PRs #3

Workflow file for this run

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,
prNumber
});
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
});
}
}
}