From f0890a91db3829e8d802abe56b384edc32ddedd6 Mon Sep 17 00:00:00 2001 From: ccoVeille <3875889+ccoVeille@users.noreply.github.com> Date: Wed, 17 Jul 2024 11:46:44 +0200 Subject: [PATCH] feat: add pre-commit hook support Fixes #791 --- .pre-commit-hooks.yaml | 16 ++++++++++++++++ docs/installation.md | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 .pre-commit-hooks.yaml diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml new file mode 100644 index 00000000..3008a00b --- /dev/null +++ b/.pre-commit-hooks.yaml @@ -0,0 +1,16 @@ +--- +- id: generate-mocks + name: generate mocks + description: Generate mocks with mockery + language: golang + entry: go run . + types: [go] + pass_filenames: false + +- id: generate-mocks-local + name: generate mocks with local mockery + description: Generate mocks with local mockery + language: system + entry: mockery + types: [go] + pass_filenames: false \ No newline at end of file diff --git a/docs/installation.md b/docs/installation.md index 8dcb10d3..95d8ab81 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -32,8 +32,45 @@ Generate all the mocks for your project: Install through [brew](https://brew.sh/) - brew install mockery - brew upgrade mockery +```shell +brew install mockery +``` + +Upgrade to the latest version + +```shell +brew upgrade mockery +``` + +### pre-commit + +Add the following lines to your `.pre-commit-config.yaml` file + +```yaml +repos: + - repo: https://github.com/vektra/mockery + rev: v2 # This is a mutable reference to the latest version + 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: + +```console +# This one will report a warning about mutable reference +$ pre-commit install + +# This one will fix the warning +$ pre-commit autoupdate +``` + +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/)