Auto Close Inactive Issues #253
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Auto Close Inactive Issues | |
on: | |
schedule: | |
# Runs at 00:00 UTC every day | |
- 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 label = "awaiting user"; // Label to filter issues | |
const inactiveDays = 90; // 3 months | |
const closingComment = "Closed due to inactivity."; | |
const issues = await github.rest.issues.listForRepo({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
labels: label, | |
state: 'open', | |
per_page: 100, | |
}); | |
const now = new Date(); | |
for (const issue of issues.data) { | |
const lastUpdated = new Date(issue.updated_at); | |
const differenceInDays = Math.floor((now - lastUpdated) / (1000 * 3600 * 24)); | |
if (differenceInDays >= inactiveDays) { | |
// Post a comment before closing the issue | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue.number, | |
body: closingComment, | |
}); | |
// Close the issue | |
await github.rest.issues.update({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue.number, | |
state: 'closed', | |
}); | |
} | |
} | |
env: | |
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' |