Solvedcommitlint How to validate github issues / jira issues

Hey,
i am currently looking into how i could validate that a commit msg does include a github issue number or a jira issue number.
We currently do this with validate-commit-msg
since that package is supposed to be deprecated i was wondering how i am supposed to do something similar with commitlint.

21 Answers

✔️Accepted Answer

Is it also possible to configure so that this would be accepted:

PROJ-1 feat(users): add model

Other Answers:

You can do this via the references-empty rule

// commitlint.config.js
module.exports = {
  'references-empty': [2, 'never']
};

This checks for the presence of any "reference", which depends on conventional-commit-parser settings. Per default this yields:

λ echo "type: subject" | commitlint
   input: type: subject
   references may not be empty [references-empty]
   found 1 problems, 0 warnings

λ echo "type: subject #1" | commitlint
   input: type: subject #1
   found 0 problems, 0 warnings

When validating JIRA ticket numbers you'll want to configure an issuePrefix:

// commitlint.config.js
module.exports = {
  parserPreset: {
    parserOpts: {
      issuePrefixes: ['PROJ-']
    }
  },
  'references-empty': [2, 'never']
};

This create the following results:

λ echo "type: subject" | commitlint
   input: type: subject
   references may not be empty [references-empty]
   found 1 problems, 0 warnings

λ echo "type: subject #1" | commitlint
   input: type: subject #1
   references may not be empty [references-empty]
   found 1 problems, 0 warnings

λ echo "type: subject PROJ-1" | commitlint
   input: type: subject PROJ-1
   found 0 problems, 0 warnings

This question crops up often enough to warrant documentation.
Thinking about creating a "Common use cases" page.

@cevatkerim rules definitions have to be wrapped into a rules, parserPreset must be inside parserOpts:

// commitlint.config.js
module.exports = {
  parserPreset: {
    parserOpts: {
      issuePrefixes: ['PROJ-']
    }
  },
  rules: {
    'references-empty': [2, 'never']
  }
};
echo "type: subject" | commitlint
   input: type: subject
   references may not be empty [references-empty]
   found 1 problems, 0 warnings

echo "type: subject PROJ-1" | commitlint
   input: type: subject PROJ-1
   found 0 problems, 0 warnings

@Anzumana @belamrani @mebibou I created a plugin and a config special for JIRA commit messages style commitlint-jira

Related Issues:

12
commitlint How to validate github issues / jira issues
Is it also possible to configure so that this would be accepted: Hey ...
11
commitlint core: multiple scopes in commit message
Thanks for the quick reply @marionebl :) For a lerna project with the following packages: Current Be...
9
commitlint [input] is required: supply via stdin, or --env or --edit or --from and --to
I hope this helps with identifying the issue If you explicitly specify the default value it works as...
339
husky Can't find Husky, skipping pre-commit hook
I was able to fix this issue with: yarn in v1.6.0 husky installed information: config in .huskyrc I ...
145
husky husky with sourcetree : Can't find node in PATH, trying to find a node binary on your system
I was experiencing this error with NVM & WebStorm (while everything was fine from the Ubuntu termina...
101
husky Command "husky-run" not found.
Try yarn husky install Just have upgraded from v4.3.8 to v5.0.9 and got the error have tried to unin...
36
husky husky is using some strange node version when running hooks
The fix for node v10 is to update lint-staged to ^7.0.5: or First problem husky is using npm when I'...
24
husky Bug commit from vscode
I use VS Code and Husky v6 I ran echo $PATH from the root of my project Then I copied the output to ...
22
husky Husky v5 and Gitkraken
@adriankwiat you can try shx for cross-platform: Disclaimer This is no longer an issue since Gitkrak...
16
husky Can't find Node.js installed with NVM, when used in VS Code
Looks like adding a ~/.huskyrc file with: Stops VS Code from committing and allows husky to continue...
15
conventionalcommits.org What about work in progress commits
I came across this as an open source maintainer and agree with @rikhoffbauer examle: i'm work on fea...
15
husky Git LFS and husky prepush hook?
To summarize suggestions by @jmchambers and @Fandekasp I just tried to husky a prepush script and no...
15
husky Problem with the pre-push git hook
As @soda0289 pointed out it was missing a A new version (4.0.10) has been released with the fix Than...
12
husky hook fails as it assumes yarn will be available in $PATH
There's a similar issue when using husky with SourceTree Getting an error: This error can't be fixed...
8
husky git commit hooks never get created when husky v5 is installed
Hi @DouglasDev It's normal behaviour with v5 You need to run npx husky install and create hooks with...
570
desktop The user name or passphrase you entered is not correct.
It sure looks like something's screwy with Keychain Try opening Keychain Access.app ...
381
git lfs Encountered 1 file(s) that should have been pointers, but weren't
Run git lfs uninstall and then git reset --hard (assuming there are no changes you want to keep!) On...
356
desktop Could not resolve host: github.com
Check this out as well it helped me. Description I create a new repository in my local and complete ...
322
desktop It keeps saying The user name or passphrase you entered is not correct.
@tom10271 we think this is related to Keychain access due to some sort of macOS update: Try opening ...
230
git lfs Simple steps to uninstall Git LFS from your repository
Thanx that helped me a lot while I was migrating from BitBucket to AWS CodeCommit ...
226
git lfs git-lfs aborts with "LFS: Git credentials for https://XXX not found." even for repositories without passwords
In my case on Windows using gitbash I had to use: git config --global credential.helper wincred ...
219
desktop A lock file already exists in the repository, which blocks this operation from completing.
@simhox thank you for updating the issue body and uploading the log file! Here's the related error: ...
133
desktop Improve ease of configuring Git to work with corporate proxy
@DanielKeogh currently you still need to tell Git about your proxy settings: git config --global htt...
109
desktop fatal: unable to access 'https://github.com/': Could not resolve proxy: aproxy
Run the below command git config --global --unset http.proxy Description [Description of the issue] ...
104
nodegit Can't install via NPM
Latest Xcode just straight up broke things all across the world Try running sudo xcode-select --inst...
95
git lfs installation in ubuntu is not working
Running the following command looks to have fixed this issue for me: Trying the instruction: yields ...
89
desktop reference broken
@herio5154 thanks for the feedback! It looks like something with the underlying Git repository has b...
83
desktop Feature Request: Graph history view
IMO full tree is too complex and we should decide the main reason to add this feature ...
82
desktop Commit failed error with GPG signing turned on
In case it helps someone the workaround I'm using for now is to disable gpg signing with a repositor...
77
git lfs git lfs issue even after adding the file
Hi @kamlekar thanks for opening this issue and I'm sorry that you're having some trouble! Here's my ...
75
gitsome Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-7SrToZ/gitsome/
I had the same problem on OSX and Solve my issue (I have both python versions installed). ...
71
git lfs Authentication required : You must have push access to verify locks error.
I'm trying to help you skip the pre-push hook You inadvertently re-installed it :) Try this: Sorry a...
71
bat Ubuntu install error when rg is installed also
As a workaround one can use sudo apt install -o Dpkg::Options::=--force-overwrite bat ripgrep (taken...
69
lint staged Build typescript on commit
hi I know this is an already closed issue but I still ran into it I'm trying to rebuild my typescrip...
62
pre commit python3.7: command not found
Just adding this here for anyone that comes across this issue When you create a virtualenv using for...
61
lint staged No staged files match src/**/*.{ts,tsx}
I solved my problem I had a space in between ts and tsx change in .lintstagedrc.json from *.{ts tsx}...
60
bfg repo cleaner Just write how to install it.
@srugano I agree I had no idea how to properly install it Luckily I found it on homebrew so I instal...
59
patchwork remote Permission to jlord/patchwork.git denied returned error: 403
When you get a 403 on this challenge it is because you are trying to push your changes to a reposito...
51
desktop "Warning: line endings have changed from 'LF' to 'CRLF'." when files have LF line endings on Windows
@stuartpb Isn't configuration from Github Desktop you using Windows Git assumes CRLF but your text e...
47
desktop Authentication Failed
Experienced this issue with a Bitbucket SSH URL changing to a https URL in the Repository Settings f...
45
cli Ability to configure a default editor for use with gh
I think it would make most sense to honour GIT_EDITOR since that is likely what people will have set...
45
44
git lfs cannot spawn .git/hooks/pre-push: No such file or directory
Cool glad you got it working What ended up being the solution? my solution was git lfs update --forc...
44
git lfs Force pushes can lead to "bad object" message from git rev-list
You can run git fetch to fetch from the remote first. Describe the bug When force-pushing a ref to a...
41
desktop Github Desktop version 1.0.12 Authentication Failed during fetch with remote
Goto File > Options > Sign Out and Sign In again It works for me. Description After upgrading to the...
41
lint staged lint-staged ignores tsconfig.json when it called through husky hooks
Similar issue with tsc Passing files AND project config is not possible When invoked from husky ...
37
netlify cms Support for multilingual content authoring
So I can see from #2988 that we're still looking for UI/UX solutions on this Thanks @barthc for the ...
36
git lfs Object does not exist on the server
For anyone in a situation where git lfs thinks everything is dandy but repos are spouting Object doe...
35
desktop file too large, but can't remove it
This worked for me: A simple solution I used: Do git reset HEAD^ for as many commits you want to und...
35
vscode gitlens GitLens disables merging CodeLens
Hey guys So after long searching with trying i may discovered the reason of disabled options for the...