Skip to content
Merged
Show file tree
Hide file tree
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
92 changes: 92 additions & 0 deletions .github/workflows/close_stale_issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Close Stale Issues

on:
schedule:
# Run every day at 02:00 UTC
- cron: '0 2 * * *'
workflow_dispatch: {}

jobs:
close-stale-issues:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- uses: actions/github-script@v7
with:
script: |
const STALE_DAYS = 30;
const EXEMPT_LABEL = 'keep-open';
// MEMBER = org member, OWNER = org owner
const TEAM_ASSOCIATIONS = ['MEMBER', 'OWNER'];

const now = new Date();
const staleThreshold = new Date(now.getTime() - STALE_DAYS * 24 * 60 * 60 * 1000);

console.log(`Looking for issues with last team reply before ${staleThreshold.toISOString()}`);

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

let closedCount = 0;

for (const issue of issues) {
// Skip pull requests (GitHub API returns PRs as issues too)
if (issue.pull_request) continue;

// Skip issues with the exempt label
if (issue.labels.some(l => l.name === EXEMPT_LABEL)) {
console.log(`Skipping #${issue.number} (has '${EXEMPT_LABEL}' label)`);
continue;
}

// Get all comments for this issue
const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
per_page: 100,
});

// Skip issues with no comments
if (comments.length === 0) continue;

const lastComment = comments[comments.length - 1];
const lastCommentDate = new Date(lastComment.created_at);
const isFromTeam = TEAM_ASSOCIATIONS.includes(lastComment.author_association);
const isStale = lastCommentDate < staleThreshold;

if (isFromTeam && isStale) {
console.log(`Closing #${issue.number}: last team reply on ${lastCommentDate.toISOString()} by @${lastComment.user.login}`);

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: [
'This issue has been automatically closed because it has not received a response for over 30 days since the last reply from a team member.',
'',
'If this issue is still relevant, feel free to reopen it or create a new issue.',
'You can also add the `keep-open` label to prevent automatic closure.',
].join('\n'),
});

await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed',
state_reason: 'not_planned',
});

closedCount++;
}
}

console.log(`Done. Closed ${closedCount} stale issue(s).`);
38 changes: 38 additions & 0 deletions .github/workflows/keep_open_command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Keep Open Command

on:
issue_comment:
types: [created]

jobs:
keep-open:
if: >-
!github.event.issue.pull_request
&& contains(github.event.comment.body, '/keep-open')
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- uses: actions/github-script@v7
with:
script: |
const TEAM_ASSOCIATIONS = ['MEMBER', 'OWNER'];
const association = context.payload.comment.author_association;

if (!TEAM_ASSOCIATIONS.includes(association)) {
console.log(`Ignoring /keep-open from non-team user (association: ${association})`);
return;
}

const owner = context.repo.owner;
const repo = context.repo.repo;
const issue_number = context.issue.number;

await github.rest.issues.addLabels({
owner,
repo,
issue_number,
labels: ['keep-open'],
});

console.log(`Added 'keep-open' label to #${issue_number}`);