From 9ca94756e5589cb7fe8e0cfc4ebed9444ae8b1e0 Mon Sep 17 00:00:00 2001 From: jamesread Date: Fri, 19 Nov 2021 15:09:02 +0000 Subject: [PATCH] cicd: Require commit messages are tagged --- .githooks/commit-msg | 28 ++++++++++++++++++++++++++++ Makefile | 5 ++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100755 .githooks/commit-msg diff --git a/.githooks/commit-msg b/.githooks/commit-msg new file mode 100755 index 0000000..a04c605 --- /dev/null +++ b/.githooks/commit-msg @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 + +import sys + +commitmsg = "" + +with open('.git/COMMIT_EDITMSG', mode='r') as f: + commitmsg = f.readline().strip() + +print("Commit message is: " + commitmsg) + +ALLOWED_COMMIT_TYPES = [ + "cicd", + "typo", + "fmt", + "doc", + "bugfix", + "security", + "feature", +] + +for allowedType in ALLOWED_COMMIT_TYPES: + if commitmsg.startswith(allowedType + ":"): + print("Allowing commit type: ", allowedType) + sys.exit(0) + +print("Commit message should start with commit type. One of: ", ", ".join(ALLOWED_COMMIT_TYPES)) +sys.exit(1) diff --git a/Makefile b/Makefile index 281f754..6834ffd 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,9 @@ daemon-unittests: mkdir -p reports go test ./... -coverprofile reports/unittests.out go tool cover -html=reports/unittests.out -o reports/unittests.html + +githooks: + cp -v .githooks/* .git/hooks/ go-tools: go install "github.com/bufbuild/buf/cmd/buf" @@ -31,7 +34,7 @@ go-tools: go install "google.golang.org/grpc/cmd/protoc-gen-go-grpc" go install "google.golang.org/protobuf/cmd/protoc-gen-go" -grpc: go-tools +grpc: githooks go-tools buf generate podman-image: