Skip to content

Commit e270977

Browse files
authored
Merge pull request #122 from Asymtode712/ClosePRFeat
added workflow for closing old PRs
2 parents 5fa3477 + 7079b8a commit e270977

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

.github/workflows/close-old-pr.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Close Stale PRs Without Owner Comments
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *" # Runs daily at midnight
6+
7+
jobs:
8+
close_stale_prs:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Check out the repository
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Close Stale PRs Without Owner Comments
18+
run: |
19+
const daysThreshold = 30;
20+
const github = require('@actions/github');
21+
const { Octokit } = require('@octokit/rest');
22+
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
23+
const owner = github.context.repo.owner;
24+
const repo = github.context.repo.repo;
25+
const now = new Date();
26+
const thresholdDate = new Date(now.setDate(now.getDate() - daysThreshold));
27+
28+
async function run() {
29+
const { data: pullRequests } = await octokit.pulls.list({ owner, repo, state: 'open' });
30+
for (const pr of pullRequests) {
31+
const { data: comments } = await octokit.issues.listComments({ owner, repo, issue_number: pr.number });
32+
const ownerComments = comments.filter(comment => comment.user.login === owner);
33+
const recentOwnerComment = ownerComments.find(comment => new Date(comment.created_at) > thresholdDate);
34+
35+
if (!recentOwnerComment) {
36+
await octokit.pulls.update({ owner, repo, pull_number: pr.number, state: 'closed' });
37+
await octokit.issues.createComment({
38+
owner,
39+
repo,
40+
issue_number: pr.number,
41+
body: "This pull request has been closed because there has been no comment from the repository owner for the last 30 days. Please reach out to the maintainers if you have any questions."
42+
});
43+
}
44+
}
45+
}
46+
47+
run().catch(err => {
48+
console.error(err);
49+
process.exit(1);
50+
});
51+
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)