pre-commit 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/sh
  2. # Create a link to this file at .git/hooks/pre-commit to
  3. # force PEP8 validation prior to committing
  4. #
  5. # Ignored violations:
  6. #
  7. # W504: Line break after binary operator
  8. # E501: Line too long
  9. exec 1>&2
  10. EXIT=0
  11. RED='\033[0;31m'
  12. YELLOW='\033[0;33m'
  13. NOCOLOR='\033[0m'
  14. if [ -d ./venv/ ]; then
  15. VENV="$PWD/venv"
  16. if [ -e $VENV/bin/python ]; then
  17. PATH=$VENV/bin:$PATH
  18. elif [ -e $VENV/Scripts/python.exe ]; then
  19. PATH=$VENV/Scripts:$PATH
  20. fi
  21. fi
  22. if [ ${NOVALIDATE} ]; then
  23. echo "${YELLOW}Skipping validation checks${NOCOLOR}"
  24. exit $EXIT
  25. fi
  26. echo "Linting with ruff..."
  27. ruff check netbox/
  28. if [ $? != 0 ]; then
  29. EXIT=1
  30. fi
  31. echo "Checking for missing migrations..."
  32. python netbox/manage.py makemigrations --dry-run --check
  33. if [ $? != 0 ]; then
  34. EXIT=1
  35. fi
  36. git diff --cached --name-only | if grep --quiet 'netbox/project-static/'
  37. then
  38. echo "Checking UI ESLint, TypeScript, and Prettier compliance..."
  39. yarn --cwd "$PWD/netbox/project-static" validate
  40. if [ $? != 0 ]; then
  41. EXIT=1
  42. fi
  43. fi
  44. if [ $EXIT != 0 ]; then
  45. printf "${RED}COMMIT FAILED${NOCOLOR}\n"
  46. fi
  47. exit $EXIT