Label Stale Issues #444
This file contains 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
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'] | |
}); | |
} | |
} |