[ci] add GitHub Actions workflow to automatically close inactive issues

This commit is contained in:
dijunkun
2025-10-21 11:29:31 +08:00
parent 0da812e7e9
commit 8e499772f9
3 changed files with 38 additions and 0 deletions

38
.github/workflows/close-issue.yml vendored Normal file
View File

@@ -0,0 +1,38 @@
name: Close Inactive Issues
on:
schedule:
# run every day at midnight
- cron: "0 0 * * *"
jobs:
close_inactive_issues:
runs-on: ubuntu-latest
steps:
- name: Check inactive issues and close them
uses: actions/github-script@v6
with:
script: |
const { data: issues } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
});
const now = new Date().getTime();
const inactivePeriod = 7 * 24 * 60 * 60 * 1000; // 7 days
for (const issue of issues) {
const lastUpdated = new Date(issue.updated_at).getTime();
// if the issue hasn't been updated in the past week, close it
if (now - lastUpdated > inactivePeriod) {
console.log(`Closing inactive issue: ${issue.number}`);
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed',
});
}
}