Skip to content

Commit 4f3925d

Browse files
authored
ci: close likely-no issues automatically (coder#10569)
1 parent 4316c1c commit 4f3925d

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

.github/workflows/stale.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,52 @@ jobs:
3030
operations-per-run: 60
3131
# Start with the oldest issues, always.
3232
ascending: true
33+
- name: "Close old issues labeled likely-no"
34+
uses: actions/github-script@v5
35+
with:
36+
github-token: ${{ secrets.GITHUB_TOKEN }}
37+
script: |
38+
const thirtyDaysAgo = new Date(new Date().setDate(new Date().getDate() - 30));
39+
console.log(`Looking for issues labeled with 'likely-no' more than 30 days ago, which is after ${thirtyDaysAgo.toISOString()}`);
40+
41+
const issues = await github.rest.issues.listForRepo({
42+
owner: context.repo.owner,
43+
repo: context.repo.repo,
44+
labels: 'likely-no',
45+
state: 'open',
46+
});
47+
48+
console.log(`Found ${issues.data.length} open issues labeled with 'likely-no'`);
49+
50+
for (const issue of issues.data) {
51+
console.log(`Checking issue #${issue.number} created at ${issue.created_at}`);
52+
53+
const timeline = await github.rest.issues.listEventsForTimeline({
54+
owner: context.repo.owner,
55+
repo: context.repo.repo,
56+
issue_number: issue.number,
57+
});
58+
59+
const labelEvent = timeline.data.find(event => event.event === 'labeled' && event.label.name === 'likely-no');
60+
61+
if (labelEvent) {
62+
console.log(`Issue #${issue.number} was labeled with 'likely-no' at ${labelEvent.created_at}`);
63+
64+
if (new Date(labelEvent.created_at) < thirtyDaysAgo) {
65+
console.log(`Issue #${issue.number} is older than 30 days with 'likely-no' label, closing issue.`);
66+
await github.rest.issues.update({
67+
owner: context.repo.owner,
68+
repo: context.repo.repo,
69+
issue_number: issue.number,
70+
state: 'closed',
71+
state_reason: 'not planned'
72+
});
73+
}
74+
} else {
75+
console.log(`Issue #${issue.number} does not have a 'likely-no' label event in its timeline.`);
76+
}
77+
}
78+
3379
branches:
3480
runs-on: ubuntu-latest
3581
steps:

0 commit comments

Comments
 (0)