-
-
Notifications
You must be signed in to change notification settings - Fork 72
61 lines (51 loc) · 2.5 KB
/
cleanup-inactive-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
name: Remove Inactive Issue Assignees
on:
schedule:
- cron: '0 0 * * 0'
workflow_dispatch:
jobs:
cleanup_assignees:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Identify and notify inactive issues
uses: actions/github-script@v7
with:
script: |
const inactiveDays = 60;
const warningDays = 7;
const issues = await github.paginate(github.rest.issues.listForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open'
});
const now = new Date();
for (const issue of issues) {
const lastUpdate = new Date(issue.updated_at);
const daysInactive = Math.floor((now - lastUpdate) / (1000 * 60 * 60 * 24));
if (daysInactive >= inactiveDays && issue.assignees.length > 0) {
const warningComment = issue.comments.some(comment => comment.body.includes('[PT-BR] Os assignees serão removidos. \n\n[EN] The assignees will be removed.'));
if (!warningComment) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: `:warning: [PT-BR] Esta issue está inativa há ${daysInactive} dias. Os assignees serão removidos em ${warningDays} dias caso não haja atualizações.\n\n:warning: [EN] This issue has been inactive for ${daysInactive} days. The assignees will be removed in ${warningDays} days if there are no updates.`
});
}
} else if (daysInactive >= inactiveDays + warningDays && issue.assignees.length > 0) {
await github.rest.issues.removeAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
assignees: issue.assignees.map(assignee => assignee.login)
});
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: `✅ [PT-BR] Os assignees foram removidos devido à inatividade prolongada da issue.\n\n✅ [EN] The assignees have been removed due to prolonged inactivity of this issue.`
});
}
}