Skip to content

Auto Close Inactive Issues #25

Auto Close Inactive Issues

Auto Close Inactive Issues #25

name: Auto Close Inactive Issues
on:
schedule:
# Run the job once a day at midnight
- cron: '0 0 * * *'
jobs:
close_inactive_issues:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Close inactive issues
uses: actions/github-script@v6
with:
script: |
const now = new Date();
const daysToClose = 3; // Close issues after 3 days of inactivity
const issues = await github.paginate(github.issues.listForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
state: "open",
});
for (const issue of issues) {
const lastUpdated = new Date(issue.updated_at);
const daysSinceUpdate = (now - lastUpdated) / (1000 * 60 * 60 * 24);
if (daysSinceUpdate >= daysToClose) {
await github.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: "closed"
});
console.log(`Closed inactive issue #${issue.number}, inactive for ${daysSinceUpdate.toFixed(1)} days.`);
}
}