Installations
npm install @healthmatch/jira-prepare-commit-msg
Releases
Unable to fetch releases
Developer
bk201-
Developer Guide
Module System
Unable to determine the module system for this package.
Min. Node Version
>=10.13
Typescript Support
No
Node Version
12.18.3
NPM Version
6.14.6
Statistics
118 Stars
827 Commits
37 Forks
3 Watching
8 Branches
9 Contributors
Updated on 29 Oct 2024
Languages
TypeScript (95.08%)
JavaScript (4.92%)
Total Downloads
Cumulative downloads
Total Downloads
85,410
Last day
-69.6%
21
Compared to previous day
Last week
-51.2%
235
Compared to previous week
Last month
-30.7%
764
Compared to previous month
Last year
38.5%
16,836
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
jira-prepare-commit-msg
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.
Why?
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!
Installation
Install the package using NPM
1npm install husky jira-prepare-commit-msg --save-dev && npx husky install
For Husky 5+
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'
For Husky 2-4
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}
Configuration
Starting with v1.3 you can now use different ways of configuring it:
jira-prepare-commit-msg
object in yourpackage.json
.jirapreparecommitmsgrc
file in JSON or YML formatjira-prepare-commit-msg.config.js
file in JS format
See 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}
Supported message pattern
jira-prepare-commit-msg
supports special message pattern to configure where JIRA ticket number will be inserted.
- Symbols
$J
will be replaced by the JIRA ticket number - Symbols
$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}
Examples
[$J] $M
[$J]-$M
$J $M
NOTE: the supplied commit message will be cleaned up by strip
mode.
Replacing all occurrences
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}
Examples
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
Supported JIRA ticket pattern
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 comment char
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}
Allow empty commit message
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}
Git root
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');
Ignoring branches
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]+$
Silently ignore any branch that does not have a jira ticket in it
Be silent and skip any branch with missing jira ticket
1{ 2 "jira-prepare-commit-msg": { 3 "ignoreBranchesMissingTickets": true 4 } 5}
Conventional commit
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
Examples
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 committype
.(\\([a-z0-9.,-_ ]+\\))?!?
is the commitscope
.- And
([\\w \\S]+)
is the commitsubject
.
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.
Examples
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.
TODO
- Support user patterns
- Support configuration (package.json)
- Lint
- Tests
- Test for configuration
- Don't clear commit message
License
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
3 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
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
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 30 are checked with a SAST tool
Score
3
/10
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 MoreOther packages similar to @healthmatch/jira-prepare-commit-msg
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
@hamosapience/jira-prepare-commit-msg
Husky Git hook to add JIRA ticket ID into the commit message
jira-prepare-conventional-commit-msg
Husky Git hook to add JIRA ticket ID into the scope of conventional commit message