Auto Close Help Wanted Issues #2
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: Auto Close Help Wanted Issues | |
| on: | |
| schedule: | |
| - cron: "0 3 * * *" # 每天 UTC+0 的 03:00 运行一次 | |
| workflow_dispatch: # 可手动触发测试 | |
| jobs: | |
| close-stale-help-wanted: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| issues: write | |
| contents: read | |
| steps: | |
| - name: Check out repo | |
| uses: actions/checkout@v4 | |
| - name: Run issue closer | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { data: issues } = await github.rest.issues.listForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: "open", | |
| labels: "help wanted", | |
| per_page: 100, | |
| }); | |
| const now = new Date(); | |
| for (const issue of issues) { | |
| const created = new Date(issue.created_at); | |
| const daysPassed = (now - created) / (1000 * 60 * 60 * 24); | |
| // 如果超过 7 天 && 没有评论 | |
| if (daysPassed > 7 && issue.comments === 0) { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issue.number, | |
| body: "由于超过 7 天没有回复,此 issue 自动关闭。" | |
| }); | |
| await github.rest.issues.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issue.number, | |
| state: "closed", | |
| }); | |
| } | |
| } |