Przeglądaj źródła

refactor: Switch to conventional scripts, rather than custom script (#535)

James Read 1 rok temu
rodzic
commit
6b9c6c8b9c
4 zmienionych plików z 15 dodań i 40 usunięć
  1. 0 31
      .githooks/commit-msg
  2. 1 1
      .github/PULL_REQUEST_TEMPLATE.md
  3. 14 5
      .pre-commit-config.yaml
  4. 0 3
      Makefile

+ 0 - 31
.githooks/commit-msg

@@ -1,31 +0,0 @@
-#!/usr/bin/env python
-
-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",
-    "test",
-    "refactor",
-    "depbump",
-    "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)

+ 1 - 1
.github/PULL_REQUEST_TEMPLATE.md

@@ -14,7 +14,7 @@ Helpful information to understand the project can be found here: [CONTRIBUTING](
 Please put a X in the boxes as evidence of reading through the checklist.
 
 - [ ] I have forked the project, and raised this PR on a feature branch.
-- [ ] `make githooks` has been run, and my git commit message was accepted by the git hook.
+- [ ] I ran the `pre-commit` hooks, and my commit message was validated.
 - [ ] `make daemon-compile` runs without any issues.
 - [ ] `make daemon-codestyle` runs without any issues.
 - [ ] `make daemon-unittests` runs without any issues.

+ 14 - 5
.pre-commit-config.yaml

@@ -1,10 +1,19 @@
+---
 # See https://pre-commit.com for more information
 # See https://pre-commit.com/hooks.html for more hooks
 repos:
--   repo: https://github.com/pre-commit/pre-commit-hooks
+  - repo: https://github.com/pre-commit/pre-commit-hooks
     rev: v3.2.0
     hooks:
-    -   id: trailing-whitespace
-    -   id: end-of-file-fixer
-    -   id: check-yaml
-    -   id: check-added-large-files
+      - id: trailing-whitespace
+      - id: end-of-file-fixer
+      - id: check-yaml
+      - id: check-added-large-files
+
+  # Alternative semantic commit checker
+  - repo: https://github.com/compilerla/conventional-pre-commit
+    rev: v3.1.0
+    hooks:
+      - id: conventional-pre-commit
+        stages: [commit-msg]
+        args: [] # optional: list of Conventional Commits types to allow e.g. [feat, fix, ci, chore, test]

+ 0 - 3
Makefile

@@ -40,9 +40,6 @@ daemon-unittests:
 it:
 	cd integration-tests && make
 
-githooks:
-	git config --local core.hooksPath .githooks
-
 go-tools:
 	go install "github.com/bufbuild/buf/cmd/buf"
 	go install "github.com/fzipp/gocyclo/cmd/gocyclo"