File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ name: Issue Close Require
33on :
44 schedule :
55 - cron : ' 0 0 * * *'
6+ workflow_dispatch :
67
78jobs :
89 close-issues :
2425 token : ${{ secrets.GITHUB_TOKEN }}
2526 labels : maybe automated
2627 inactive-day : 3
28+
29+ close-prs :
30+ runs-on : ubuntu-latest
31+ permissions :
32+ issues : read # to query PRs by label via the issues API
33+ pull-requests : write # to close pull requests
34+ steps :
35+ - name : maybe automated PRs
36+ uses : actions/github-script@v8
37+ with :
38+ script : |
39+ const cutoff = new Date(Date.now() - 3 * 24 * 60 * 60 * 1000)
40+
41+ const issues = await github.paginate(github.rest.issues.listForRepo, {
42+ owner: context.repo.owner,
43+ repo: context.repo.repo,
44+ state: 'open',
45+ labels: 'maybe automated',
46+ per_page: 100,
47+ })
48+
49+ const prs = issues.filter(issue =>
50+ issue.pull_request && new Date(issue.updated_at) <= cutoff
51+ )
52+
53+ for (const pr of prs) {
54+ console.log(`Closing PR #${pr.number}, last updated at ${pr.updated_at}`)
55+ await github.rest.pulls.update({
56+ owner: context.repo.owner,
57+ repo: context.repo.repo,
58+ pull_number: pr.number,
59+ state: 'closed',
60+ })
61+ }
62+
63+ if (prs.length === 0) {
64+ console.log('No inactive maybe automated PRs found')
65+ }
You can’t perform that action at this time.
0 commit comments