A script for the prepare-commit-msg git hook that automatically injects a Jira ticket based off the jira ticket in the branch name
npm install @humankode/git-inject-jira-ticket> A git hook script to automatically inject the Jira ticket in a commit message
For example:
branch:
- feature-JIRA-1234
- or feature-JIRA-1234-implement-caching
- or feature/JIRA-1234-implement-caching
- or feature/JIRA-1234/implement-caching etc.
commit:
git commit -m "implement caching"
//=> JIRA-1234: implement caching
Install and configure Husky
.husky/prepare-commit-msg
``
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx --yes @humankode/git-inject-jira-ticket@latest
`
Zero configuration by default.
If no configuration specified, it will use JIRA-1234 as the Jira ticket pattern.
To override the default configuration, place a file called gitInjectJiraTicket.json in your root directory.
Refer to the Configuration interface for all options.
gitInjectJiraTicket.json
``
{
"jiraIssuePrefix": "FOO"
}
For example
It will expect Jira tickets to be in the format of FOO-1234
Valid branches would be feature-FOO-1234, feature-FOO-1234-some-message, feature/FOO-1234 etc.
The default allowed branchTypes are feature, hotfix, revert, release, build, ci, docs, fix, performance, refactor and test
To override branchTypes:
To only allow feature and hotfix branch types:
gitInjectJiraTicket.json
``
{
"branchConfiguration": {
"branchTypes": [
"feature",
"hotfix"
]
}
}
For example:
these branches would be valid:
- feature-JIRA-1234hotfix-JIRA-1234-implement-caching
- or feature/JIRA-1234-implement-caching
- or hotfix/JIRA-1234/implement-caching
- or etc.
The default value for jiraTicketLength is 1, which means that the Jira ticket is expected to have 1 or more digits.JIRA-1
For example, these would all be valid: , JIRA-12, JIRA-12324 etc.
To change this to only have 4 digits:
gitInjectJiraTicket.json
``
{
"jiraTicketLength": "4"
}
Now only 4 digits would be valid, for example: JIRA-1234
The default value for capitalizeMessage is true.
This capitalizes the first letter of the commit message.
For example:
branch: feature-JIRA-1234
git commit -m "some message. with another sentence"
//=> JIRA-1234: Some message. with another sentence
To override capitalizeMessage:
gitInjectJiraTicket.json
`
{
"messageConfiguration": {
"capitalizeMessage": false
}
}
``