-
Notifications
You must be signed in to change notification settings - Fork 306
62 lines (53 loc) · 2 KB
/
close-abandoned-issues.yaml
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
name: Close Abandoned Issues
on:
schedule:
- cron: "0 */24 * * *"
jobs:
close-labeler:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Close the abandoned issue
uses: actions/github-script@v6
env:
daysInterval: ${{ vars.MONITORING_INTERVAL_DAYS }}
with:
script: |
const { owner, repo } = context.repo;
const abandonedLabel = "Status: Abandoned";
const parsedDays = parseFloat("${{ env.daysInterval }}");
const timeThreshold = parsedDays * 24 * 60 * 60 * 1000;
const issuesResponse = await github.rest.issues.listForRepo({
owner,
repo,
labels: abandonedLabel,
state: "open",
});
for (const issue of issuesResponse.data) {
const updatedAt = new Date(issue.updated_at).getTime();
const currentTime = new Date().getTime();
const updateMessage = `Greetings,
It's been more than ${parsedDays} days since this issue was identified as abandoned.
We have closed this issue due to inactivity, please feel free to re-open it if you have more information to share.`;
if (currentTime - updatedAt > timeThreshold) {
await github.rest.issues.removeLabel({
owner,
repo,
issue_number: issue.number,
name: abandonedLabel,
});
await github.rest.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: updateMessage,
});
await github.rest.issues.update({
owner,
repo,
issue_number: issue.number,
state: "closed",
});
}
}