-
-
Notifications
You must be signed in to change notification settings - Fork 27
54 lines (48 loc) · 1.72 KB
/
auto-close-issues.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
name: Auto Close Inactive Issues
on:
schedule:
# Runs at 00:00 UTC every day
- cron: '0 0 * * *'
jobs:
close-inactive-issues:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Close inactive issues
uses: actions/github-script@v6
with:
script: |
const label = "awaiting user"; // Label to filter issues
const inactiveDays = 90; // 3 months
const closingComment = "Closed due to inactivity.";
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: label,
state: 'open',
per_page: 100,
});
const now = new Date();
for (const issue of issues.data) {
const lastUpdated = new Date(issue.updated_at);
const differenceInDays = Math.floor((now - lastUpdated) / (1000 * 3600 * 24));
if (differenceInDays >= inactiveDays) {
// Post a comment before closing the issue
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: closingComment,
});
// Close the issue
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed',
});
}
}
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'