branch-commit-msg
![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)
Overview
branch-commit-msg
is a git commit-msg hook that extracts a configurable regex pattern from the current branch and reformats the final commit message to the configured format.
Installation
With no dependency:
$ npx branch-commit-msg install
With husky:
$ npm install -D branch-commit-msg
$ npx husky add .husky/commit-msg 'npx branch-commit-msg-hook "$1"'
Uninstall
With no dependency:
$ rm .git/hooks/commit-msg
With husky:
Remove npx branch-commit-msg-hook "$1"
from .husky/commit-msg
and run:
$ npm uninstall branch-commit-msg
Usage
After installation, create a .commitmsgrc.json
file at the root of your project and configure how you would like to reformat your final commit message based on elements of the active branch name:
{
"extractPattern": string,
"extractPatternMatchCase": boolean,
"commitMsgFormat": string
}
After your .commitmsgrc.json
is configured, start making commits!
Configuration Examples
Preface commit message with a Shortcut ticket number:
{
"extractPattern": "sc-[0-9]+",
"extractPatternMatchCase": false,
"commitMsgFormat": "%b0 - %m"
}
$ git commit -m "added a thing"
$ git log -1 --pretty=%B
Suffix and format a commit message with a JIRA ticket:
{
"extractPattern": "SOMEPRJ-[0-9]+",
"extractPatternMatchCase": false,
"commitMsgFormat": "%m (%b0 | upper)"
}
$ git commit -m "added a thing"
$ git log -1 --pretty=%B
Go crazy with group matching:
{
"extractPattern": "(some).*(complex[0-9-]+).*(branch)",
"extractPatternMatchCase": false,
"commitMsgFormat": "%m | upper to %b1 | upper %b2 %b3 | lower"
}
$ git commit -m "added a thing"
$ git log -1 --pretty=%B
Development
Prerequisites
- Docker installation (for integration and end-to-end (e2e) testing)
- Node.js (>=14.0.0) runtime
- Yarn installation
Install Dependencies
$ yarn install
Test
$ yarn test[:unit|:integration|:e2e|:smoke]
Build
$ yarn build