Skip to content

Commit 86807ad

Browse files
hi-ogawacodex
andauthored
ci: close maybe automated label pull requests (#10165)
Co-authored-by: Codex <noreply@openai.com>
1 parent 663b99f commit 86807ad

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

.github/workflows/issue-close-require.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Issue Close Require
33
on:
44
schedule:
55
- cron: '0 0 * * *'
6+
workflow_dispatch:
67

78
jobs:
89
close-issues:
@@ -24,3 +25,41 @@ jobs:
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+
}

0 commit comments

Comments
 (0)