https://github.com/s3rius/pre_commit_hooks
Collection of useful pre-commit hooks
https://github.com/s3rius/pre_commit_hooks
Last synced: 8 months ago
JSON representation
Collection of useful pre-commit hooks
- Host: GitHub
- URL: https://github.com/s3rius/pre_commit_hooks
- Owner: s3rius
- Created: 2021-05-18T19:57:46.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-07-14T08:36:38.000Z (almost 5 years ago)
- Last Synced: 2025-02-05T21:59:03.350Z (over 1 year ago)
- Language: Python
- Size: 42 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Collection of useful pre-commit hooks.
[](https://coveralls.io/github/s3rius/pre_commit_hooks)

This repo includes pre-commit-hooks that I couldn't find on the internet.
If you find it helpful too, please give a star to this repo.
Existing hooks:
* [Commit message prefix appender](#commit-message-prefix-appender)
* [TODOS linked to a Jira ticket](#todos-linked-to-a-jira-ticket)
## Commit message prefix appender
### Abstract
This hook appends JIRA task name at the beginning of the commit message just before you commit.
It detects that current branch is a JIRA ticket name and prepends it's name to the commit message.
Task name detecting is the following:
* Name starts with at least 2 **uppercase** latin letters;
* Letters followed by hyphen.
* hyphen followed by numbers.
E.G:
It will detect `TASK-123` or `AJAJ-312`.
### Installation
Add to your `.pre-commit-config.yaml`
```yaml
- repo: https://github.com/s3rius/pre_commit_hooks
hooks:
- id: commit_msg_prefix
args:
- "-f={}:"
```
And install `prepare-commit-msg` hooks like this.
```bash
pre-commit install --hook-type "prepare-commit-msg"
```
### Arguments
You can use the following parameters:
```
-f FORMAT, --format FORMAT
Commit prefix format. (default: {}:)
The "{}" will be replaced with current branch name.
--force Force prefix addition. (default: False)
Add prefix even if it already exists.
```
## TODOS linked to a Jira ticket
### Abstract
This hook won't allow you to commit if you have todo linked to
currently active branch.
TODO is linked if it has the following format:
```
TODO TASK-123:
```
E.G.
If you work on a branch JTICKET-123 and you have
comment like this somwhere in your codebase:
```python
a = 3 # TODO JTICKET-123: change to 4
```
This hook will raise an error.
### Installation
Add to your `.pre-commit-config.yaml`
```yaml
- repo: https://github.com/s3rius/pre_commit_hooks
hooks:
- id: linked_todos
args:
- FIXME
- FOR_TEST
```
### Arguments
You can use the following parameters:
```
positional arguments:
formats List of different formats for special comments. E.G FIXME. (default: [])
optional arguments:
-h, --help show this help message and exit
--disable-todos Disable todo detection. (default: False)
```
```
# note
Positional arguments are provided as is.
args:
- '--disable-todos'
- ONE
- TWO
- THREE
parameters 'ONE', 'TWO' and 'THREE' are positional.
```