-
Notifications
You must be signed in to change notification settings - Fork 418
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
.pre-commit-hooks.yaml
Outdated
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
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 |
Hi @ccoVeille, just wondering if you are back from the Christmas break? Please let me know if I can help with anything! |
943dcde
to
3b14ef9
Compare
Thanks for the reminder. Winter break was indeed a great period. Please let me know, if you think it's OK now. |
@sx-klaviyo In order to test locally, please use the following set up Add the following lines to your repos:
- repo: https://github.com/ccoveille-forks/vektra-mockery
rev: v2 # This is a mutable reference to the latest version
hooks:
- id: generate-mocks Then test the other ones repos:
- repo: https://github.com/ccoveille-forks/vektra-mockery
rev: v2 # This is a mutable reference to the latest version
hooks:
- id: generate-mocks-local Both should work, I created a fake 2.51.1 tag Please check and let me know. |
Thank you for the instructions! I believe the - repo: https://github.com/ccoveille-forks/vektra-mockery
rev: v2.51.1-alpha # by explicitly using the tag that you created
hooks:
- id: generate-mocks Using |
I had to test a lot to finally find why I worked in a branch in my fork, but here is what the documentation of pre-commit says: https://pre-commit.com/#updating-hooks-automatically
I had to switch the default branch of my fork to be the one of my PR ... so the tag I created would be the one precommit looks for. Now everything works as expected. Please check by following steps: repos:
- repo: https://github.com/ccoveille-forks/vektra-mockery
rev: v2
hooks:
- id: generate-mocks Then $ pre-commit install
$ pre-commit autoupgrade Then try to commit a Go file Then proceed with the exact same steps with repos:
- repo: https://github.com/ccoveille-forks/vektra-mockery
rev: v2
hooks:
- id: generate-mocks-local Then $ pre-commit install
$ pre-commit autoupgrade Then try to commit a Go file And it should be OK (famous last words) Please let me know @sx-klaviyo and even @liveFreeOrCode So much time lost because of the "last tag from the default branch" joke. It's logic, But it's a pain to spot. I might open a bug report/feature request on pre-commit code |
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