Using GitHub Actions for Bulk Resolving
| CommentsToday I was working on one of our internal GitHub repositories that apparently used to be used for our tooling issue tracking. I have no idea the history but a quick look at the 68 issues with the latest dating back to 2017 told me that yeah, nobody is looking at these anymore. After a quick email ack from my dev lead that I could bulk clear these out I immediately went to the repo issues list, and was about to do this:
Then I realized that all that was going to do was close them without any reasoning at all. I know that closing sends a notification to people on the issue and that wasn’t the right thing to do. I quickly looked around, did some googling and didn’t find anything in the GitHub docs that would allow me to “bulk resolve and add a message” outside of adding a commit and a bunch of “close #XXX” statements. That was unrealistic. I threw it out on Twitter in hopes maybe someone had a tool already. The other debate in my head was writing some code to iterate through them and close with a message. This felt heavy for my needs, I’d need to get tokens, blah blah. I’m lazy.
Then I thought to myself, Self, I’m pretty sure you should be able to use the ‘labeled’ trigger in GitHub Actions to automate this! Thinking this way made me think that I could use a trigger to still bulk close them but the action would be able to add a message to each one. Again, a quick thinking here led me to be writing more code than I thought…but I was on the right track. Some more searching for different terms (adding actions) and I discovered the action actions/stale to the rescue! This is a workflow designed to run on a schedule, look at ‘stale’ (to be defined by you) and label them and/or close them after certain intervals. The design looks to be something like “run every day and look for things that are X days old, label them stale, then warn that if action isn’t taken in Y days that they would be closed” – perfect for my need except I wanted to close NOW! No problem. Looking at the sample it used a schedule trigger and a CRON format for the schedule. Off to crontab.guru to help me figure out the thing I can never remember. What’s worse, regex or cron? Who knows?
And then it dawned on me! My favorite GitHub Actions tip is to add workflow_dispatch as one of the triggers to workflows. This allows you to manually trigger a workflow from your repo:
I use this ALL the time to make sure I can not have to fake a commit or something on certain projects. This was the perfect thing I needed. The combination of workflow_dispatch and this stale action would enable me to complete this quickly. I added the following workflow to our repo:
name: "Close stale issues" on: workflow_dispatch: branches: - master jobs: stale: runs-on: ubuntu-latest steps: - uses: actions/stale@v3 with: repo-token: ${{ secrets.GITHUB_TOKEN }} days-before-stale: 30 days-before-close: 0 stale-issue-message: 'This issue is being closed as stale' close-issue-message: 'This repo has been made internal and no longer tracking product issues. Closing all open stale issues.'
I just had to set a few parameters for a stale message (required) and I set the warning day basically to 0 so it would happen NOW. Then I trigger the workflow manually. Boom! The workflow ran and 2 minutes later all 68 issues were marked closed with a message that serves as the reason and the user won’t be too alarmed for some random bulk closure.
I’m glad I remembered that GitHub Actions aren’t just for CI/CD uses and can be used to quickly automate much more. In fact I’m writing this blog post maybe to help others, but certainly to serve as a bookmark to myself when I forget about this again.
Hope this helps!
Please enjoy some of these other recent posts...
Comments