Close stale needs-info / needs-repro issues #41
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: | |
| # Run daily at 09:00 UTC | |
| - 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) { | |
| // Skip PRs (the issues API returns both) | |
| if (issue.pull_request) continue; | |
| // Find when the label was most recently applied (paginate to | |
| // handle issues with many events) | |
| 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; | |
| // Use the most recent label application (don't rely on API ordering) | |
| const labeledAt = new Date(Math.max( | |
| ...labelEvents.map(e => new Date(e.created_at).getTime()) | |
| )); | |
| // Check for any comment from the issue author AFTER the label | |
| // was applied. Paginate to ensure we don't miss replies on | |
| // issues with many comments (the API returns ascending order). | |
| 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; | |
| // Check if enough time has passed since the label was applied | |
| 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()})`); | |
| } | |
| } |