Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

pre-commit 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/sh
  2. # get the list of modified files
  3. files=$(git diff --cached --name-only)
  4. # check if api or web directory is modified
  5. api_modified=false
  6. web_modified=false
  7. for file in $files
  8. do
  9. # Use POSIX compliant pattern matching
  10. case "$file" in
  11. api/*.py)
  12. # set api_modified flag to true
  13. api_modified=true
  14. ;;
  15. web/*)
  16. # set web_modified flag to true
  17. web_modified=true
  18. ;;
  19. esac
  20. done
  21. # run linters based on the modified modules
  22. if $api_modified; then
  23. echo "Running Ruff linter on api module"
  24. # run Ruff linter auto-fixing
  25. uv run --project api --dev ruff check --fix ./api
  26. # run Ruff linter checks
  27. uv run --project api --dev ruff check ./api || status=$?
  28. status=${status:-0}
  29. if [ $status -ne 0 ]; then
  30. echo "Ruff linter on api module error, exit code: $status"
  31. echo "Please run 'dev/reformat' to fix the fixable linting errors."
  32. exit 1
  33. fi
  34. fi
  35. if $web_modified; then
  36. echo "Running ESLint on web module"
  37. cd ./web || exit 1
  38. lint-staged
  39. echo "Running unit tests check"
  40. modified_files=$(git diff --cached --name-only -- utils | grep -v '\.spec\.ts$' || true)
  41. if [ -n "$modified_files" ]; then
  42. for file in $modified_files; do
  43. test_file="${file%.*}.spec.ts"
  44. echo "Checking for test file: $test_file"
  45. # check if the test file exists
  46. if [ -f "../$test_file" ]; then
  47. echo "Detected changes in $file, running corresponding unit tests..."
  48. pnpm run test "../$test_file"
  49. if [ $? -ne 0 ]; then
  50. echo "Unit tests failed. Please fix the errors before committing."
  51. exit 1
  52. fi
  53. echo "Unit tests for $file passed."
  54. else
  55. echo "Warning: $file does not have a corresponding test file."
  56. fi
  57. done
  58. echo "All unit tests for modified web/utils files have passed."
  59. fi
  60. cd ../
  61. fi