Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workflow to automatically close inactive issues #358

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/close-inactive-issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Close Inactive Issues
on:
schedule:
- cron: '0 0 * * *' # Run daily at midnight UTC
workflow_dispatch: # Allow manual triggering

jobs:
close-inactive:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Close inactive issues
uses: actions/github-script@v7
with:
script: |
const daysUntilClose = 14
const warningLabel = 'stale'
const warningMessage = 'This issue has been automatically marked as stale due to inactivity. It will be closed in 3 days if no further activity occurs.'

const now = new Date()
const timeAgo = new Date(now.getTime() - (daysUntilClose * 24 * 60 * 60 * 1000))

const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
sort: 'updated',
direction: 'asc'
})

for (const issue of issues.data) {
const lastUpdated = new Date(issue.updated_at)

if (lastUpdated < timeAgo) {
// Check if issue has warning label
if (issue.labels.find(label => label.name === warningLabel)) {
// Close issue
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed',
state_reason: 'not_planned'
})

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: 'This issue has been automatically closed due to inactivity.'
})
} else {
// Add warning label and comment
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: [warningLabel]
})

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: warningMessage
})
}
}
}