Skip to content

Label Stale Issues #462

Label Stale Issues

Label Stale Issues #462

Workflow file for this run

name: Label Stale Issues
on:
schedule:
- cron: '0 0 * * *'
jobs:
add_stale_label:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Set "stale" label on update
uses: actions/github-script@v6
with:
script: |
const needsStale = (issue) => {
const labels = issue.labels.map(labelObj => labelObj.name);
return (issue.assignees !== undefined
&& issue.assignees.length > 0
&& !labels.includes('epic')
&& !labels.includes('stale')
&& issue.state === 'open'
&& new Date(issue.updated_at) <= new Date() - 14 * 24 * 60 * 60 * 1000);
}
const issues = await github.paginate(github.rest.issues.listForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open'
});
for (const issue of issues) {
if (!issue.pull_request && await needsStale(issue)) {
console.log(`Adding STALE to issue #${issue.number}: ${issue.title}`);
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: ['stale']
});
}
}