Skip to main content
← Back to workflows

How to Automate Closing Stale Issues and PRs in GitHub Actions

actions-stale -
GitHub Action
v9.0.0
1,347
Contributors
Contributor - dsameContributor - C0ZEN
Categories
CICUBE ANALYTICS INSIGHTS
Engineering Velocity: 25% Team Time Lost to CI Issues
View Platform →
3.5h
Time Saved/Dev/Week
40%
Faster Releases
Click for next insight
Usage
name: 'Usage of stale GitHub Action'

permissions:
contents: write # only for delete-branch option
issues: write
pull-requests: write

on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/stale@v9
with:
stale-issue-message: >
'Message to comment on stale issues. If none provided, will not mark issues stale'
stale-pr-message: >
'Message to comment on stale PRs. If none provided, will not mark PRs stale'

stale logo

stale

Marks issues and pull requests that have not had recent interaction


What is stale?

The GitHub Action for closing stale issues and PRs helps manage the lifecycle of contributions and discussions within a repository. This automation improves project maintenance by:

  • Labeling issues and PRs as "Stale" after a specified period of inactivity.
  • Automatically closing these stale items if the inactivity continues beyond an additional set duration.
  • Resetting the stale status if there's any new activity, keeping relevant discussions open.

Benefits of Automating Stale Issue and PR Management

  • Improved Efficiency: Automates the routine task of issue and PR triage, freeing up time for more critical development tasks.
  • Enhanced Engagement: Encourages contributors to revisit and update or close their pending submissions.
  • Project Clarity: Keeps the repository clean from old and unresolved issues or PRs, making it easier for maintainers and contributors to navigate and prioritize.

Configuring GitHub Actions to Manage Stale Issues and PRs with Different Timelines

For projects where issues tend to become irrelevant if not addressed or updated within a specific timeframe, we can set up an automated workflow to handle them accordingly. Here’s how you can configure GitHub Actions to mark issues as stale and close them if they remain inactive:

name: 'Close stale issues and PRs'
on:
schedule:
- cron: '30 1 * * *' # Scheduled to run at 1:30 AM every day

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9
with:
stale-issue-message: >
'This issue is stale because it has been open 30 days with no activity.'
days-before-stale: 30
days-before-close: 5

Configuring Different Timeouts for Issues and PRs, But Never Closing PRs

In some scenarios, you might want to treat issues and PRs differently, particularly to ensure that PRs are not closed automatically, giving contributors more time to address feedback.

name: 'Close stale issues and PR'
on:
schedule:
- cron: '30 1 * * *' # Scheduled to run at 1:30 AM every day

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9
with:
stale-issue-message: >
'This issue is stale because it has been open 30 days with no activity.'
stale-pr-message: >
'This PR is stale because it has been open 45 days with no activity.'
close-issue-message: >
'This issue was closed because it has been stalled for 5 days with no activity.'
days-before-stale: 30
days-before-close: 5
days-before-pr-close: -1 # PRs are marked as stale but not closed

How to Configure Labels and Date Restrictions for Stale Issues and PRs

For projects that require detailed tracking and management of issues and PRs, we can specify custom labels for stale issues/PRs and exempt certain items from being marked as stale based on their labels.

name: 'Close stale issues and PRs'
on:
schedule:
- cron: '30 1 * * *' # Scheduled to run at 1:30 AM every day

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9
with:
stale-issue-message: 'Stale issue message'
stale-pr-message: 'Stale pull request message'
stale-issue-label: 'no-issue-activity'
exempt-issue-labels: 'awaiting-approval,work-in-progress'
stale-pr-label: 'no-pr-activity'
exempt-pr-labels: 'awaiting-approval,work-in-progress'
only-labels: 'awaiting-feedback,awaiting-answers'

How to Prevent Stale Automation for PRs with Assignees

For projects that require maintaining active engagement on assigned PRs, we can configure the actions/stale GitHub Action to ignore these PRs when performing stale checks. This ensures that PRs under active review or development are not closed automatically.

name: 'Close stale issues and PRs'
on:
schedule:
- cron: '30 1 * * *' # Scheduled to run at 1:30 AM every day

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9
with:
exempt-all-pr-assignees: true

Input Parameters for Configuring Stale Issue and PR Management

InputDescription
repo-tokenA Personal Access Token (PAT) used for GitHub API authentication.
days-before-staleThe number of days to wait before marking issues or PRs as stale due to inactivity.
days-before-issue-staleSpecific number of days to wait before marking only issues as stale, overriding the general setting.
days-before-pr-staleSpecific number of days to wait before marking only PRs as stale, overriding the general setting.
days-before-closeThe number of days to wait before closing issues or PRs marked as stale.
days-before-issue-closeSpecific number of days to wait before closing issues marked as stale, overriding the general setting.
days-before-pr-closeSpecific number of days to wait before closing PRs marked as stale, overriding the general setting.
stale-issue-messageThe message to post when an issue is marked as stale.
stale-pr-messageThe message to post when a PR is marked as stale.
close-issue-messageThe message to post when a stale issue is closed.
close-pr-messageThe message to post when a stale PR is closed.
stale-issue-labelThe label to apply to issues when they are marked as stale.
close-issue-labelThe label to apply to issues when they are closed after being stale.
close-issue-reasonThe reason provided when closing a stale issue.
stale-pr-labelThe label to apply to PRs when they are marked as stale.
close-pr-labelThe label to apply to PRs when they are closed after being stale.
exempt-issue-labelsLabels that prevent issues from being marked as stale.
exempt-pr-labelsLabels that prevent PRs from being marked as stale.
only-labelsLabels that must all be present for an issue or PR to be checked for staleness.
only-issue-labelsSpecific labels that must all be present for issues only, overriding the general 'only-labels' setting.
only-pr-labelsSpecific labels that must all be present for PRs only, overriding the general 'only-labels' setting.
any-of-labelsLabels where the presence of any will mark the issue or PR to be checked for staleness.
any-of-issue-labelsSpecific labels where the presence of any will mark issues only to be checked for staleness.
any-of-pr-labelsSpecific labels where the presence of any will mark PRs only to be checked for staleness.
operations-per-runThe maximum number of operations the action can perform in one run.
remove-stale-when-updatedWhether to remove the stale label when an update/comment occurs on the issue/PR.
remove-issue-stale-when-updatedWhether to remove the stale label when an update/comment occurs on issues only.
remove-pr-stale-when-updatedWhether to remove the stale label when an update/comment occurs on PRs only.
labels-to-add-when-unstaleLabels to add to issues or PRs when they are no longer marked as stale.
labels-to-remove-when-staleLabels to remove from issues or PRs when they become stale.
labels-to-remove-when-unstaleLabels to remove from issues or PRs when they are no longer marked as stale.
debug-onlyWhether to perform a dry-run without making any actual changes.
ascendingWhether to fetch issues/PRs in ascending order based on creation date.
start-dateExcludes issues/PRs created before this date from being marked as stale.
delete-branchWhether to delete the branch after closing a stale PR.
exempt-milestonesMilestones that exempt issues/PRs from being marked as stale.
exempt-issue-milestonesSpecific milestones that exempt issues only from being marked as stale.
exempt-pr-milestonesSpecific milestones that exempt PRs only from being marked as stale.
exempt-all-milestonesExempts all issues and PRs with any milestones from being