Label stale pending-contributor issues #236
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: Label stale pending-contributor issues | |
| on: | |
| schedule: | |
| - cron: '0 * * * *' # hourly | |
| workflow_dispatch: | |
| jobs: | |
| check-stale: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| issues: write | |
| steps: | |
| - uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const CONTRIBUTOR = 'pending-contributor'; | |
| const CLOSING = 'closing-soon'; | |
| const STALE_DAYS = 7; | |
| const cutoff = new Date(Date.now() - STALE_DAYS * 24 * 60 * 60 * 1000); | |
| const issues = await github.rest.issues.listForRepo({ | |
| ...context.repo, | |
| state: 'open', | |
| labels: CONTRIBUTOR, | |
| per_page: 100 | |
| }); | |
| for (const issue of issues.data) { | |
| if (issue.pull_request) continue; | |
| const labels = issue.labels.map(l => l.name); | |
| if (labels.includes(CLOSING)) continue; | |
| // Find when pending-contributor was last applied | |
| const { data: events } = await github.rest.issues.listEvents({ | |
| ...context.repo, | |
| issue_number: issue.number, | |
| per_page: 100 | |
| }); | |
| const labelEvent = events | |
| .filter(e => e.event === 'labeled' && e.label?.name === CONTRIBUTOR) | |
| .pop(); | |
| if (!labelEvent) continue; | |
| const labeledAt = new Date(labelEvent.created_at); | |
| if (labeledAt > cutoff) continue; | |
| await github.rest.issues.addLabels({ | |
| ...context.repo, | |
| issue_number: issue.number, | |
| labels: [CLOSING] | |
| }); | |
| console.log(`#${issue.number} — ${CONTRIBUTOR} since ${labeledAt.toISOString()}, added ${CLOSING}`); | |
| } |