-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-commit
91 lines (84 loc) · 2.22 KB
/
pre-commit
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
87
88
89
90
91
#!/bin/bash
# Pre-commit git hook que comprueba el codigo puppet y erb antes
# de ser introducido en el repositorio.
# Revisa que sólo se realicen commits en la rama 'develop'.
if [ `git rev-parse --abbrev-ref HEAD` != "develop" ]; then
echo "$(tput setaf 1 ; tput bold ; tput smul)Error$(tput sgr0):no estas en la rama 'develop'."
exit 1
fi
# Check sintaxis de ficheros puppet.
echo "$(tput setaf 4 ; tput bold)==> $(tput setaf 7 ; tput bold)Revision de sintaxis de manifests.$(tput sgr0)"
for file in `git diff --name-only --cached | grep -E '\.(pp)'`
do
if [[ -f $file ]]
then
num_files_p+=1
puppet parser validate $file
if [[ $? -ne 0 ]]
then
syntax_is_bad=1
else
echo "$file - OK"
fi
fi
done
if [[ num_files_p -eq 0 ]]
then
echo "No manifests."
fi
echo ""
# Check de estilo puppet.
echo "$(tput setaf 4 ; tput bold)==> $(tput setaf 7 ; tput bold)Revision de estilo de manifests.$(tput sgr0)"
for file in `git diff --name-only --cached | grep -E '\.(pp)'`
do
if [[ -f $file ]]
then
num_files_s+=1
puppet-lint --fail-on-warnings --no-80chars-check $file
if [[ $? -ne 0 ]]
then
syntax_is_bad=1
else
echo "$file - OK"
fi
fi
done
if [[ num_files_s -eq 0 ]]
then
echo "No manifests."
fi
echo ""
# Check sintaxis de templates.
echo "$(tput setaf 4 ; tput bold)==> $(tput setaf 7 ; tput bold)Revision de sintaxis de templates.$(tput sgr0)"
for file in `git diff --name-only --cached | grep -E '\.erb'`
do
if [[ -f $file ]]
then
num_files_t+=1
erb -x -P -T - | ruby -c
if [[ $? -ne 0 ]]
then
syntax_is_bad=1
else
echo "$file"
fi
fi
done
if [[ num_files_t -eq 0 ]]
then
echo "No templates."
fi
echo ""
if [[ $syntax_is_bad -eq 1 ]]
then
echo "---------------------------------------------------------"
echo "$(tput setaf 1 ; tput bold)WARNING$(tput sgr0): Revisa tu codigo de nuevo."
echo "Corrige los errores que se muestran arriba."
echo "Mientras no sea valido no podras añadirlo al repositorio."
echo "---------------------------------------------------------"
exit 1
else
echo "----------------------------"
echo "$(tput setaf 2 ; tput bold)Codigo valido.$(tput sgr0)"
echo "----------------------------"
fi