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 3, 2024
1 parent 2ee10b5 commit 3851383
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions .github/workflows/close-old-issues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
const inactivityPeriod = new Date();
inactivityPeriod.setDate(inactivityPeriod.getDate() - 14);
const labelKeepIssue = 'Keep Issue Open';
try {
// Get all open issues with pagination
for await (const response of octokit.paginate.iterator(octokit.rest.issues.listForRepo, {
Expand All @@ -36,28 +37,41 @@ 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}`);
const respondIssueLabels = await octokit.request("GET /repos/{owner}/{repo}/issues/{issue_number}/labels", {
owner: owner,
repo: repo,
issue_number: issue.number
});
const labels = respondIssueLabels.data;
console.log(`${JSON.stringify(labels, null, 4)}`);
for (const label in labels) {
console.log(`${label.name}`);
if (label.name === labelKeepIssue) {
console.log(`Issue #${issue.number} will not be closed`);
}
}
// 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 3851383

Please sign in to comment.