-
Notifications
You must be signed in to change notification settings - Fork 913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: print commit message when the message is invalid #302
feat: print commit message when the message is invalid #302
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thanks! Some comments, let me know what you think.
@@ -4,13 +4,23 @@ import parse from '@commitlint/parse'; | |||
import implementations from '@commitlint/rules'; | |||
import entries from 'lodash.topairs'; | |||
|
|||
const buildCommitMesage = ({header, body, footer}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand what this is intended to solve, could you drop some lines about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, so I've added this function so that on @commitlint/cli
package it can print a parsed commit message (meaning, without comments or other parser configs). So, with this "helper", the string returned on the lint object contains the commit message (header, body, footer combined, if they are valid strings).
If you don't agree with this implementation or you see a better way of doing this, please let me know to see what I can improve 🙂
@commitlint/lint/src/index.test.js
Outdated
@@ -31,10 +31,13 @@ test('negative on stub message and broken rule', async t => { | |||
}); | |||
|
|||
test('positive on ignored message and broken rule', async t => { | |||
const actual = await lint('Revert "some bogus commit"', { | |||
const message = 'Revert "some bogus commit"'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those changes are unrelated, please revert them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes reverted.
73171e9
to
6ac65d0
Compare
When using the CLI, if the message is invalid we lose all its content (using a custom message in VIM mode), which might be a little frustrating when we a have a long commit body. This feature prints the full message when there are linting errors. Closes conventional-changelog#222
6ac65d0
to
5a75986
Compare
what do you guys think about also adding a small "header" so that if it's integrated in the CI or in a hook, it display smth like : |
const input = | ||
report.errors.length > 0 | ||
? `\n${report.input}\n` | ||
: message.split('\n')[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not print the entire input
always? Seems good info even when the commit is successful...
const input = `\n${report.input}\n`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On #222, I have proposed to only print the full message when an error occurs, because if your input passes on commitlint, you can always amend it but, if the input validation fails, then you lost all the commit text, making sense to print the message. This way, you can copy the message and fix the highlighted issues in it, before making a new commit.
However, if more people agree to show the full input, I can change it. @marionebl, what are your thoughts about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dnamorim totally agree that printing the entire message on error is definitely a must, for the exact reason you've mentioned. Just mentioning that printing the entire message on success can be nice too, @marionebl thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's stay with the printing input only on error, but revisit printing it always later.
Thanks, will publish a release tomorrow. |
Print the full commit message when the input message is invalid.
Description
On
@commitlint/cli
when a commit message has validation errors, it prints the full commit message, returned by the lint function, otherwise, it prints just the commit header, just like before.On
@commitlint/lint
, the return object returns the input parsed (useful for delete comments on editors like vim).Motivation and Context
Currently, when using the CLI, if the message is invalid we lose all its content (using a custom message in VIM mode), which might be a little frustrating when we a have a long commit body, so it would be nice if we show the previous message after the linting errors.
Closes #222
Usage examples
For an invalid message
git commit
Output is:
For a valid message
git commit
Output is:
How Has This Been Tested?
Added unit tests on
@commitlint/lint
ensuring that:Added unit tests on
@commitlint/cli
to ensure the different type of outputs valid/invalid scenarios, with small or big commit messages.Functional testing by using the commit command of the mono-repo.
Types of changes
Checklist: