forked from RamakrushnaBiswal/PlayCafe
-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (61 loc) · 2.46 KB
/
auto-close.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
name: Auto Close Issues Based on Priority Levels
on:
schedule:
# Run the job every day at midnight
- cron: '0 0 * * *'
permissions:
issues: write
contents: read
jobs:
close_issues:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v3
- name: Close Issues Based on Labels
uses: actions/github-script@v6
with:
script: |
const now = new Date();
const issues = await github.paginate(github.rest.issues.listForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
state: "open",
});
for (const issue of issues) {
const daysSinceOpened = (now - new Date(issue.created_at)) / (1000 * 60 * 60 * 24);
// Log the issue and the number of days it has been open
console.log(`Checking issue #${issue.number}, opened ${daysSinceOpened.toFixed(1)} days ago.`);
console.log(`Issue #${issue.number} has labels: ${issue.labels.map(label => label.name).join(", ")}`);
if (issue.labels.some(label => label.name === "level 1")) {
if (daysSinceOpened >= 1) {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: "closed"
});
console.log(`Closed level 1 issue #${issue.number}`);
}
} else if (issue.labels.some(label => label.name === "level 2")) {
if (daysSinceOpened >= 2) {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: "closed"
});
console.log(`Closed level 2 issue #${issue.number}`);
}
} else if (issue.labels.some(label => label.name === "level 3")) {
if (daysSinceOpened >= 4) {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: "closed"
});
console.log(`Closed level 3 issue #${issue.number}`);
}
}
}