From 9d1fae7917dfe7e799956ac80a62a60c82a7506c Mon Sep 17 00:00:00 2001 From: "Mr.k" Date: Thu, 4 Apr 2024 02:57:13 +0300 Subject: [PATCH] Update Github Actions Auto Close Issues --- .github/workflows/close-old-issues.yaml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/close-old-issues.yaml b/.github/workflows/close-old-issues.yaml index 1b129a0a..d08742f8 100644 --- a/.github/workflows/close-old-issues.yaml +++ b/.github/workflows/close-old-issues.yaml @@ -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 {