If you are already using pre-commit or you are planning to use pre-commit to enforce coding standard and detect issues before code check-in, update-pre-commit keeps revs in .pre-commit-config.yaml up to date and facilitate your change management operations to optionally create pull request.
- we outperform others in update speed by more than
70%. - we protect you against unreliable revs with tag such as
alpha,beta,prerelease, andrc. - we reduce your supply chain risks with
openssf best practicesin our development and operations.
Please visit our GitHub action (update-pre-commit-action) on the GitHub Marketplace.
Prerequisites
* Python (3.12+)
β‘ install pre-commit.
* GitHub
β‘ create a fine-grained token with repository permissions (see below).
In the command-line examples below, we use a GitHub project named hello-world. This project has pre-commit installed and a valid .pre-commit-config.yaml.
We will first install update-pre-commit in a virtual environment named after the project. Next, we will run update-pre-commit with different options and show the results.
~/work/hello-world $ workon hello-world
(hello-world) ~/work/hello-world $ export GH_TOKEN=github_pat_xxxxxxxxxxxxx
(hello-world) ~/work/hello-world $ pip install -U update-pre-commit
π Run to show command line usage and options: --help
(hello-world) ~/work/hello-world $ update-pre-commit --help
Usage: update-pre-commit [OPTIONS]
Options:
--file TEXT default: .pre-commit-config.yaml
--dry-run BOOLEAN default: true
--open-pr BOOLEAN default: false
--version Show the version and exit.
--help Show this message and exit.
π Run to show version: --version
(hello-world) ~/work/hello-world $ update-pre-commit --version
update-pre-commit, version 1.2.3
π Run default (without any options)
By default, update-pre-commit implicitly runs --dry-run true --open-pr false.
update-pre-commit:
- reads
.pre-commit-config.yaml. - produces a list of out-of-date pre-commit hooks on screen.
(NO changes will be made to.pre-commit-config.yaml)
(hello-world) ~/work/hello-world $ update-pre-commit
Starting update-pre-commit (file: .pre-commit-config.yaml, dry-run True open-pr False)...
hadolint/hadolint (v2.11.0) is not using the latest release rev (v2.12.0)
pycqa/flake8 (7.1.2) is not using the latest release tag (7.2.0)
antonbabenko/pre-commit-terraform (v1.98.0) is not using the latest release rev (v1.98.1)
Update revs in .pre-commit-config.yaml: None
π Run to update out-of-date hooks: --dry-run false
update-pre-commit:
- reads
.pre-commit-config.yaml. - produce a list of out-of-date pre-commit hooks.
- update
.pre-commit-config.yaml.
(hello-world) ~/work/hello-world $ update-pre-commit --dry-run false
Starting update-pre-commit (file: .pre-commit-config.yaml, dry-run False open-pr False)...
hadolint/hadolint (v2.11.0) is not using the latest release rev (v2.12.0)
pycqa/flake8 (7.1.2) is not using the latest release tag (7.2.0)
antonbabenko/pre-commit-terraform (v1.98.0) is not using the latest release rev (v1.98.1)
Update revs in .pre-commit-config.yaml: Success
π Run to update out-of-date hooks and open a pull request: --dry-run false --open-pr true
update-pre-commit:
- reads
.pre-commit-config.yaml. - produces a list of out-of-date pre-commit hooks on screen.
- updates
.pre-commit-config.yaml. - checkout a new git branch
update_pre_commit_XXXXXXXXXXXXXXXXXXXXX. - opens a pull request against repository default branch.
(hello-world) ~/work/hello-world $ update-pre-commit --dry-run false --open-pr true
Starting update-pre-commit (file: .pre-commit-config.yaml, dry-run False open-pr True)...
hadolint/hadolint (v2.11.0) is not using the latest release rev (v2.12.0)
pycqa/flake8 (7.1.2) is not using the latest release tag (7.2.0)
antonbabenko/pre-commit-terraform (v1.98.0) is not using the latest release rev (v1.99.0)
Update revs in .pre-commit-config.yaml: Success
Checkout new branch successfully....
Push commits successfully:
from local branch: update_pre_commit_01JV8P09N4G5K9Q4DDD533ARBH
with commit hash : 7b293faf5e14f6950bf28b510eb8d8c8beff26fe
Creating a Pull Request as follows:
Owner/Repo. : tagdots/hello-world
Title : update pre-commit-config
Source Branch: tagdots:update_pre_commit_01JV8P09N4G5K9Q4DDD533ARBH
PR for Branch: main
Rev Variances: [{"owner_repo": "antonbabenko/pre-commit-terraform", "current_rev": "v1.98.1", "new_rev": "v1.99.0"}, {"owner_repo": "adrienverge/yamllint", "current_rev": "v1.37.0", "new_rev": "v1.37.1"}]
Created pull request #101 successfully: https://github.com/tagdots/hello-world/pull/101
Step 1 - Ensure the following
* your project's .pre-commit-config.yaml file is valid.
* your GitHub fine-grained token has the write permissions to contents and pull requests.
* update-pre-commit can find the .pre-commit-config.yaml file at the root of YOUR project.
Step 2 - Open an issue
Pull requests and stars are always welcome. For pull requests to be accepted on this project, you should follow PEP8 when creating/updating Python codes.
See Contributing
