forked from zilliztech/VectorDBBench
-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (76 loc) · 3.37 KB
/
close_stale_issues.yml
File metadata and controls
92 lines (76 loc) · 3.37 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: Close Stale Issues
on:
schedule:
# Run every day at 02:00 UTC
- cron: '0 2 * * *'
workflow_dispatch: {}
jobs:
close-stale-issues:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- uses: actions/github-script@v7
with:
script: |
const STALE_DAYS = 30;
const EXEMPT_LABEL = 'keep-open';
// MEMBER = org member, OWNER = org owner
const TEAM_ASSOCIATIONS = ['MEMBER', 'OWNER'];
const now = new Date();
const staleThreshold = new Date(now.getTime() - STALE_DAYS * 24 * 60 * 60 * 1000);
console.log(`Looking for issues with last team reply before ${staleThreshold.toISOString()}`);
const issues = await github.paginate(github.rest.issues.listForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
sort: 'updated',
direction: 'asc',
per_page: 100,
});
let closedCount = 0;
for (const issue of issues) {
// Skip pull requests (GitHub API returns PRs as issues too)
if (issue.pull_request) continue;
// Skip issues with the exempt label
if (issue.labels.some(l => l.name === EXEMPT_LABEL)) {
console.log(`Skipping #${issue.number} (has '${EXEMPT_LABEL}' label)`);
continue;
}
// Get all comments for this issue
const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
per_page: 100,
});
// Skip issues with no comments
if (comments.length === 0) continue;
const lastComment = comments[comments.length - 1];
const lastCommentDate = new Date(lastComment.created_at);
const isFromTeam = TEAM_ASSOCIATIONS.includes(lastComment.author_association);
const isStale = lastCommentDate < staleThreshold;
if (isFromTeam && isStale) {
console.log(`Closing #${issue.number}: last team reply on ${lastCommentDate.toISOString()} by @${lastComment.user.login}`);
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: [
'This issue has been automatically closed because it has not received a response for over 30 days since the last reply from a team member.',
'',
'If this issue is still relevant, feel free to reopen it or create a new issue.',
'You can also add the `keep-open` label to prevent automatic closure.',
].join('\n'),
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed',
state_reason: 'not_planned',
});
closedCount++;
}
}
console.log(`Done. Closed ${closedCount} stale issue(s).`);