From 92fa85768f4cc3dd324778aa54daa92062c16d1c Mon Sep 17 00:00:00 2001 From: Chris Titus Date: Wed, 7 Feb 2024 17:03:51 -0600 Subject: [PATCH] Update close-old-issues.yaml --- .github/workflows/close-old-issues.yaml | 56 +++++++++++++------------ 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/.github/workflows/close-old-issues.yaml b/.github/workflows/close-old-issues.yaml index 7fca4ccc..5b472bc0 100644 --- a/.github/workflows/close-old-issues.yaml +++ b/.github/workflows/close-old-issues.yaml @@ -14,39 +14,43 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const octokit = context.octokit; + const octokit = github.getOctokit(); // Get the repository owner and name - const { owner, repo } = context.repo; + const { owner, repo } = github.context.repo; // Define the inactivity period (14 days) const inactivityPeriod = new Date(); inactivityPeriod.setDate(inactivityPeriod.getDate() - 14); - // Get all open issues - const { data: issues } = await octokit.rest.issues.listForRepo({ - owner, - repo, - state: 'open', - }); + async function run() { + // Get all open issues + const issues = await octokit.issues.listForRepo({ + owner, + repo, + state: 'open', + }); - // Close issues inactive for more than the inactivity period - for (const issue of issues) { - const lastCommentDate = issue.updated_at; - if (new Date(lastCommentDate) < inactivityPeriod) { - // Close the issue and add a comment - await octokit.rest.issues.update({ - owner, - repo, - issue_number: issue.number, - state: 'closed', - }); + // Close issues inactive for more than the inactivity period + for (const issue of issues.data) { + const lastCommentDate = issue.updated_at; + if (new Date(lastCommentDate) < inactivityPeriod) { + // Close the issue and add a comment + await octokit.issues.update({ + owner, + repo, + issue_number: issue.number, + state: 'closed', + }); - await octokit.rest.issues.createComment({ - owner, - repo, - issue_number: issue.number, - body: 'Closed due to inactivity', - }); + await octokit.issues.createComment({ + owner, + repo, + issue_number: issue.number, + body: 'Closed due to inactivity', + }); + } } - } \ No newline at end of file + } + + run().catch(error => console.error(error));