/
pre-commit.sh
executable file
·63 lines (50 loc) · 1.12 KB
/
pre-commit.sh
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
#!/bin/sh
color_normal="\033[0m"
color_white="\033[;1m"
color_green="\033[32m"
color_yellow="\033[33m"
color_red="\033[31m"
_print() {
echo "${color_white}[pre-commit hook]${color_normal} $1"
}
_info() {
_print "$1"
}
_success() {
_print "${color_green}$1${color_normal}"
}
_warn() {
_print "${color_yellow}$1${color_normal}"
}
_error() {
_print "${color_red}$1${color_normal}"
}
_checkCode() {
errors=$(lein check 2>&1 > /dev/null)
if [ ! $? = 0 ] ; then
_error "Syntax check failed:"
if [ true ] ; then
error=$(head -n1 <<< "$errors")
_error "$error"
fi
exit 1
fi
errors=$(lein test 2> /dev/null)
if [ ! $? = 0 ] ; then
_error "Tests failed:"
if [ true ] ; then
error=$(grep "^FAIL" <<< "$errors")
_error "$error"
fi
exit 1
fi
_success "Code check passed."
}
_checkDocumentation() {
# Check if metadata (:added, :deprecated, :io, :pure, ...) is accurate
_success "Documentation check passed."
}
_info "Running..."
_checkCode
_checkDocumentation
_info "Finished."