From 27edbefa0c318110f86f183fa9421b445b430cf4 Mon Sep 17 00:00:00 2001 From: "Mr.k" Date: Mon, 1 Apr 2024 14:50:04 +0300 Subject: [PATCH] Update Github Actions Auto Close Issues --- .github/workflows/close-old-issues.yaml | 49 +++++++++++++++---------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/.github/workflows/close-old-issues.yaml b/.github/workflows/close-old-issues.yaml index 1b129a0abc..b911712b9d 100644 --- a/.github/workflows/close-old-issues.yaml +++ b/.github/workflows/close-old-issues.yaml @@ -18,6 +18,7 @@ jobs: script: | const octokit = github; + const labelExcludeName = 'Keep Issue Open' // Get the repository owner and name const { owner, repo } = context.repo; @@ -33,31 +34,39 @@ jobs: state: 'open', })) { const issues = response.data; + const shouldClose = true; // Close issues inactive for more than the inactivity period for (const issue of issues) { - const lastCommentDate = issue.updated_at; - if (new Date(lastCommentDate) < inactivityPeriod) { - try { - // Close the issue - await octokit.rest.issues.update({ - owner, - repo, - issue_number: issue.number, - state: 'closed', - }); - - // Add a comment - await octokit.rest.issues.createComment({ - owner, - repo, - issue_number: issue.number, - body: 'Closed due to inactivity', - }); - } catch (error) { - console.error(`Error updating or commenting on issue #${issue.number}: ${error}`); + for (const label in issue.labels) { + if (label.name == labelExcludeName) { + shouldClose = false; } } + if (shouldClose) { + // const lastCommentDate = issue.updated_at; + // if (new Date(lastCommentDate) < inactivityPeriod) { + try { + // Close the issue + await octokit.rest.issues.update({ + owner, + repo, + issue_number: issue.number, + state: 'closed', + }); + + // Add a comment + await octokit.rest.issues.createComment({ + owner, + repo, + issue_number: issue.number, + body: 'Closed due to inactivity', + }); + } catch (error) { + console.error(`Error updating or commenting on issue #${issue.number}: ${error}`); + } + // } + } } } } catch (error) {