|
3 | 3 | A [`pre-commit`](https://pre-commit.com) hook to check commit messages for |
4 | 4 | [Conventional Commits](https://conventionalcommits.org) formatting. |
5 | 5 |
|
| 6 | +Works with Python >= 3.8. |
| 7 | + |
6 | 8 | ## Usage |
7 | 9 |
|
8 | 10 | Make sure `pre-commit` is [installed](https://pre-commit.com#install). |
|
24 | 26 | hooks: |
25 | 27 | - id: conventional-pre-commit |
26 | 28 | stages: [commit-msg] |
27 | | - args: [] # optional: list of Conventional Commits types to allow e.g. [feat, fix, ci, chore, test] |
| 29 | + args: [] |
28 | 30 | ``` |
29 | 31 |
|
30 | 32 | Install the `pre-commit` script: |
@@ -62,9 +64,15 @@ Example commit message fixing an issue: |
62 | 64 |
|
63 | 65 | fix: remove infinite loop |
64 | 66 |
|
65 | | -Optionally, include a scope in parentheses after the type for more context: |
| 67 | +Example commit with scope in parentheses after the type for more context: |
66 | 68 |
|
67 | 69 | fix(account): remove infinite loop |
| 70 | +
|
| 71 | +Example commit with a body: |
| 72 | +
|
| 73 | + fix: remove infinite loop |
| 74 | +
|
| 75 | + Additional information on the issue caused by the infinite loop |
68 | 76 | ``` |
69 | 77 |
|
70 | 78 | Make a (conventional) commit :heavy_check_mark:: |
@@ -115,6 +123,40 @@ print(is_conventional("nope: this is not a conventional commit")) |
115 | 123 | print(is_conventional("custom: this is a conventional commit", types=["custom"])) |
116 | 124 | ``` |
117 | 125 |
|
| 126 | +## Passing `args` |
| 127 | + |
| 128 | +`conventional-pre-commit` supports a number of arguments to configure behavior: |
| 129 | + |
| 130 | +```shell |
| 131 | +$ conventional-pre-commit -h |
| 132 | +usage: conventional-pre-commit [-h] [--force-scope] [--strict] [types ...] input |
| 133 | +
|
| 134 | +Check a git commit message for Conventional Commits formatting. |
| 135 | +
|
| 136 | +positional arguments: |
| 137 | + types Optional list of types to support |
| 138 | + input A file containing a git commit message |
| 139 | +
|
| 140 | +options: |
| 141 | + -h, --help show this help message and exit |
| 142 | + --force-scope Force commit to have scope defined. |
| 143 | + --strict Force commit to strictly follow Conventional Commits formatting. Disallows fixup! style commits. |
| 144 | +``` |
| 145 | + |
| 146 | +Supply arguments on the command-line, or via the pre-commit `hooks.args` property: |
| 147 | + |
| 148 | +```yaml |
| 149 | +repos: |
| 150 | + - repo: https://github.com/compilerla/conventional-pre-commit |
| 151 | + rev: <git sha or tag> |
| 152 | + hooks: |
| 153 | + - id: conventional-pre-commit |
| 154 | + stages: [commit-msg] |
| 155 | + args: [--strict, --force-scope, feat, fix, chore, test, custom] |
| 156 | +``` |
| 157 | + |
| 158 | +**NOTE:** when using as a pre-commit hook, `input` is supplied automatically (with the current commit's message). |
| 159 | + |
118 | 160 | ## Development |
119 | 161 |
|
120 | 162 | `conventional-pre-commit` comes with a [VS Code devcontainer](https://code.visualstudio.com/learn/develop-cloud/containers) |
|
0 commit comments