Skip to content

Auto Close Old Issues #41

Auto Close Old Issues

Auto Close Old Issues #41

name: Auto Close Old Issues
on:
schedule:
- cron: '0 0 * * *'
jobs:
close_old_issues:
runs-on: ubuntu-latest
steps:
- name: Check and Close Old Issues
uses: actions/github-script@v5
with:
github-token: ${{ secrets.BOT_TOKEN }}
script: |
const github = require('github');
const octokit = new github.getOctokit("${{secrets.BOT_TOKEN}}");
const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);
const issues = await octokit.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
since: thirtyDaysAgo.toISOString(),
});
for (const issue of issues.data) {
await octokit.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed',
});
}