fix: make issue auto-close strictly label-based #1758
Workflow file for this run
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: Issue Close Require | ||
| on: | ||
| schedule: | ||
| - cron: '0 0 * * *' | ||
| permissions: | ||
| issues: write | ||
| jobs: | ||
| close-issues: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: close stale issues by label | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const INACTIVE_DAYS = 3; | ||
| const cutoff = Date.now() - INACTIVE_DAYS * 24 * 60 * 60 * 1000; | ||
| const targets = [ | ||
| { | ||
| label: '🤔 Need Reproduce', | ||
| body: `Since the issue was labeled with \`🤔 Need Reproduce\`, but no response in 3 days. This issue will be closed. If you have any questions, you can comment and reply. | ||
| 由于该 issue 被标记为需要重现(🤔 Need Reproduce),却 3 天未收到回应。现关闭 issue,若有任何问题,可评论回复。`, | ||
| }, | ||
| { | ||
| label: 'needs more info', | ||
| body: `Since the issue was labeled with \`needs more info\`, but no response in 3 days. This issue will be closed. If you have any questions, you can comment and reply. | ||
| 由于该 issue 被标记为需要更多信息,却 3 天未收到回应。现关闭 issue,若有任何问题,可评论回复。`, | ||
| }, | ||
| ]; | ||
| const closed = []; | ||
| for (const target of targets) { | ||
| const issues = await github.paginate(github.rest.issues.listForRepo, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| state: 'open', | ||
| labels: target.label, | ||
| 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; | ||
| } | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| body: target.body, | ||
| }); | ||
| await github.rest.issues.update({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| state: 'closed', | ||
| state_reason: 'not_planned', | ||
| }); | ||
| closed.push(`#${issue.number}(${target.label})`); | ||
| } | ||
| } | ||
| core.info(`Closed ${closed.length} issue(s): ${closed.join(', ')}`); | ||