-
-
Notifications
You must be signed in to change notification settings - Fork 301
Report hook installation fail #578
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
Report hook installation fail #578
Conversation
Codecov ReportBase: 97.92% // Head: 98.03% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@ ## master #578 +/- ## ========================================== + Coverage 97.92% 98.03% +0.10% ========================================== Files 35 39 +4 Lines 1252 1676 +424 ========================================== + Hits 1226 1643 +417 - Misses 26 33 +7
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
I found that TestPreCommitCases has some duplicated code. Should they be extracted to methods?
Yep that would be great
c81ad48
to
ca08c91
Compare
@Lee-W I think it's ready to be reviewed.
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.
Hi @Bogay sorry for the late review. Just one minor design issue I'd like to discuss. Others are just minor nitpick. You could fix it if you have time. Otherwise we could do that in the future. We're almost ready for this merge!
commitizen/commands/init.py
Outdated
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 think we should put the following code into _exec_install_pre_commit_hook
. This seems to be the responsibility of that function. @Bogay what do you think?
raise InitFailedError( "Installation failed. See error outputs for more information." )
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.
Yeah, I think that's reasonable. We can let _install_pre_commit_hook
raise an exception instead of return a bool
.
Maybe we can just put all error message inside the InitFailedError
so that we don't need extra out.error
calls?
This is what the error output looks like:
圖片
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.
Yep, that sounds great!
commitizen/commands/init.py
Outdated
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.
nitpick: missing return type anntation
commitizen/commands/init.py
Outdated
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.
nitpick: I might suggest invoke one out.error
and concatenation the string instead.
commitizen/commands/init.py
Outdated
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 found that I forgot to add a space between --hook-type
options...
@Lee-W Do you have any idea how to write tests for this?
Because it depends on pre-commit
's behavior, it's harder to test.
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.
we could verify whether the code generate the pre-commit command we want. e.g., mock the caller function of cmd_str
to check
@Lee-W it's done 👍
instead of returning a `False` value.
there should be a space between `--hook-type` options in generated `pre-commit` command string.
df02f29
to
a23ef07
Compare
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.
Uh oh!
There was an error while loading. Please reload this page.
Description
This PR make
cz
report errors if user want to install pre-commit hook and failed, which fixs #428.Checklist
./scripts/format
and./scripts/test
locally to ensure this change passes linter check and testExpected behavior
Run
cz init
will print error if there is something wrong.And the exit code should not be 0.
Steps to Test This Pull Request
Additional context
I found that
TestPreCommitCases
has some duplicated code. Should they be extracted to methods?