2018-11-08 13:52:34 -05:00
|
|
|
#!/bin/sh
|
|
|
|
# Create a link to this file at .git/hooks/pre-commit to
|
|
|
|
# force PEP8 validation prior to committing
|
|
|
|
#
|
|
|
|
# Ignored violations:
|
|
|
|
#
|
|
|
|
# W504: Line break after binary operator
|
|
|
|
# E501: Line too long
|
|
|
|
|
|
|
|
exec 1>&2
|
|
|
|
|
2019-12-06 12:54:13 -05:00
|
|
|
EXIT=0
|
|
|
|
RED='\033[0;31m'
|
|
|
|
NOCOLOR='\033[0m'
|
|
|
|
|
2020-09-30 08:28:48 -05:00
|
|
|
if [ -d ./venv/ ]; then
|
|
|
|
VENV="$PWD/venv"
|
|
|
|
if [ -e $VENV/bin/python ]; then
|
|
|
|
PATH=$VENV/bin:$PATH
|
|
|
|
elif [ -e $VENV/Scripts/python.exe ]; then
|
|
|
|
PATH=$VENV/Scripts:$PATH
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-11-08 13:52:34 -05:00
|
|
|
echo "Validating PEP8 compliance..."
|
2021-04-26 00:34:25 -07:00
|
|
|
pycodestyle --ignore=W504,E501 --exclude=node_modules netbox/
|
2019-12-06 12:54:13 -05:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
EXIT=1
|
|
|
|
fi
|
2018-11-08 13:52:34 -05:00
|
|
|
|
2019-12-06 12:42:59 -05:00
|
|
|
echo "Checking for missing migrations..."
|
|
|
|
python netbox/manage.py makemigrations --dry-run --check
|
2019-12-06 12:54:13 -05:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
EXIT=1
|
|
|
|
fi
|
|
|
|
|
2021-08-24 00:41:10 -07:00
|
|
|
echo "Checking UI ESLint, TypeScript, and Prettier compliance..."
|
|
|
|
yarn --cwd "$PWD/netbox/project-static" validate
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
EXIT=1
|
|
|
|
fi
|
|
|
|
|
2019-12-06 12:54:13 -05:00
|
|
|
if [ $EXIT != 0 ]; then
|
|
|
|
printf "${RED}COMMIT FAILED${NOCOLOR}\n"
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit $EXIT
|