-
Notifications
You must be signed in to change notification settings - Fork 56
35 lines (32 loc) · 1.37 KB
/
close-inactive-prs.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
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}`);
}
}