-
Notifications
You must be signed in to change notification settings - Fork 642
Add workflow to auto-close stale needs-info issues #9057
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| name: Close Stale Needs-Info Issues | ||
|
|
||
| on: | ||
| schedule: | ||
| # Run nightly at midnight UTC | ||
| - cron: "0 0 * * *" | ||
|
|
||
| # Manual trigger for testing | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| close-stale-needs-info: | ||
| name: Close Stale Needs-Info Issues | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| issues: write | ||
| steps: | ||
| - name: Close stale needs-info issues | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const LABEL = "needs-info"; | ||
| const BUSINESS_DAYS = 3; | ||
|
|
||
| function addBusinessDays(date, days) { | ||
| const result = new Date(date); | ||
| let added = 0; | ||
| while (added < days) { | ||
| result.setUTCDate(result.getUTCDate() + 1); | ||
| const day = result.getUTCDay(); | ||
| if (day !== 0 && day !== 6) { | ||
| added++; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| // Fetch all open issues with the needs-info label | ||
| const issues = await github.paginate(github.rest.issues.listForRepo, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| labels: LABEL, | ||
| state: "open", | ||
| per_page: 100, | ||
| }); | ||
|
|
||
| const now = new Date(); | ||
| let closedCount = 0; | ||
|
|
||
| for (const issue of issues) { | ||
| // Skip pull requests (the issues API also returns PRs) | ||
| if (issue.pull_request) { | ||
| continue; | ||
| } | ||
|
|
||
| // Find when the needs-info label was most recently applied | ||
| const events = await github.paginate(github.rest.issues.listEvents, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| per_page: 100, | ||
| }); | ||
|
|
||
| const labelEvents = events.filter( | ||
| (e) => | ||
| e.event === "labeled" && | ||
| e.label?.name === LABEL | ||
| ); | ||
|
|
||
| if (labelEvents.length === 0) { | ||
| continue; | ||
| } | ||
|
|
||
| const lastLabeledAt = new Date( | ||
| labelEvents[labelEvents.length - 1].created_at | ||
| ); | ||
| const deadline = addBusinessDays(lastLabeledAt, BUSINESS_DAYS); | ||
|
|
||
| if (now < deadline) { | ||
| continue; | ||
| } | ||
|
|
||
| // Check for any comments after the label was applied | ||
| const comments = await github.paginate(github.rest.issues.listComments, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| since: lastLabeledAt.toISOString(), | ||
| per_page: 100, | ||
| }); | ||
|
|
||
| // Filter to comments strictly after the label event | ||
| const hasNewComments = comments.some( | ||
| (c) => new Date(c.created_at) > lastLabeledAt | ||
| ); | ||
|
|
||
| if (hasNewComments) { | ||
| continue; | ||
| } | ||
|
|
||
| // Close the issue with a comment | ||
| 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 was labeled " + | ||
| "`needs-info` and received no response for 3 business days. " + | ||
| "If you have the requested information, please reply and we will reopen.", | ||
| }); | ||
|
|
||
| await github.rest.issues.update({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| state: "closed", | ||
| state_reason: "not_planned", | ||
| }); | ||
|
|
||
| closedCount++; | ||
| core.info(`Closed issue #${issue.number}: ${issue.title}`); | ||
| } | ||
|
|
||
| core.info(`Done. Closed ${closedCount} stale needs-info issue(s).`); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.