Skip to content

Commit

Permalink
Update Github Actions Auto Close Issues
Browse files Browse the repository at this point in the history
  • Loading branch information
og-mrk committed Apr 1, 2024
1 parent 2ee10b5 commit d7302b2
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions .github/workflows/close-old-issues.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: Close Inactive Issues

debug: true

on:
schedule:
- cron: '0 0 * * *' # Run daily
Expand All @@ -18,6 +20,7 @@ jobs:
script: |
const octokit = github;
const labelExcludeName = 'Keep Issue Open'
// Get the repository owner and name
const { owner, repo } = context.repo;
Expand All @@ -36,28 +39,34 @@ jobs:
// 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) {
console.log(`Issue won't be closed.`);
return
}
}
// 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) {
Expand Down

0 comments on commit d7302b2

Please sign in to comment.