Gathering detailed insights and metrics for jira-prepare-commit-msg
Gathering detailed insights and metrics for jira-prepare-commit-msg
Gathering detailed insights and metrics for jira-prepare-commit-msg
Gathering detailed insights and metrics for jira-prepare-commit-msg
npm install jira-prepare-commit-msg
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
118 Stars
827 Commits
37 Forks
3 Watching
8 Branches
9 Contributors
Updated on 29 Oct 2024
TypeScript (95.08%)
JavaScript (4.92%)
Cumulative downloads
Total Downloads
Last day
4.9%
13,938
Compared to previous day
Last week
-0.5%
67,996
Compared to previous week
Last month
6.3%
297,805
Compared to previous month
Last year
38.9%
2,765,108
Compared to previous year
1
The husky command to add JIRA ticket ID into the commit message if it is missing.
The JIRA ticket ID is taken from the current git branch name.
Installing Jira prepare commit msg hook into your project will mean everyone contributing code to your project will automatically tag each commit with its associated issue key based on the branch name.
So if your branch name is feature/TEST-123-new-feature
, then when you commit with a message "initial commit"
it will automatically become "TEST-123: initial commit"
.
Why would you want this? Well, Jira has many hidden goodies, and this is one of them! If you include an issue key in your commit messages AND you have your deployment pipeline connected to Jira this will unlock many bonus features, such as the Deployments view, Cycle time report, Deployment frequency report and I've heard many more features are coming soon!
Install the package using NPM
1npm install husky jira-prepare-commit-msg --save-dev && npx husky install
Execute command
1npx husky add .husky/prepare-commit-msg 'npx jira-prepare-commit-msg $1'
To quiet the output of the command, you can use the --quiet
flag.
1npx husky add .husky/prepare-commit-msg 'npx jira-prepare-commit-msg --quiet $1'
Inside your package.json add a standard husky npm script for the git hook
1{ 2 "husky": { 3 "hooks": { 4 "prepare-commit-msg": "jira-prepare-commit-msg" 5 } 6 } 7}
Starting with v1.3 you can now use different ways of configuring it:
jira-prepare-commit-msg
object in your package.json
.jirapreparecommitmsgrc
file in JSON or YML formatjira-prepare-commit-msg.config.js
file in JS formatSee cosmiconfig for more details on what formats are supported.
package.json
example:1{ 2 "jira-prepare-commit-msg": { 3 "messagePattern": "[$J] $M", 4 "jiraTicketPattern": "([A-Z]+-\\d+)", 5 "commentChar": "#", 6 "isConventionalCommit": false, 7 "conventionalCommitPattern": "^([a-z]+)(\\([a-z0-9.,-_ ]+\\))?!?: ([\\w \\S]+)$", 8 "allowEmptyCommitMessage": false, 9 "gitRoot": "", 10 "allowReplaceAllOccurrences": true, 11 "ignoredBranchesPattern": "^(master|main|dev|develop|development|release)$", 12 "ignoreBranchesMissingTickets": false 13 } 14}
jira-prepare-commit-msg
supports special message pattern to configure where JIRA ticket number will be inserted.
$J
will be replaced by the JIRA ticket number$M
will be replaced by the commit message.Pattern [$J]\n$M
is currently enabled by default.
1{ 2 "jira-prepare-commit-msg": { 3 "messagePattern": "[$J]\n$M" 4 } 5}
[$J] $M
[$J]-$M
$J $M
NOTE: the supplied commit message will be cleaned up by strip
mode.
jira-prepare-commit-msg
supports by default replacing all occurrences variables in message pattern.
1{ 2 "jira-prepare-commit-msg": { 3 "allowReplaceAllOccurrences": true 4 } 5}
If set the message pattern to [$J] $M. \n Line for CI ($J): $M
, then all occurrences will be replaced:
[JIRA-1234] test message.
Line for CI (JIRA-1234): test message
jira-prepare-commit-msg
allows using custom regexp string pattern to search JIRA ticket number.
Pattern ([A-Z]+-\\d+)
is currently supported by default.
NOTE: to search JIRA ticket pattern flag i
is used: new RegExp(pattern, i')
1{ 2 "jira-prepare-commit-msg": { 3 "jiraTicketPattern": "([A-Z]+-\\d+)" 4 } 5}
Git uses #
by default to comment lines in the commit message. If default char was changed jira-prepare-commit-msg
can allow set it.
1{ 2 "jira-prepare-commit-msg": { 3 "commentChar": "#" 4 } 5}
The commit message might be empty after cleanup or using -m ""
, jira-prepare-commit-msg
might insert the JIRA ticket number anyway if this flag is set.
1{ 2 "jira-prepare-commit-msg": { 3 "allowEmptyCommitMessage": true 4 } 5}
The git root folder might be set. It is either absolute path or relative path which will be resolved from cwd
1{ 2 "jira-prepare-commit-msg": { 3 "gitRoot": "./../../" 4 } 5}
The package will search commit message so:
1const pathToGit = path.resolve(cwd, './../../'); 2const pathToCommitMessage = path.join(pathToGit, '.git', 'COMMIT_EDITMSG');
Branches can be ignored and skipped by regex pattern string
1{ 2 "jira-prepare-commit-msg": { 3 "ignoredBranchesPattern": "^main|develop|(maint-.*)$" 4 } 5}
Moreover, this can be solved by replacing the Husky hook. Put in your prepare-commit-msg file (husky git hook):
1#!/bin/sh 2. "$(dirname "$0")/_/husky.sh" 3 4if [[ "$(git rev-parse --abbrev-ref HEAD)" =~ YOUR_BRANCH_REGEX ]]; then 5npx --no-install jira-prepare-commit-msg $1 6fi
where YOUR_BRANCH_REGEX
e.g. ^(feature|(bug|hot)fix)\/[A-Z]+-[0-9]+$
Be silent and skip any branch with missing jira ticket
1{ 2 "jira-prepare-commit-msg": { 3 "ignoreBranchesMissingTickets": true 4 } 5}
jira-prepare-commit-msg
supports conventional commit. To insert JIRA
ticket number to the description set the following setting:
1{ 2 "jira-prepare-commit-msg": { 3 "isConventionalCommit": true 4 } 5}
NOTE: For description will be applied messagePattern
If the configuration is:
1{ 2 "jira-prepare-commit-msg": { 3 "messagePattern": "[$J] $M", 4 "isConventionalCommit": true 5 } 6}
and commit message is fix(test)!: important changes
then at result will be fix(test)!: [JIRA-1234] important changes
Additionally, you can customize the conventional commit format with the following setting:
1{ 2 "jira-prepare-commit-msg": { 3 "conventionalCommitPattern": "^([a-z]+)(\\([a-z0-9.,-_ ]+\\))?!?: ([\\w \\S]+)$" 4 } 5}
The above regular expression is the default conventional commit pattern so, if you don't provide this property, jira-prepare-commit-msg
will use this by default.
In the default regular expression, from left to right:
([a-z]+)
is the commit type
.(\\([a-z0-9.,-_ ]+\\))?!?
is the commit scope
.([\\w \\S]+)
is the commit subject
.With this setting you can change how jira-prepare-commit-msg
reads your custom conventional commit message and rewrite it adding the Jira ticket id.
You can allow the scope to have capital letters adding A-Z to the regular expression above. If the configuration is:
1{ 2 "jira-prepare-commit-msg": { 3 "messagePattern": "[$J] $M", 4 "isConventionalCommit": true, 5 "conventionalCommitPattern": "^([a-z]+)(\\([a-zA-Z0-9.,-_ ]+\\))?!?: ([\\w \\S]+)$" 6 // ^^^ 7 // Now we can use capital letters in the conventional commit scope 8 } 9}
and commit message is "test(E2E): some end-to-end testing stuff
" then at result will be "test(E2E): [JIRA-1234] some end-to-end testing stuff
"
Be aware that if you leave the default conventionalCommitPattern
value (that it not allows capital letters in the commit scope), and the same values for messagePattern
and isConventionalCommit
in the example above, your resulting message will be "[JIRA-1234] test(E2E): some end-to-end testing stuff
". Maybe, this is not the result you are expecting and you can have problems using other tools like commitlint.
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
3 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More@hamosapience/jira-prepare-commit-msg
Husky Git hook to add JIRA ticket ID into the commit message
@healthmatch/jira-prepare-commit-msg
Husky Git hook to add JIRA ticket ID into the commit message
prefix-commit-message
Git hook to extract ID from branch name into commit message
jira-prepare-conventional-commit-msg
Husky Git hook to add JIRA ticket ID into the scope of conventional commit message