diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 7c27e1c..610e5c5 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -60,3 +60,10 @@ files: '\.go$' language: "script" description: "Runs `go-ruleguard`, install https://github.com/quasilyte/go-ruleguard" + +- id: go-dochl + name: "go-dochl" + entry: run-go-dochl.sh + files: '\.go$' + language: "script" + description: "Runs go-dochl, to extract comment before commit" diff --git a/run-go-dochl.sh b/run-go-dochl.sh new file mode 100755 index 0000000..2829a35 --- /dev/null +++ b/run-go-dochl.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +if ! command -v go-dochl 2>&1 /dev/null +then + echo "Error: go-dochl not found. Please install it by running 'go get -u github.com/diontr00/dochl@latest' and ensure it is in your PATH." + exit 1 +fi + +KEY="$1" + +# Run dochl with provided arguments or default +dochl_output=$(go-dochl -keys="$KEY" "$@") + +# Check if dochl found any matching comments +if [ -n "$dochl_output" ]; then + echo "You have work todo. Commit rejected." + go-dochl -keys="$KEY" "$@" + exit 1 +else + exit 0 +fi