Auto Close Help Wanted Issues #281
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@v6 | |
| - name: Run issue closer | |
| uses: actions/github-script@v8 | |
| 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) { | |
| // 使用 updated_at 作为最后活动时间,涵盖评论、修改、标签变动等 | |
| // 这样可以避免仅检查 issue.comments 导致忽略其他类型活跃(如标签更新、编辑等)的问题 | |
| const lastActivityTime = new Date(issue.updated_at); | |
| const daysPassed = (now - lastActivityTime) / (1000 * 60 * 60 * 24); | |
| // 如果最后活动时间超过 7 天 | |
| if (daysPassed > 7) { | |
| 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", | |
| state_reason: "not_planned", | |
| }); | |
| } | |
| } |