Skip to content

Auto close inactive issues with schedule #22

Auto close inactive issues with schedule

Auto close inactive issues with schedule #22

# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Close issue
run-name: Auto close inactive issues with schedule
on:
schedule:
- cron: "0 0 */7 * *"
jobs:
close-issues:
permissions:
issues: write
runs-on: ubuntu-latest
steps:
- name: 😞 Check labels and close inactive issues
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const inactiveDays = 7
const cutoff = Date.now() - inactiveDays * 24 * 60 * 60 * 1000
const labels = ['status|waiting-reproduction', 'status|waiting-feedback']
const owner = context.repo.owner
const repo = context.repo.repo
const issues = await github.paginate(github.rest.issues.listForRepo, {
owner,
repo,
state: 'open',
labels: labels.join(','),
sort: 'updated',
direction: 'asc',
per_page: 100
})
for (const issue of issues) {
if (issue.pull_request)
continue
const updatedAt = new Date(issue.updated_at).getTime()
if (Number.isNaN(updatedAt) || updatedAt > cutoff)
continue
const body = [
'Hi, this issue has been closed because it has been inactive for more than 7 days.',
'If you think it should still be open, please reply here.'
].join('\n')
await github.rest.issues.createComment({
owner,
repo,
issue_number: issue.number,
body
})
await github.rest.issues.update({
owner,
repo,
issue_number: issue.number,
state: 'closed'
})
}