Skip to content

Commit

Permalink
Update close-old-issues.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisTitusTech committed Feb 20, 2024
1 parent e745d79 commit 31c6622
Showing 1 changed file with 37 additions and 24 deletions.
61 changes: 37 additions & 24 deletions .github/workflows/close-old-issues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
jobs:
close-issues:
runs-on: ubuntu-latest
permissions:
issues: write # Ensure necessary permissions for issues

steps:
- name: Close inactive issues
Expand All @@ -23,30 +25,41 @@ jobs:
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',
});
try {
// Get all open issues with pagination
for await (const response of octokit.paginate.iterator(octokit.rest.issues.listForRepo, {
owner,
repo,
state: 'open',
})) {
const issues = response.data;
// 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) {
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',
});
await octokit.rest.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: 'Closed due to inactivity',
});
// 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) {
console.error(`Error fetching issues: ${error}`);
}

0 comments on commit 31c6622

Please sign in to comment.