From 9ca6a6ddd87202b70a79f0267772d5d1dfcf3adb Mon Sep 17 00:00:00 2001 From: Arun Chander Date: Thu, 7 Nov 2024 12:16:31 -0800 Subject: [PATCH 1/2] Update close-stale-needs-more-info.yml --- .../workflows/close-stale-needs-more-info.yml | 41 ++++++++----------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/.github/workflows/close-stale-needs-more-info.yml b/.github/workflows/close-stale-needs-more-info.yml index 09bf494..70ea678 100644 --- a/.github/workflows/close-stale-needs-more-info.yml +++ b/.github/workflows/close-stale-needs-more-info.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 - + - name: Close Stale Issues with Needs More Info Label and Comment uses: actions/github-script@v6 with: @@ -27,18 +27,27 @@ jobs: const staleDays = 14; const closingComment = "This issue has been automatically closed due to inactivity and having the 'needs-more-info' label for more than 14 days. If the issue still persists, please reopen the issue with the requested information."; const currentDate = new Date(); + const staleDaysInMilliseconds = staleDays * 24 * 60 * 60 * 1000; + + // Fetch all open issues with 'needs-more-info' label const issues = await github.paginate(github.rest.issues.listForRepo, { owner: context.repo.owner, repo: context.repo.repo, - labels: labelName + ', -' + excludedLabel, // Excludes issues with 'enhancement' label + labels: labelName, state: 'open', }); for (const issue of issues) { + // Skip if the issue has 'enhancement' label + const labels = issue.labels.map(label => label.name); + if (labels.includes(excludedLabel)) { + continue; + } + let labelAddedDate = null; - // Fetch events to find when the label was added - const events = await github.paginate(github.rest.issues.listEventsForRepo, { + // Fetch events for the issue to find when the label was added + const events = await github.paginate(github.rest.issues.listEvents, { owner: context.repo.owner, repo: context.repo.repo, issue_number: issue.number, @@ -56,28 +65,12 @@ jobs: const issueUpdatedDate = new Date(issue.updated_at); const labelAddedTime = labelAddedDate.getTime(); const issueUpdatedTime = issueUpdatedDate.getTime(); - const diffTime = Math.abs(currentDate - labelAddedDate); + const diffTime = currentDate.getTime() - labelAddedTime; const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); - // Check if the issue was updated after the label was added and if it has been more than 'staleDays' since the label was added - if (issueUpdatedTime > labelAddedTime && diffDays > staleDays) { - // Post a closing comment before closing the issue - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issue.number, - body: closingComment, - }); - - // Close the issue - await github.rest.issues.update({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issue.number, - state: 'closed', - }); - - console.log(`Issue #${issue.number} has been closed with a comment as it has had the '${labelName}' label for more than ${staleDays} days and was updated since the label was applied.`); + // Check if the issue was not updated after the label was added and if it has been more than 'staleDays' since the label was added + if (issueUpdatedTime <= labelAddedTime && diffDays > staleDays) { + console.log(`Issue #${issue.number} can be closed`); } } } From 5236aab2ec90750984cf4e1a4f89f5b58afd6e93 Mon Sep 17 00:00:00 2001 From: Arun Chander Date: Thu, 7 Nov 2024 12:24:12 -0800 Subject: [PATCH 2/2] Update close-stale-needs-more-info.yml --- .../workflows/close-stale-needs-more-info.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/close-stale-needs-more-info.yml b/.github/workflows/close-stale-needs-more-info.yml index 70ea678..941d43e 100644 --- a/.github/workflows/close-stale-needs-more-info.yml +++ b/.github/workflows/close-stale-needs-more-info.yml @@ -70,7 +70,23 @@ jobs: // Check if the issue was not updated after the label was added and if it has been more than 'staleDays' since the label was added if (issueUpdatedTime <= labelAddedTime && diffDays > staleDays) { - console.log(`Issue #${issue.number} can be closed`); + // Post a closing comment before closing the issue + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue.number, + body: closingComment, + }); + + // Close the issue + await github.rest.issues.update({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue.number, + state: 'closed', + }); + + console.log(`Issue #${issue.number} has been closed with a comment as it has had the '${labelName}' label for more than ${staleDays} days and was not updated since the label was applied.`); } } }