Skip to content

Commit 5f33c43

Browse files
authored
Merge pull request #360 from Asymtode712/patch-6
Update close-old-pr.yml
2 parents 48aa451 + 8c24fa4 commit 5f33c43

File tree

1 file changed

+26
-45
lines changed

1 file changed

+26
-45
lines changed

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

Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,34 @@
1-
name: Close Stale PRs Without Owner Comments
1+
name: Close Stale PRs
22

33
on:
44
schedule:
5-
- cron: "0 0 * * *" # Runs daily at midnight
5+
- cron: '0 0 * * *' # Runs daily at midnight
6+
pull_request:
7+
types:
8+
- opened
9+
- reopened
10+
- synchronize
11+
12+
permissions:
13+
pull-requests: write
14+
issues: write
615

716
jobs:
817
close_stale_prs:
918
runs-on: ubuntu-latest
10-
19+
permissions:
20+
pull-requests: write
21+
1122
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 }}
23+
- uses: actions/stale@v7
24+
with:
25+
repo-token: ${{ secrets.GITHUB_TOKEN }}
26+
stale-pr-message: 'This PR has been automatically closed due to inactivity from the owner for 30 days.'
27+
days-before-pr-stale: 30
28+
days-before-pr-close: 0
29+
exempt-pr-author: false
30+
exempt-pr-labels: ''
31+
only-labels: ''
32+
operations-per-run: 30
33+
remove-stale-when-updated: true
34+
debug-only: false

0 commit comments

Comments
 (0)