Skip to content
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

Feature request: pre-commit hooks #791

Open
liveFreeOrCode opened this issue Jul 2, 2024 · 8 comments
Open

Feature request: pre-commit hooks #791

liveFreeOrCode opened this issue Jul 2, 2024 · 8 comments
Assignees

Comments

@liveFreeOrCode
Copy link

liveFreeOrCode commented Jul 2, 2024

PLEASE READ

DO NOT submit tickets without first using the latest version of Golang, clearing your local golang package cache, and re-building mockery using the latest Golang version and the latest version of mockery. Please provide evidence this has been done in your issue. Failure to provide this evidence will likely result in your issue being closed.

Description

It would be nice to have supported pre-commit hooks capable of generating mocks as part of the normal CD process. Currently I accomplish this as a local hook, but that local hook uses my local golang installation, and if I have a mockery version installed already, the "additional_dependencies" won't be honored.

repos:
  - repo: local
    hooks:
      - id: generate-mocks
        name: generate mocks
        language: golang
        additional_dependencies:
          - github.com/vektra/mockery/[email protected]
        entry: mockery
        pass_filenames: false

Mockery Version

latest

Golang Version

go version go1.22.4 linux/amd64

NOTE: Please upgrade to the latest golang version before submitting tickets!
@LandonTClipp
Copy link
Collaborator

Sorry I don't understand the question. Are you asking about git pre-commit hooks?

@ccoVeille
Copy link
Contributor

ccoVeille commented Jul 14, 2024

I recognize the pattern of https://pre-commit.com

So, it's about adding a YAML file to the repository.

I don't think there will be a need to maintain the file on version upgrade. Maybe using @latest would be enough.

I can help if you want. I can open a PR.

I have already set up such a thing.

The only thing I'm worried about is the fact, a pre-commit hooks might generate the mock, but I'm unsure how it could stop the commit.

But maybe, I will find it out by testing, or the author of this issue would give us some explanation.

Said, otherwise I can help in coding, the need is clear to me as I know pre-commit tool. But I'm unsure what author wants to achieve exactly.

Adding the generated mocked file to the commit, prevent the commit when the mocked files are not up to date.

Please note for maintainers of the repository, it won't have much consequence than adding a file to the repository, maybe add a section about it in the documentation.

Only a few people might use the feature, but it's a convenient way for people to use mockery

@ccoVeille
Copy link
Contributor

Please note, the work is almost complete with the YAML file provided by @liveFreeOrCode

So maybe, he is just asking for a GO to code it by himself.

@LandonTClipp
Copy link
Collaborator

Feel free to open a PR. I have never used this tool so I will need education on how this practically speaking will be used by mockery users. I understand the basic concept based on the docs I read of this tool, but perhaps a PR would help solidify the idea for me, in addition to a description of how pre-commit would be configured in a separate repo to pull the YAML config that we will define here.

@ccoVeille
Copy link
Contributor

I will unless @liveFreeOrCode post a message.

@LandonTClipp May I ask you to assign me this issue for now?

@LandonTClipp
Copy link
Collaborator

Assigned, thank you!

ccoVeille added a commit to ccoveille-forks/vektra-mockery that referenced this issue Jul 17, 2024
ccoVeille added a commit to ccoveille-forks/vektra-mockery that referenced this issue Jul 17, 2024
@liveFreeOrCode
Copy link
Author

👋 Hi @ccoVeille. Thank you for taking this on. I usually drop in a feature request first in issues before I start any work to make sure I work out any gotchas with the maintainers, and to see if it's in line with the product's vision. That said, I probably wasn't going to be able to get to this anytime soon, so I do really appreciate you being able to jump on this.

The only thing I'm worried about is the fact, a pre-commit hooks might generate the mock, but I'm unsure how it could stop the commit.

pre-commit will block a commit if any of the hooks modify a file. So once mockery updates or adds a new mock, the pre-commit output will notify the user that this commit hook modified files, and it will stop the commit so the developer can review the changes that were made by mockery.

@ccoVeille
Copy link
Contributor

I remembered it was something like that indeed. But I wasn't sure, and was awaiting a feedback from you to know how you were using the local hook you quoted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants