https://github.com/uglow/cz-customizable-ghooks
Integrate cz-customizable config with ghooks or husky
https://github.com/uglow/cz-customizable-ghooks
Last synced: 12 months ago
JSON representation
Integrate cz-customizable config with ghooks or husky
- Host: GitHub
- URL: https://github.com/uglow/cz-customizable-ghooks
- Owner: uglow
- License: mit
- Created: 2016-05-12T05:43:52.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T14:00:00.000Z (over 3 years ago)
- Last Synced: 2025-07-18T18:26:34.173Z (12 months ago)
- Language: JavaScript
- Homepage:
- Size: 856 KB
- Stars: 20
- Watchers: 1
- Forks: 13
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# cz-customizable-ghooks
Integrate [cz-customizable](https://github.com/leonardoanalista/cz-customizable) config with [ghooks](https://github.com/gtramontina/ghooks) or [husky](https://github.com/typicode/husky) to use a single configuration for commit message generation AND commit message validation.
[](https://travis-ci.org/uglow/cz-customizable-ghooks)
[](http://npm.im/cz-customizable-ghooks)
[](https://github.com/semantic-release/semantic-release)
[](https://coveralls.io/github/uglow/cz-customizable-ghooks?branch=master)
[](https://david-dm.org/uglow/cz-customizable-ghooks#info=dependencies)
[](https://david-dm.org/uglow/cz-customizable-ghooks#info=devDependencies)
[](http://commitizen.github.io/cz-cli/)
## Purpose
This package validates that a git commit message matches the rules defined in your `cz-customizable` config file (see [cz-customizable](https://github.com/leonardoanalista/cz-customizable)).
[Example commit message rules](fixtures/fullCommitMessageConfig.js).
## Prerequisites
- git
- Node >= 4.x
- [commitizen](https://github.com/commitizen/cz-cli)
- [cz-customizable](https://github.com/leonardoanalista/cz-customizable)
- [ghooks](https://github.com/gtramontina/ghooks) or [husky](https://github.com/typicode/husky)
Make sure you have a git repository (`git init`) BEFORE installing ghooks, otherwise you have to take extra steps if you install ghooks before running `git init`.
## Installation
This package is designed to be used in conjunction with `commitizen`, `cz-customizable` and either `ghooks` or `husky`.
1. Install pre-requisites (if not already installed):
```
npm i commitizen -g
npm i cz-customizable cz-customizable-ghooks
```
2. Configure cz-customizable in `package.json`:
```
"config": {
"cz-customizable": {
"config": "path/to/your/cz-customizable-rules.js"
}
}
```
3. Install ONE of these git hook packages:
ghooks
1. Install ghooks:
```
npm i ghooks
```
2. Configure `package.json`:
```
"config": {
"ghooks": {
"commit-msg": "cz-customizable-ghooks $2"
}
}
```
_An example of this setup is in `examples/ghooks`._
husky
Install husky:
```
npm i husky
```
**If you use husky v4 or under:**
Configure the hooks in the `package.json`:
```
"husky": {
"hooks": {
"commit-msg": "cz-customizable-ghooks"
}
}
```
**If you use husky v5 or higher:**
Inside the *.husky* folder, create a new script:
`husky add .husky/commit-msg "npm run commit-msg -- \"$1\""`.
Then create create the `commit-msg` script in the `package.json`:
```
"scripts": {
"commit-msg": "cz-customizable-ghooks"
}
```
If you wish to specify the `LOGGING_LEVEL` flag, you can use [cross-env](https://www.npmjs.com/package/cross-env):
```
"scripts": {
"commit-msg": "cross-env LOGGING_LEVEL=debug cz-customizable-ghooks"
}
```
_An example of this setup is in `examples/husky`._
## Usage
Commit your changes to git as normal. If the commit message entered is invalid, the commit will be rejected with an error message (according to the rules specified in your cz-customizable config).
Works with git command-line and visual Git tools (such as SourceTree).
## Additional config
### `appendIssueFromBranchName`
If this config value is set to true, the git branch name is queried, and an attempt is made to
parse the branch name, looking for the `ticketNumberPrefix` and `ticketNumberRegExp` values. If found,
they are appended to the commit message. If the branch name does not match the `ticketNumberPrefix`
and `ticketNumberRegExp` expression, or if `ticketNumberPrefix` and `ticketNumberRegExp` are not provided,
the full branch name is appended to the commit message.
This property was previously called `appendBranchNameToCommitMessage`.
## Debugging
You can turn on debug logging by specifying `LOGGING_LEVEL=debug` before the `cz-customizable-ghooks` command.