From 70fbf5307a623f18d0de8a57a0616d1890a7ae1c Mon Sep 17 00:00:00 2001 From: Dion Date: Wed, 22 Nov 2023 13:48:32 +1100 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20add=20godoc-hl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-hooks.yaml | 7 +++++++ run-go-dochl.sh | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100755 run-go-dochl.sh 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