-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
repos: | ||
- repo: https://github.com/ccoVeille/mockery | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
rev: v2 | ||
hooks: | ||
- id: generate-mocks |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,9 @@ | ||||||||||||
--- | ||||||||||||
- id: generate-mocks | ||||||||||||
name: generate mocks | ||||||||||||
description: Generate mocks with mockery | ||||||||||||
language: golang | ||||||||||||
additional_dependencies: | ||||||||||||
- github.com/vektra/mockery/v2@latest | ||||||||||||
entry: mockery | ||||||||||||
Comment on lines
+6
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Also, we may only want this hook to run when
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 |
||||||||||||
pass_filenames: false |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -28,6 +28,32 @@ Generate all the mocks for your project: | |||||
|
||||||
docker run -v "$PWD":/src -w /src vektra/mockery --all | ||||||
|
||||||
### pre-commit | ||||||
|
||||||
Add the following lines to your `.pre-commit-config.yaml` file | ||||||
|
||||||
```yaml | ||||||
repos: | ||||||
- repo: https://github.com/ccoVeille/mockery | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
rev: v2 | ||||||
ccoVeille marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
hooks: | ||||||
- id: generate-mocks | ||||||
``` | ||||||
|
||||||
!!! note | ||||||
|
||||||
If the file is missing, you can simply create it with this content | ||||||
|
||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Ah, this is why you have it as There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
``` | ||||||
|
||||||
It will install everything. And from now, your commit will trigger mock generation. | ||||||
|
||||||
More information about pre-commit can be found on [pre-commit.com/](https://pre-commit.com/) | ||||||
|
||||||
### Homebrew | ||||||
|
||||||
Install through [brew](https://brew.sh/) | ||||||
|
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