From df6b998e07e977d3f69709324843659d92a66a03 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-config.yaml | 6 ++++++ .pre-commit-hooks.yaml | 9 +++++++++ docs/installation.md | 26 ++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 .pre-commit-config.yaml create mode 100644 .pre-commit-hooks.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..1e269e35 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,6 @@ +--- +repos: + - repo: https://github.com/ccoVeille/mockery + rev: v2 + hooks: + - id: generate-mocks \ No newline at end of file diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml new file mode 100644 index 00000000..3f6667d7 --- /dev/null +++ b/.pre-commit-hooks.yaml @@ -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 + pass_filenames: false diff --git a/docs/installation.md b/docs/installation.md index 8dcb10d3..51054ad8 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -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 + rev: v2 + 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 +``` + +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/)