Update Github Actions Auto Close Issues

This commit is contained in:
Mr.k
2024-04-04 02:57:13 +03:00
parent 2ee10b57d4
commit 9d1fae7917

View File

@ -25,6 +25,8 @@ jobs:
const inactivityPeriod = new Date();
inactivityPeriod.setDate(inactivityPeriod.getDate() - 14);
const labelKeepIssue = 'Keep Issue Open';
try {
// Get all open issues with pagination
for await (const response of octokit.paginate.iterator(octokit.rest.issues.listForRepo, {
@ -36,6 +38,28 @@ jobs:
// Close issues inactive for more than the inactivity period
for (const issue of issues) {
const closeIssue = true;
// Get all Labels of issue, and compared each label with the labelKeepIssue const variable
const respondIssueLabels = await octokit.request("GET /repos/{owner}/{repo}/issues/{issue_number}/labels", {
owner: owner,
repo: repo,
issue_number: issue.number
});
const labels = respondIssueLabels.data;
for (let i = 0; i < labels.length; i++) {
const label = labels[i]
if (label.name === labelKeepIssue) {
console.log(`Issue #${issue.number} will not be closed`);
closeIssue = false;
}
}
if (!closeIssue) {
continue; // Skip the next bit of code
}
const lastCommentDate = issue.updated_at;
if (new Date(lastCommentDate) < inactivityPeriod) {
try {