How to handle long URLs in commit messages
See original GitHub issueExpected Behavior
I want to be able to add links with long URLs (over 100 characters) to the footer so that I’ll be able to adjust the footer line length in my own rules, while still assuring that the commit message body will be formatted consistently.
Alternatively there should be another way to add long urls to commits without having to minify them, while still adhering to the commit message max-line-length rules.
Current Behavior
It is impossible to create a commit containing a long url (over 100 characters), with the default config without minifying it. I would prefer not to minify the URL as depending on the minification service the minified URL might not be online as long and I could potentially lose context information from the actual URL, which I can only find out by following the minfied one.
Putting a long URL in the body on a single line only works by adjusting the body-max-line-length
rule, reducing the usefulness of the configuration.
Example
docs(adl): commit message style convention
asserted by commitlint to [angular commit style]
https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional#type-enum
according to the conventional commits convention.
Putting the URL as a markdown link in the footer does not work while adjusting footer-max-line-length
to Infinity
as it is recognized not as the footer, but as part of the body.
Example
docs(adl): commit message style convention
asserted by commitlint to [angular commit style] according to the
conventional commits convention.
[angular commit style]: https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional#type-enum
results in
husky > pre-commit (node v12.18.2)
✔ Preparing...
✔ Running tasks...
✔ Applying modifications...
✔ Cleaning up...
husky > commit-msg (node v12.18.2)
⧗ input: docs(adl): commit message style convention
asserted by commitlint to [angular commit style] according to the
conventional-commits convention
[angular-commit-style]: https://github.com/conventional-changelog/commitlint/tree/master/@commitlint/config-conventional
✖ body's lines must not be longer than 100 characters [body-max-line-length]
✖ found 1 problems, 0 warnings
ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
husky > commit-msg hook failed (add --no-verify to bypass)
This seems to be due to the conventional-commit-parser package only recognizing the footer by usage of either “BREAKING CHANGE:” or supplying some issue number link “#333”.
I found this out by saving the above commit message to a test.txt
file and running the parser over it resulting in:
[
{
"type":"docs",
"scope":"adl",
"subject":"commit message style convention",
"merge":null,
"header":"docs(adl): commit message style convention",
"body":"asserted by commitlint to [angular commit style] according to the\n[conventional commits] convention.\n\n[angular commit style]: https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional#type-enum",
"footer":null,
"notes":[],
"references":[],
"mentions":[],
"revert":null
}
]
Affected packages
- parse
- config-angular
Possible Solution
A solution could be to supply the conventional-commits-parser with a regex for specific noteKeywords.
Another solution could be to introduce an option to somehow ignore single line urls in the body of commit messages from the testing of body-max-line-length
rule.
But my question would also be how others normally add URLs to commit messges. Do you just always minify them?
Issue Analytics
- State:
- Created 3 years ago
- Comments:9
Top GitHub Comments
IMHO this isn’t really resolved, because
noteKeywords
is undocumented AFAICS.I think it would be nicer if it could just spot long URLs and understand that they need to be on a single line and therefore an exception to
body-max-line-length
. The above workaround definitely seems like a case of the human having to uncomfortably adapt to the whims of the machine, whereas good tooling should work the other way around.Here is my 2c for what it’s worth.
Forgive me because I am not sure if
[angular commit style]
is a static string or if that is contextual based on the current commit. If it’s static and you are always going to use that then you could easily just pass in the former as a parser option.In which case the following parses correctly:
If
[angular commit style]
changes then you might need to create a keyword such that you can recognise the start of a footer. Such aslink
, orlinks
:Then you could just append the word
link
to your footer whenever you need to list a footer.Then when you need a link you can simpy do the following:
I would note though in both scenarios I have had to disable the footer line length because that line (without the link keyword appended) is longer than 100 characters anyway. So if you’re going to disable line length somewhere I think it’s a trade off between how much you want to control the body length vs how much you force a particular commit style for footers.