Skip to content

Commit f7f6fa7

Browse files
committed
build: updated pre-commit hook to run ./just-scripts/commit-msg
1 parent ea17a7c commit f7f6fa7

File tree

2 files changed

+55
-12
lines changed

2 files changed

+55
-12
lines changed

just-scripts/commit-msg

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/sh
2+
3+
min_length=10
4+
max_length=1000
5+
types=("build" "chore" "ci" "docs" "feat" "fix" "perf" "refactor" "style" "test" "WIP")
6+
7+
function build_regex() {
8+
regexp="^("
9+
for type in "${types[@]}"
10+
do
11+
regexp="${regexp}$type|"
12+
done
13+
14+
# Remove trailing pipe `|`
15+
regexp="${regexp%|}"
16+
17+
# Optional scope and optional breaking `!`
18+
regexp="${regexp})(\(.+\))?(!)?: "
19+
20+
# Length restriction
21+
regexp="${regexp}.{$min_length,$max_length}$"
22+
}
23+
24+
function print_error() {
25+
echo -e "\n\e[1m\e[31m[INVALID COMMIT MESSAGE]"
26+
echo -e "------------------------\033[0m\e[0m"
27+
echo -e "\e[1mValid types:\e[0m \e[34m${types[@]}\033[0m"
28+
echo -e "\e[1mMax length (first line):\e[0m \e[34m$max_length\033[0m"
29+
echo -e "\e[1mMin length (first line):\e[0m \e[34m$min_length\033[0m\n"
30+
}
31+
32+
INPUT_FILE=.git/COMMIT_EDITMSG
33+
START_LINE=`head -n1 $INPUT_FILE`
34+
35+
build_regex
36+
37+
if [[ ! $START_LINE =~ $regexp ]]; then
38+
# commit message is invalid according to config - block commit
39+
print_error
40+
exit 1
41+
fi

justfile

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
default: check lint fmt test
22

3-
check:
4-
@echo "[+] Checking"
5-
@cargo check
3+
@check:
4+
echo "[+] Checking"
5+
cargo check
66

7-
lint:
8-
@echo "[+] Linting"
9-
@cargo clippy --workspace --all-targets --all-features -- -Dwarnings
7+
@lint:
8+
echo "[+] Linting"
9+
cargo clippy --workspace --all-targets --all-features -- -Dwarnings
1010

11-
fmt:
12-
@echo "[+] Formatting"
13-
@cargo fmt --all --check
11+
@fmt:
12+
echo "[+] Formatting"
13+
cargo fmt --all --check
1414

15+
@test:
16+
echo "[+] Testing"
17+
cargo nextest r
1518

16-
test:
17-
@echo "[+] Testing"
18-
@cargo nextest r
19+
@commit-msg:
20+
sh ./just-scripts/commit-msg

0 commit comments

Comments
 (0)