iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🌐

Automatically Close Inactive Issues with GitHub Actions

に公開

By using GitHub Actions' actions/stale, you can automatically close inactive issues.

The flow with actions/stale is as follows:

  • Comment on an issue that has been inactive for a certain period to encourage action from participants.
  • Close the issue if there is no further activity after another certain period.

I will now try implementing this in my own project.

Configuration

I added a workflow to the repository with a file named .github/workflows/stale-issues.yml.

name: Close inactive issues
on:
  schedule:
    - cron: "30 1 * * *"

jobs:
  close-issues:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/stale@v4
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          stale-issue-message: "This issue is stale because it has been open for 60 days with no activity."
          close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale."
          stale-issue-label: "stale"
          exempt-issue-labels: 'bug,enhancement'
          days-before-issue-stale: 60
          days-before-issue-close: 14
          days-before-pr-stale: -1
          days-before-pr-close: -1

Below is an explanation of each item:

  • on.schedule.cron specifies the execution date and time. Setting it to "30 1 * * *" means it will run every day at 1:30 (UTC).
  • If there is no activity for the number of days specified in days-before-issue-stale, it will add the label specified in stale-issue-label and post the stale-issue-message as a comment.
    • Issues with labels specified in exempt-issue-labels will be excluded.
  • If there is still no activity for the number of days specified in days-before-issue-close, the ticket will be closed and the close-issue-message will be posted as a comment.
  • While actions/stale can also close Pull Requests, I have excluded Pull Requests this time by setting days-before-pr-stale and days-before-pr-close to -1.

Results

They were processed in sequence as shown below (at the time of introduction, labels were set for those over 60 days, and then closed 14 days later):

Comment

Conclusion

Closing neglected issues one by one was a hassle, so being able to close them all at once was a huge help.
I think it's also great for my peace of mind to be able to handle inactive issues mechanically from now on.

Discussion