-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a workflow to warn and close inactive pull requests
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: "Close inactive PRs" | ||
|
||
on: | ||
schedule: | ||
- cron: "0 0 * * *" | ||
|
||
jobs: | ||
close-inactive-prs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Close inactive PRs | ||
uses: actions/github-script@v5 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
const owner = context.repo.owner; | ||
const repo = context.repo.repo; | ||
const prs = await github.rest.pulls.list({ owner, repo, state: 'open' }); | ||
const thirtyDaysAgo = new Date(); | ||
thirtyDaysAgo.setMinutes(thirtyDaysAgo.getDate() - 28); | ||
const oneWeekAgo = new Date(); | ||
oneWeekAgo.setMinutes(oneWeekAgo.getDate() - 7); | ||
for (const pr of prs.data) { | ||
const updatedAt = new Date(pr.updated_at); | ||
const number = pr.number; | ||
if (updatedAt < thirtyDaysAgo) { | ||
await github.rest.pulls.update({ owner, repo, pull_number: number, state: 'closed' }); | ||
console.log(`Closed PR #${number}`); | ||
} else if (updatedAt < oneWeekAgo) { | ||
const message = 'This PR will be closed in one week due to inactivity. Please update the PR if necessary.'; | ||
await github.rest.issues.createComment({ owner, repo, issue_number: number, body: message }); | ||
console.log(`Posted warning on PR #${number}`); | ||
} | ||
} |