-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy path.pre-commit-config.yaml
More file actions
86 lines (81 loc) · 3.65 KB
/
Copy path.pre-commit-config.yaml
File metadata and controls
86 lines (81 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
repos:
- repo: local
hooks:
- id: strip-co-authored-by
name: Strip Co-authored-by lines
entry: |-
bash -c '
# With bash -c "script" arg, the commit msg path is $0
tmp=$(mktemp)
grep -vi "co-authored-by:" "$0" > "$tmp"
mv "$tmp" "$0"
'
language: system
stages: [commit-msg]
pass_filenames: true
- id: go-fmt
name: go fmt
entry: bash -c 'go fmt $(go list ./... | grep -v "/migrations" | grep -v "/scripts$")'
language: system
types: [go]
pass_filenames: false
- id: go-mod-tidy
name: go mod tidy
entry: go mod tidy
language: system
types: [go]
pass_filenames: false
- id: go-vet
name: go vet
entry: bash -c 'go vet $(go list ./... | grep -v "/migrations" | grep -v "/scripts$")'
language: system
types: [go]
pass_filenames: false
# - id: golangci-lint
# name: golangci-lint
# entry: golangci-lint run
# language: system
# types: [go]
# pass_filenames: false
- id: conventional-commit-check
name: Conventional Commit Message Check
entry: |-
bash -c '
# With bash -c "script" arg, the commit msg path is $0
COMMIT_MSG_FILE="$0"
FIRST_LINE=$(head -n1 "$COMMIT_MSG_FILE")
# Regex for conventional commit: type(optional_scope)!: subject
# Allowed types: feat, fix, docs, style, refactor, perf, test, chore, ci, build, revert
# Allows an optional scope in parentheses e.g. feat(parser):
# Allows an optional ! for breaking change e.g. feat!:
# Requires a colon and a space after type/scope/!.
# Requires some subject text.
# Use POSIX bracket expressions, not \w/\s: BSD grep (macOS) does
# not honor those GNU/PCRE shorthands, so a scoped subject like
# fix(trigger): ... was wrongly rejected on macOS while passing
# under the GNU grep that CI uses. Avoid apostrophes in this
# block too: pre-commit shlex-parses the single-quoted entry.
PATTERN="^(feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert)(\([[:alnum:]_[:space:]-]+\))?!?:[[:space:]].+"
if ! grep -Eq "$PATTERN" <<< "$FIRST_LINE"; then
echo "-------------------------------------------------------------------"
echo "ERROR: Commit message does not follow Conventional Commits format."
echo "-------------------------------------------------------------------"
echo "It must start with a type like feat, fix, docs, etc.,"
echo "followed by an optional scope in parentheses (e.g. (api), (ui)),"
echo "an optional exclamation mark for breaking changes (!),"
echo "a colon and a single space, and then the subject."
echo ""
echo "Examples:"
echo " feat: add new user authentication feature"
echo " fix(parser): correctly handle empty input"
echo " docs!: update API documentation for breaking change"
echo ""
echo "Allowed types: feat, fix, docs, style, refactor, perf, test, chore, ci, build, revert"
echo "For more details, see: https://www.conventionalcommits.org/"
echo "-------------------------------------------------------------------"
exit 1
fi
'
language: system
stages: [commit-msg]
pass_filenames: true # The script expects the filename as $1