|
1 | 1 | # conventional-pre-commit |
2 | | -A pre-commit hook that checks the commit message for Conventional Commit formatting |
| 2 | + |
| 3 | +A [`pre-commit`](https://pre-commit.com) hook to check commit messages for |
| 4 | +[Conventional Commit](https://conventionalcommits.org) formatting. |
| 5 | + |
| 6 | +## Usage |
| 7 | + |
| 8 | +Make sure `pre-commit` is [installed](https://pre-commit.com#install). |
| 9 | + |
| 10 | +Create a blank configuration file at the root of your repo, if needed: |
| 11 | + |
| 12 | +```console |
| 13 | +touch .pre-commit-config.yaml |
| 14 | +``` |
| 15 | + |
| 16 | +Add a new repo entry to your configuration file: |
| 17 | + |
| 18 | +```yaml |
| 19 | +repos: |
| 20 | + |
| 21 | +# - repo: ... |
| 22 | + |
| 23 | + - repo: https://github.com/compilerla/conventional-pre-commit |
| 24 | + rev: <git sha or tag> |
| 25 | + hooks: |
| 26 | + - id: conventional-pre-commit |
| 27 | + stages: [commit-msg] |
| 28 | +``` |
| 29 | +
|
| 30 | +Install the `pre-commit` script: |
| 31 | + |
| 32 | +```console |
| 33 | +pre-commit install --hook-type commit-msg |
| 34 | +``` |
| 35 | + |
| 36 | +Make a (normal) commit :x:: |
| 37 | + |
| 38 | +```console |
| 39 | +$ git commit -m "add a new feature" |
| 40 | +
|
| 41 | +[INFO] Initializing environment for .... |
| 42 | +Conventional Commit......................................................Failed |
| 43 | +- hook id: conventional-pre-commit |
| 44 | +- duration: 0.07s |
| 45 | +- exit code: 1 |
| 46 | +
|
| 47 | +[Commit message] add a new feature |
| 48 | +
|
| 49 | +Your commit message doesn't look like a Conventional Commit https://www.conventionalcommits.org/ |
| 50 | +
|
| 51 | +Conventional Commit messages start with one of the below types, followed by a colon, followed by the message: |
| 52 | +
|
| 53 | + build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test |
| 54 | +
|
| 55 | +Example commit message adding a feature: |
| 56 | +
|
| 57 | + feat: add great new feature |
| 58 | +
|
| 59 | +Example commit message fixing an issue: |
| 60 | +
|
| 61 | + fix: remove infinite loop |
| 62 | +
|
| 63 | +Optionally, include a scope in parentheses after the type for more context: |
| 64 | +
|
| 65 | + fix(account): remove infinite loop |
| 66 | +``` |
| 67 | + |
| 68 | +Make a (conventional) commit :heavy_check_mark:: |
| 69 | + |
| 70 | +```console |
| 71 | +$ git commit -m "feat: add a new feature" |
| 72 | +
|
| 73 | +[INFO] Initializing environment for .... |
| 74 | +Conventional Commit......................................................Passed |
| 75 | +- hook id: conventional-pre-commit |
| 76 | +- duration: 0.05s |
| 77 | +``` |
| 78 | + |
| 79 | +## License |
| 80 | + |
| 81 | +[Apache 2.0](LICENSE) |
| 82 | + |
| 83 | +Inspired by matthorgan's [`pre-commit-conventional-commits`](https://github.com/matthorgan/pre-commit-conventional-commits). |
0 commit comments