-
Notifications
You must be signed in to change notification settings - Fork 33
56 lines (48 loc) · 1.87 KB
/
Copy pathauto-close-help-wanted.yml
File metadata and controls
56 lines (48 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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",
});
}
}