|
4 | 4 | schedule: |
5 | 5 | - cron: '0 0 * * *' |
6 | 6 |
|
| 7 | +permissions: |
| 8 | + issues: write |
| 9 | + |
7 | 10 | jobs: |
8 | 11 | close-issues: |
9 | 12 | runs-on: ubuntu-latest |
10 | 13 | steps: |
11 | | - - name: need reproduce |
12 | | - uses: actions-cool/issues-helper@v3 |
| 14 | + - name: close stale issues by label |
| 15 | + uses: actions/github-script@v7 |
13 | 16 | with: |
14 | | - actions: 'close-issues' |
15 | | - labels: '🤔 Need Reproduce' |
16 | | - inactive-day: 3 |
| 17 | + script: | |
| 18 | + const INACTIVE_DAYS = 3; |
| 19 | + const cutoff = Date.now() - INACTIVE_DAYS * 24 * 60 * 60 * 1000; |
17 | 20 |
|
18 | | - - name: needs more info |
19 | | - uses: actions-cool/issues-helper@v3 |
20 | | - with: |
21 | | - actions: 'close-issues' |
22 | | - labels: 'needs more info' |
23 | | - inactive-day: 3 |
24 | | - body: | |
25 | | - 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. |
26 | | - 由于该 issue 被标记为需要更多信息,却 3 天未收到回应。现关闭 issue,若有任何问题,可评论回复。 |
| 21 | + const targets = [ |
| 22 | + { |
| 23 | + label: '🤔 Need Reproduce', |
| 24 | + 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. |
| 25 | +由于该 issue 被标记为需要重现(🤔 Need Reproduce),却 3 天未收到回应。现关闭 issue,若有任何问题,可评论回复。`, |
| 26 | + }, |
| 27 | + { |
| 28 | + label: 'needs more info', |
| 29 | + 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. |
| 30 | +由于该 issue 被标记为需要更多信息,却 3 天未收到回应。现关闭 issue,若有任何问题,可评论回复。`, |
| 31 | + }, |
| 32 | + ]; |
| 33 | + |
| 34 | + const closed = []; |
| 35 | + |
| 36 | + for (const target of targets) { |
| 37 | + const issues = await github.paginate(github.rest.issues.listForRepo, { |
| 38 | + owner: context.repo.owner, |
| 39 | + repo: context.repo.repo, |
| 40 | + state: 'open', |
| 41 | + labels: target.label, |
| 42 | + per_page: 100, |
| 43 | + }); |
| 44 | + |
| 45 | + for (const issue of issues) { |
| 46 | + if (issue.pull_request) { |
| 47 | + continue; |
| 48 | + } |
| 49 | + |
| 50 | + const updatedAt = new Date(issue.updated_at).getTime(); |
| 51 | + if (Number.isNaN(updatedAt) || updatedAt > cutoff) { |
| 52 | + continue; |
| 53 | + } |
| 54 | + |
| 55 | + await github.rest.issues.createComment({ |
| 56 | + owner: context.repo.owner, |
| 57 | + repo: context.repo.repo, |
| 58 | + issue_number: issue.number, |
| 59 | + body: target.body, |
| 60 | + }); |
| 61 | + |
| 62 | + await github.rest.issues.update({ |
| 63 | + owner: context.repo.owner, |
| 64 | + repo: context.repo.repo, |
| 65 | + issue_number: issue.number, |
| 66 | + state: 'closed', |
| 67 | + state_reason: 'not_planned', |
| 68 | + }); |
| 69 | + |
| 70 | + closed.push(`#${issue.number}(${target.label})`); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + core.info(`Closed ${closed.length} issue(s): ${closed.join(', ')}`); |
0 commit comments