Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dtaivpp/commit-msg-regex-hook
A simple repository for bashing commit messages against regex
https://github.com/dtaivpp/commit-msg-regex-hook
Last synced: 5 days ago
JSON representation
A simple repository for bashing commit messages against regex
- Host: GitHub
- URL: https://github.com/dtaivpp/commit-msg-regex-hook
- Owner: dtaivpp
- License: mit
- Created: 2021-06-29T20:49:25.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-06T17:22:21.000Z (12 months ago)
- Last Synced: 2024-09-29T09:05:02.365Z (about 2 months ago)
- Language: Python
- Size: 39.1 KB
- Stars: 2
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# commit-msg-regex-hook
This hook is designed to be used with the [pre-commit](https://pre-commit.com/) hook framework. It will check your commit string against the provided regex.
### Using the commit-msg-regex-hook
First you will need to setup [pre-commit](https://pre-commit.com/) using their documentation.
Next you will need to enable commit message hooks:
`pre-commit install --hook-type commit-msg`Finally you can add this to your .pre-commit-config.yaml:
```
- repo: https://github.com/dtaivpp/commit-msg-regex-hook
rev: v0.2.2
hooks:
- id: commit-msg-regex-hook
args: ["--pattern='[A-Z]{3,4}-[0-9]{3,6} \\| [\\w\\s]* \\| .+'",
"--failure_message='Commits should match the pattern: Card-ID | Name | Message'"]
stages: [commit-msg]
```**note: the backslashes in regex need to be escaped need to be escaped
**double note: if you are having issues you can run with the --debug argument as well for additional logging.With this you can achieve so many things. A good example is verifing deveopers have signed the DCO before allowing a commit.
```
- repo: https://github.com/dtaivpp/commit-msg-regex-hook
rev: v0.2.2
hooks:
- id: commit-msg-regex-hook
args: ["--pattern='Signed-off-by: .* <(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|'(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*')@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])>'",
"--failure_message='Ensure you are signing the DCO'"]
stages: [commit-msg]
```### Developing this project
If you would like to contribute to this project I am happy to accept contributions. Small note I use two spaces for indents and am not looking to swap.
Here is how you can contribute:
1. Fork the repo
2. Create a virtual envrionment `python -m venv venv`
3. Activate the virtual environment:
- Windows: `venv\Scripts\activate`
- Mac/Linux: `source venv/bin/activate`
4. Install the reqirements `python -m pip install -r requirements.txt`
5. Install our hooks:
- `pre-commit install`And you are off to the races!
Before committing I would reccomend checking your build against unittest and the linter. If it doesn't pass it wont pass!
- `python -m unittest test/test.py`
- `python -m pylint commit_msg_regex_hook`Make sure if you add a check to add a test case!