Skip to content

Add a stale bot to help grooming issues #404

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 1 commit into from
Sep 13, 2019
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
106 changes: 106 additions & 0 deletions .github/workflows/stale.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: stale-bot

on:
schedule:
# run every day at midnight
- cron: '0 0 * * *'
issue_comment:
types: ['created']

jobs:
stale-bot:
runs-on: ubuntu-latest
steps:
- name: Mark stale
if: github.event_name == 'schedule'
uses: actions/[email protected]
with:
github-token: ${{github.token}}
script: |
// Get a list of all open issues labeled `waiting for feedback`
const opts = github.issues.listForRepo.endpoint.merge({
...context.repo,
state: 'open',
labels: ['waiting for feedback'],
});
const issues = await github.paginate(opts);

// Set this value to whatever makes sense for the repo.
let elapsedDays = 15

let elapsed = elapsedDays * 24 * 60 * 60 * 1000;
let now = new Date();
for (const issue of issues) {
// If an issue was active in the past 15 days, leave it alone.
if (now - new Date(issue.updated_at).getTime() < elapsedDays) {
continue;
}

// If we're here, we've been waiting for feedback for more than
// 15 days, mark as stale.
github.issues.addLabels({
...context.repo,
issue_number: issue.number,
labels: ['stale']
});
}

- name: Mark active
uses: actions/[email protected]
with:
github-token: ${{github.token}}
script: |
// Every time a comment is added to an issue, close it if it contains
// the `stale` label.

// Load issue's labels.
const opts = github.issues.listLabelsOnIssue.endpoint.merge({
...context.repo,
issue_number: context.issue.number
});
const labels = await github.paginate(opts);

// Search for `stale`.
for (const label of labels) {
if (label.name === 'stale') {
await github.issues.removeLabel({
...context.repo,
issue_number: context.issue.number,
name: 'stale'
})
return;
}
}

- name: Close stale
if: github.event_name == 'schedule'
uses: actions/[email protected]
with:
github-token: ${{github.token}}
script: |
// Load all the `stale` issues
const opts = github.issues.listForRepo.endpoint.merge({
...context.repo,
state: 'open',
labels: ['stale'],
});
const issues = await github.paginate(opts);

// Set this value to whatever makes sense for the repo.
let elapsedDays = 30;

let elapsed = elapsedDays * 24 * 60 * 60 * 1000;
let now = new Date();
for (const issue of issues) {
// If an issue was stale for less than elapsed time, leave it alone.
if (now - new Date(issue.updated_at).getTime() < elapsed) {
continue;
}

// Close the stale issue.
await github.issues.update({
...context.repo,
issue_number: issue.number,
state: 'closed'
});
}