2
0

pre-commit 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. printf "${YELLOW}This script is obsolete and will be removed in a future release.\n"
  15. printf "Please use pre-commit instead:\n"
  16. printf " pip install pre-commit\n"
  17. printf " pre-commit install${NOCOLOR}\n"
  18. if [ -d ./venv/ ]; then
  19. VENV="$PWD/venv"
  20. if [ -e $VENV/bin/python ]; then
  21. PATH=$VENV/bin:$PATH
  22. elif [ -e $VENV/Scripts/python.exe ]; then
  23. PATH=$VENV/Scripts:$PATH
  24. fi
  25. fi
  26. if [ ${NOVALIDATE} ]; then
  27. echo "${YELLOW}Skipping validation checks${NOCOLOR}"
  28. exit $EXIT
  29. fi
  30. echo "Linting with ruff..."
  31. ruff check netbox/
  32. if [ $? != 0 ]; then
  33. EXIT=1
  34. fi
  35. echo "Checking for missing migrations..."
  36. python netbox/manage.py makemigrations --dry-run --check
  37. if [ $? != 0 ]; then
  38. EXIT=1
  39. fi
  40. git diff --cached --name-only | if grep --quiet 'netbox/project-static/'
  41. then
  42. echo "Checking UI ESLint, TypeScript, and Prettier compliance..."
  43. yarn --cwd "$PWD/netbox/project-static" validate
  44. if [ $? != 0 ]; then
  45. EXIT=1
  46. fi
  47. fi
  48. if [ $EXIT != 0 ]; then
  49. printf "${RED}COMMIT FAILED${NOCOLOR}\n"
  50. fi
  51. exit $EXIT