Pre-Commit Auto-Fixes#
What are Pre-Commit Auto-Fixes?#
When pre-commit runs, certain hooks can automatically fix some of the issues they raise. This is a great way to ensure that your code is always formatted correctly and that you don't have to worry about fixing issues manually.
Normally, when pre-commit finds an issue and is able to automatically fix it, it will do so, but it will still raise an error. The changes it made will be unstaged, and you will have to run git add to stage and commit them. This is generally a good thing, as it allows you to review the changes first.
Integration with Automated Github Bots#
However, if a bot like renovate[bot] is making changes to your code, you want to minimize the number of human interventions required to merge the PRs it creates. If the only changes in a PR are to fix formatting issues, it's a waste of time to have to manually approve them. In this case, you can configure your Github Action to automatically stage and commit the changes it makes. This way, the changes will be included in the PR that gets automatically merged.
One tool that can help with this is stefanzweifel/git-auto-commit-action. This action will detect files changes during the course of a Workflow run and automatically commit them to the repository. All you need to do is add the action as a step at the end of your Workflow file:
name: pre-commit
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.x'
- uses: pre-commit/action@v2.2.0
- uses: stefanzweifel/git-auto-commit-action
One caveat is that if renovate[bot] thinks others are making changes to its PRs, it will assume that a human is taking over to either close or merge the PR. This means that if you use git-auto-commit-action to automatically commit the changes made by renovate[bot], renovate[bot] will stop functioning on that PR, including rebasing. To get around this, you can configure git-auto-commit-action to pretend to be renovate[bot] by setting the following variables: