-
-
Notifications
You must be signed in to change notification settings - Fork 17
113 lines (100 loc) · 3.71 KB
/
stale.yml
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
name: stale-bot
on:
schedule:
# run every day at midnight
- cron: "0 0 * * *"
issue_comment:
types: ["created"]
env:
# Name of the label that makes issues subject to the stale bot.
STALE_ENABLE_LABEL: "status: waiting for information"
# Name of the label used to mark issues as stale.
STALE_LABEL: "status: stale"
jobs:
stale-bot:
runs-on: ubuntu-latest
steps:
- name: Mark stale
if: github.event_name == 'schedule'
uses: actions/github-script@v3
with:
github-token: ${{github.token}}
script: |
// Get a list of all open issues labeled as waiting for feedback
const opts = github.issues.listForRepo.endpoint.merge({
...context.repo,
state: 'open',
labels: ['${{ env.STALE_ENABLE_LABEL }}'],
});
const issues = await github.paginate(opts);
// Set this value to whatever makes sense for the repo.
let elapsedDays = 30
let elapsed = elapsedDays * 24 * 60 * 60 * 1000;
let now = new Date().getTime();
for (const issue of issues) {
// If an issue was active in the past 15 days, leave it alone.
if (now - new Date(issue.updated_at).getTime() < elapsed) {
continue;
}
// If we're here, we've been waiting for feedback for more than
// 15 days, mark as stale.
github.issues.addLabels({
...context.repo,
issue_number: issue.number,
labels: ['${{ env.STALE_LABEL }}']
});
}
- name: Mark active
if: github.event_name == 'issue_comment'
uses: actions/github-script@v3
with:
github-token: ${{github.token}}
script: |
// Every time a comment is added to an issue, close it if it contains
// the stale label.
// Load issue's labels.
const opts = github.issues.listLabelsOnIssue.endpoint.merge({
...context.repo,
issue_number: context.issue.number
});
const labels = await github.paginate(opts);
// Search for stale label.
for (const label of labels) {
if (label.name === '${{ env.STALE_LABEL }}') {
await github.issues.removeLabel({
...context.repo,
issue_number: context.issue.number,
name: '${{ env.STALE_LABEL }}'
})
return;
}
}
- name: Close stale
if: github.event_name == 'schedule'
uses: actions/github-script@v3
with:
github-token: ${{github.token}}
script: |
// Load all the stale issues
const opts = github.issues.listForRepo.endpoint.merge({
...context.repo,
state: 'open',
labels: ['${{ env.STALE_LABEL }}'],
});
const issues = await github.paginate(opts);
// Set this value to whatever makes sense for the repo.
let elapsedDays = 15;
let elapsed = elapsedDays * 24 * 60 * 60 * 1000;
let now = new Date().getTime();
for (const issue of issues) {
// If an issue was stale for less than elapsed time, leave it alone.
if (now - new Date(issue.updated_at).getTime() < elapsed) {
continue;
}
// Close the stale issue.
await github.issues.update({
...context.repo,
issue_number: issue.number,
state: 'closed'
});
}