Closed TanKucukhas closed 4 years ago
Hi, would you mind checking if this is a duplicate of #1009 or #1016? Thanks
Thanks @escapedcat , I've seen these. My case is a little different I don't want user to input the id. Instead, I want to append fixed text to the commit automatically.
I see. Uhm, not to question your usecase but to understand it a bit better. Where would should the ticket-number come from?
Could it be enough to add a rule that checks if a ticket number is added? In that case a commit message might look like this though:
fix: bla bla bla [ABCD-10]
Would that be an issue? If yes, why?
I might have a unique use case. We have a couple of different projects and each project needs to have their own JIRA ticket, and not per commit. So for each project, I needed to append the same JIRA ID for all of the commits coming from the same project. Doing that, developers won't need to do manual work of adding the same ticket id all the time. Meanwhile, we wanted to still have some rules in place to commit a message, so that you can't push a commit without a type and subject. I have used @commitlint/config-conventional
for the job.
I am actually able to do this with the help of a shell script.
package.json
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS && ./commit-hook.sh ${HUSKY_GIT_PARAMS} 'JIRA-10'"
}
},
commit-hook.sh
#!/bin/sh
## grab original message from .git/COMMIT_EDITMSG
ORIGINAL_COMMIT=$(cat "../../$1")
## grab Jira ID from second parameter of ./commit-hook.sh ${HUSKY_GIT_PARAMS} 'JIRA-#'"
JIRA_ID="$2"
## add Jira ID to the beginning and replace .git/COMMIT_EDITMSG
echo "$JIRA_ID $ORIGINAL_COMMIT" > "../../$1"
since the shell script runs after commitlint it does not get checked and you can do push afterward without problem
for instance:
if you commit "fix: message"
passes the validation but when you do push, you'll see Jira ticket prepended automatically to your commit message JIRA:10 fix: message
Thanks, that helped! Not sure if this should be part of the scope of commitlint.
So if the script works for you we might be good here?
@escapedcat thanks for taking the time. You are right, it is more likely scope for Husky or even Githooks. We can close.
I have multiple projects with different Jira numbers. So in my project, I only want the user to commit a message following @commitlint/config-conventional rules.
I could not find anything on documentation that can help my case, is this possible using the setup below?
Expected Behavior
fix: bla bla bla
should pass but actual commit should be[ABCD-10] fix: bla bla bla
bla bla bla
should fail[ABCD-10] bla bla bla
should fail[ABCD-10 fix: bla bla bla
should failCurrent Behavior
fix: bla bla bla
passes but I'm unable to append my prefix before the commit pushesAffected packages
Possible Solution
A way to prepend, append fixed or dynamic text
Steps to Reproduce (for bugs)
see below setup
Context
Your Environment
commitlint --version
git --version
node --version