Update close-old-issues.yaml

This commit is contained in:
Chris Titus 2024-02-07 17:03:51 -06:00
parent f39deab555
commit 92fa85768f

View File

@ -14,39 +14,43 @@ jobs:
with: with:
github-token: ${{ secrets.GITHUB_TOKEN }} github-token: ${{ secrets.GITHUB_TOKEN }}
script: | script: |
const octokit = context.octokit; const octokit = github.getOctokit();
// Get the repository owner and name // Get the repository owner and name
const { owner, repo } = context.repo; const { owner, repo } = github.context.repo;
// Define the inactivity period (14 days) // Define the inactivity period (14 days)
const inactivityPeriod = new Date(); const inactivityPeriod = new Date();
inactivityPeriod.setDate(inactivityPeriod.getDate() - 14); inactivityPeriod.setDate(inactivityPeriod.getDate() - 14);
// Get all open issues async function run() {
const { data: issues } = await octokit.rest.issues.listForRepo({ // Get all open issues
owner, const issues = await octokit.issues.listForRepo({
repo, owner,
state: 'open', repo,
}); state: 'open',
});
// Close issues inactive for more than the inactivity period // Close issues inactive for more than the inactivity period
for (const issue of issues) { for (const issue of issues.data) {
const lastCommentDate = issue.updated_at; const lastCommentDate = issue.updated_at;
if (new Date(lastCommentDate) < inactivityPeriod) { if (new Date(lastCommentDate) < inactivityPeriod) {
// Close the issue and add a comment // Close the issue and add a comment
await octokit.rest.issues.update({ await octokit.issues.update({
owner, owner,
repo, repo,
issue_number: issue.number, issue_number: issue.number,
state: 'closed', state: 'closed',
}); });
await octokit.rest.issues.createComment({ await octokit.issues.createComment({
owner, owner,
repo, repo,
issue_number: issue.number, issue_number: issue.number,
body: 'Closed due to inactivity', body: 'Closed due to inactivity',
}); });
}
} }
} }
run().catch(error => console.error(error));