Close stale needs-info / needs-repro issues #23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Close stale needs-info / needs-repro issues | |
| on: | |
| schedule: | |
| - cron: '37 9 * * *' | |
| workflow_dispatch: | |
| jobs: | |
| close-needs-info: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| issues: write | |
| steps: | |
| - name: Close stale needs-info issues (14 days) | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8 | |
| with: | |
| script: | | |
| const labels = ['status/needs-info', 'status/needs-repro']; | |
| const days = 14; | |
| const cutoff = new Date(Date.now() - days * 24 * 60 * 60 * 1000); | |
| for (const label of labels) { | |
| const issues = await github.paginate(github.rest.issues.listForRepo, { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| labels: label, | |
| per_page: 100, | |
| }); | |
| for (const issue of issues) { | |
| if (issue.pull_request) continue; | |
| const events = await github.paginate(github.rest.issues.listEvents, { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issue.number, | |
| per_page: 100, | |
| }); | |
| const labelEvents = events | |
| .filter(e => e.event === 'labeled' && e.label?.name === label); | |
| if (labelEvents.length === 0) continue; | |
| const labeledAt = new Date(Math.max( | |
| ...labelEvents.map(e => new Date(e.created_at).getTime()) | |
| )); | |
| const comments = await github.paginate(github.rest.issues.listComments, { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issue.number, | |
| since: labeledAt.toISOString(), | |
| per_page: 100, | |
| }); | |
| const authorReplied = comments.some(c => | |
| c.user?.login === issue.user?.login && | |
| new Date(c.created_at) > labeledAt | |
| ); | |
| if (authorReplied) continue; | |
| if (labeledAt > cutoff) continue; | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issue.number, | |
| body: `Closing — this was marked \`${label}\` 14 days ago with no response.\n\nIf this is still relevant, please reply with the requested details and we'll reopen.`, | |
| }); | |
| await github.rest.issues.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issue.number, | |
| state: 'closed', | |
| state_reason: 'not_planned', | |
| }); | |
| console.log(`Closed #${issue.number} (${label}, labeled ${labeledAt.toISOString()})`); | |
| } | |
| } |