-
Notifications
You must be signed in to change notification settings - Fork 824
98 lines (81 loc) · 3.33 KB
/
close_old_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
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
name: Close Older Issues
on:
workflow_dispatch:
jobs:
close-older-issues:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install dependencies
run: npm install --prefix .github octokit
- name: Fetch opened issues
id: fetch_issues
uses: actions/github-script@v4
with:
github-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
script: |
const oneWeekAgo = new Date();
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
let allIssues = [];
let page = 1;
let stopFetching = false;
while (!stopFetching) {
const { data: issues } = await github.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
sort: 'created',
direction: 'asc',
per_page: 100,
page
});
for (const issue of issues) {
if (issue.pull_request === undefined && new Date(issue.created_at) < oneWeekAgo) {
allIssues.push(issue);
} else {
stopFetching = true;
break;
}
}
page++;
}
const olderIssues = allIssues.filter(issue => issue.pull_request === undefined);
core.setOutput('older_issues', olderIssues.map(issue => issue.number).join(','));
- name: Close older issues and comment
if: steps.fetch_issues.outputs.older_issues != ''
uses: actions/github-script@v4
with:
github-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
script: |
const olderIssueNumbers = '${{ steps.fetch_issues.outputs.older_issues }}'.split(',');
for (const issueNumber of olderIssueNumbers) {
// Get the issue details
const { data: issue } = await github.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: parseInt(issueNumber)
});
// Close the older issue
await github.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: parseInt(issueNumber),
state: 'closed'
});
// Comment on the closed issue
await github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: parseInt(issueNumber),
body: `Hello @${issue.user.login}, Time's Uppp!⏰ \n Sorry for closing your issue! \n But it's more than a week since we haven't received anything from your side 😢 . \n Come up with new ideas, create a new issue and make sure you finish it within a week! 🔥 \n All the best! 🚀 \n Happy Hacking! 💗`
});
console.log(`Closed and commented on issue #${issueNumber}.`);
}
- name: Skip if no older issues
if: steps.fetch_issues.outputs.older_issues == ''
run: echo "No older issues found. Skipping..."