-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit
51 lines (46 loc) · 1.07 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
#!/bin/bash
REPO_ROOT_DIR="$(git rev-parse --show-toplevel)"
REPORT_STRING=""
RESULT=0
EXISTING_UNSTAGED_CHANGES=`git diff --name-only`
if [ ${#EXISTING_UNSTAGED_CHANGES[@]} ]; then
if black --quiet --check --config "${REPO_ROOT_DIR}/pyproject.toml" "${REPO_ROOT_DIR}"; then
REPORT_STRING+="Black ✔ | "
true
else
REPORT_STRING+="Black ❌ | "
RESULT+=1
fi
else
black --quiet --config "${REPO_ROOT_DIR}/pyproject.toml" "${REPO_ROOT_DIR}"
NEW_UNSTAGED_CHANGES=`git diff --name-only`
if [ ${#NEW_UNSTAGED_CHANGES[@]} ]; then
git add -u
REPORT_STRING+="Black 💪 | "
else
REPORT_STRING+="Black ✔ | "
fi
fi
mypy "${REPO_ROOT_DIR}" > /dev/null
MYPY_RESULT=$?
if [[ $MYPY_RESULT -eq 1 ]]; then
REPORT_STRING+="Mypy ❌ | "
RESULT+=1
else
REPORT_STRING+="Mypy ✔ | "
fi
flake8 "${REPO_ROOT_DIR}" > /dev/null
FLAKE8_RESULT=$?
if [[ $FLAKE8_RESULT -eq 1 ]]; then
REPORT_STRING+="flake8 ❌"
RESULT+=1
else
REPORT_STRING+="flake8 ✔"
fi
echo $REPORT_STRING
if (( $RESULT > 0 )); then
echo "⚠ Commit aborted ⚠"
exit 1
else
exit 0
fi