Browse Source

cicd: Require commit messages are tagged

jamesread 4 years ago
parent
commit
9ca94756e5
2 changed files with 32 additions and 1 deletions
  1. 28 0
      .githooks/commit-msg
  2. 4 1
      Makefile

+ 28 - 0
.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)

+ 4 - 1
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: