使用 Stale Action 管理 Github Issue
5 分钟阅读

使用 Stale Action 管理 Github Issue

使用 Stale Action 自动关闭不活跃的 Github Issue

背景

Agenda 上线快两年了,Open 和 Close 的 issue 都超过了 100。大部分 issue 是功能请求,有些已经在 Agenda3 实现了,有些干脆不打算做了。

找了个时间一一回复了 issue,但是由于一些 issue 时间比较久远了,可能短时间内无法得到回复,所以打算引入 Stale Action,自动关闭不活跃的 issue。

引入 Stale Action

创建 .github/workflows/stale-issues.yml 文件,并配置如下:

yaml
1name: Stale Issues Policy 2on: 3 schedule: 4 - cron: "0 0 * * *" # Run at 00:00 UTC every day 5 workflow_dispatch: 6 7permissions: 8 contents: read 9 issues: write # for actions/stale to close stale issues 10 11jobs: 12 stale: 13 runs-on: ubuntu-latest 14 steps:

标记并关闭不活跃的 issue

yaml
1jobs: 2 stale: 3 runs-on: ubuntu-latest 4 steps: 5 - name: "🧹 Mark & close stale issues" 6 uses: actions/[email protected] 7 with: 8 repo-token: ${{ secrets.GITHUB_TOKEN }} 9 stale-issue-label: "automatic-stale" 10 close-issue-label: "automatic-closing" 11 exempt-issue-labels: "enhancement, feature-request, upstream, hold" 12 stale-issue-message: | 13 Hi There! 👋 14 15 This issue has been marked as stale due to inactivity for 60 days. 16 17 We would like to inquire if you still have the same problem or if it has been resolved. 18 19 If you need further assistance, please feel free to respond to this comment within the next 7 days. Otherwise, the issue will be automatically closed. 20 21 We appreciate your understanding and would like to express our gratitude for your contribution to Agenda. Thank you for your support. 🙏
参数描述
stale-issue-label标记不活跃的 issue 使用的标签名
close-issue-label关闭不活跃的 issue 使用的标签名
exempt-issue-labels排除使用此标签的 issue
stale-issue-message标记时使用的消息

stale action 默认的超时时间是 60 天,也就是 60 天内没有回复的 issue 就会被标记为不活跃。标记后如果在 7 天内没有回复,issue 就会被关闭。

这里我们设置了 exempt-issue-labels,是因为像一些需求类的 issue 以及某些 bug 暂时没有头绪没回复,这些 issue 不应该自动关闭。

让部分 issue 加速过期

yaml
1- name: "🧹 Close stale awaiting response issues" 2 uses: actions/[email protected] 3 with: 4 repo-token: ${{ secrets.GITHUB_TOKEN }} 5 days-before-issue-stale: 40 6 stale-issue-label: "automatic-stale" 7 close-issue-label: "automatic-closing" 8 only-labels: "awaiting response" 9 stale-issue-message: | 10 Hi There! 👋 11 12 This issue has been marked as stale due to inactivity for 40 days. 13 14 We would like to inquire if you still have the same problem or if it has been resolved. 15 16 If you need further assistance, please feel free to respond to this comment within the next 7 days. Otherwise, the issue will be automatically closed. 17 18 We appreciate your understanding and would like to express our gratitude for your contribution to Agenda. Thank you for your support. 🙏
参数描述
days-before-issue-stale设置过期时间
only-labels只对含有此处指定的标签的 issue 生效

对于部分 issue,我们不想等待 60 天那么久,可以打上特定标签,然后设置一个更短的过期时间。

完整代码

yaml
1name: Stale Issues Policy 2on: 3 schedule: 4 - cron: "0 0 * * *" # Run at 00:00 UTC every day 5 workflow_dispatch: 6 7permissions: 8 contents: read 9 issues: write # for actions/stale to close stale issues 10 11jobs: 12 stale: 13 runs-on: ubuntu-latest 14 steps: 15 - name: "🧹 Mark & close stale issues" 16 uses: actions/[email protected] 17 with: 18 repo-token: ${{ secrets.GITHUB_TOKEN }} 19 stale-issue-label: "automatic-stale" 20 close-issue-label: "automatic-closing" 21 exempt-issue-labels: "enhancement, feature-request, upstream, hold" 22 stale-issue-message: | 23 Hi There! 👋 24 25 This issue has been marked as stale due to inactivity for 60 days. 26 27 We would like to inquire if you still have the same problem or if it has been resolved. 28 29 If you need further assistance, please feel free to respond to this comment within the next 7 days. Otherwise, the issue will be automatically closed. 30 31 We appreciate your understanding and would like to express our gratitude for your contribution to Agenda. Thank you for your support. 🙏 32 33 - name: "🧹 Close stale awaiting response issues" 34 uses: actions/[email protected] 35 with: 36 repo-token: ${{ secrets.GITHUB_TOKEN }} 37 days-before-issue-stale: 40 38 stale-issue-label: "automatic-stale" 39 close-issue-label: "automatic-closing" 40 only-labels: "awaiting response" 41 stale-issue-message: | 42 Hi There! 👋 43 44 This issue has been marked as stale due to inactivity for 40 days. 45 46 We would like to inquire if you still have the same problem or if it has been resolved. 47 48 If you need further assistance, please feel free to respond to this comment within the next 7 days. Otherwise, the issue will be automatically closed. 49 50 We appreciate your understanding and would like to express our gratitude for your contribution to Agenda. Thank you for your support. 🙏