From 41811a5d888b4b705371d3c6c7be1f26695bff3f Mon Sep 17 00:00:00 2001 From: "Mr.k" Date: Thu, 4 Apr 2024 01:39:38 +0300 Subject: [PATCH] Update Github Actions Auto Close Issues --- .github/workflows/close-old-issues.yaml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.github/workflows/close-old-issues.yaml b/.github/workflows/close-old-issues.yaml index 1b129a0abc..7425b16d95 100644 --- a/.github/workflows/close-old-issues.yaml +++ b/.github/workflows/close-old-issues.yaml @@ -25,6 +25,7 @@ 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 +37,28 @@ jobs: // Close issues inactive for more than the inactivity period for (const issue of issues) { + const respondIssueLabels = await octokit.request("GET /repos/{owner}/{repo}/issues/{issue_number}/labels", { + owner: owner, + repo: repo, + issue_number: issue.number + }); + const closeIssue = true; + + // Get all Labels of issue, and compared each label with the labelKeepIssue const variable + const labels = respondIssueLabels.data; + console.log(`${JSON.stringify(labels, null, 4)}`); + for (let i = 0; i < labels.length; i++) { + //console.log(`${JSON.stringify(labels[i], null, 4)}`); + const label = labels[i] + if (label.name === labelKeepIssue) { + console.log(`Issue #${issue.number} will not be closed`); + closeIssue = false; + } + } + if (!closeIssue) { + continue; + } + console.log('Hello'); const lastCommentDate = issue.updated_at; if (new Date(lastCommentDate) < inactivityPeriod) { try {