-
Notifications
You must be signed in to change notification settings - Fork 414
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: add pre-commit hook support #795
base: master
Are you sure you want to change the base?
Conversation
additional_dependencies: | ||
- github.com/vektra/mockery/v2@latest | ||
entry: mockery |
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.
Rather than using additional_dependencies, the pre-commit-hook will already have access to the file system. We should just be able to use go run .
to enact the mockery ...
command I believe.
Also, we may only want this hook to run when .go
files are in the commit. What do you think?
additional_dependencies: | |
- github.com/vektra/mockery/v2@latest | |
entry: mockery | |
entry: go run . | |
files: \.go$ |
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'm unsure it will launch the code you expect to run.
I will make some tests.
But, I think keeping mockery call here would be clearer.
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.
Using additional dependencies like this won't allow people to specify version in pre commit file because no matter what version they reference, you're pulling latest
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.
Indeed, I'm unsure if there is something that can be done here, I will have to check
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.
For now,it seems to me, that it would imply to maintain the version in sync in this file vs the tag. Quite a pain
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.
Is it possible let the users assume the responsibility for installing mockery? If that's the case this should suffice
---
- id: generate-mocks
name: generate mocks
description: Generate mocks with mockery
language: golang
entry: mockery
pass_filenames: false
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.
Yes, of course, it makes sense.
But then having 2 rules could be a something to consider
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 your approach is the most commonly used in fact
https://github.com/search?q=path%3A%22%2F.pre-commit-hooks.yaml%22+golang&type=code
@@ -0,0 +1,6 @@ | |||
--- | |||
repos: | |||
- repo: https://github.com/ccoVeille/mockery |
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.
Is this just in here for testing right now? Unless mockery uses itself to generate mocks, and wants to use the pre-commit functionality, I don't think this is required to get this to work for consumers.
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.
Yes, only for the test. I forgot to mention about it in the PR
I had to create a fake "2.43.3" tag on my repository to be able to make it work.
|
||
```yaml | ||
repos: | ||
- repo: https://github.com/ccoVeille/mockery |
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.
- repo: https://github.com/ccoVeille/mockery | |
- repo: https://github.com/vektra/mockery |
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 kept it in sync to help mockery mainteners to be able to test
But yes, I will have to change this one
Then install the hook with the following command: | ||
|
||
```shell | ||
pre-commit autoupdate |
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.
Ah, this is why you have it as v2
above, calling for autoupdate will which bump the version to latest. May be better to be explicit about the versioning system, and call for pre-commit install
versus autoupdate.
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.
Indeed, I'm used to use autoupdate for everything.
I think "pre-commit install" would also bump it locally. I will make some tests.
Then I will update the documentation based on my tests
@@ -0,0 +1,6 @@ | |||
--- |
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.
Note for myself
I will have to add Co-Authored-By metadata
anyway @liveFreeOrCode could you confirm it "works" as this ? |
@liveFreeOrCode (or anyone) could you confirm ? thanks Then I will remove the oddities present to make it works with my branch, and switch to vektra/mokery one |
You commented the PR, thanks. But you didn't reply my question. Does it work on your computer now with current code I provided. I understand you might dislike the current implementation. I agree it could be improved. But right now,I would like to get a simple reply to the following question. Does it work? |
Yeah sorry I'm traveling without my PC. I can't test until next week |
OK thanks for replying, we can also wait |
Closing due to inactivity, feel free to resurrect it if you find the time to finish it. |
Please reopen. I was waiting for someone feedbacks. The code is ready. |
I was just searching for |
Just ping me back if nothing happen, I can reopen the PR |
Hi @ccoVeille! Just a reminder that this PR is opened now |
The MR was waiting for people to test since July. @liveFreeOrCode said he would, but he didn't. There are indeed some code reviews that were provided, but before going further and address them, I would like someone to test. The code was supposed to work. I would appreciate it if you could, before I iterate on addressing feedbacks. Because without a tester, it's uneasy to validate things out of my understanding/knowlege |
I'll try to test it this week and let you know! |
@ccoVeille I confirm that your |
Great. Thank you for testing. For records, I'm unsure I will have time to fix that before Christmas break. So be patient |
Description
Add pre-commit.com support in mockery.
Type of change
Version of Go used when building/testing:
How Has This Been Tested?
Locally, by following the guide I provide in installation.md file
Checklist