# Lefthook configuration for Glockenspiel monorepo
# https://github.com/evilmartians/lefthook

pre-commit:
  parallel: true

  commands:
    format-studio-api:
      root: 'studio_api/'
      glob: 'studio_api/**/*.py'
      exclude:
        - '*/migrations/*.py'
        - '*/migrations/**/*.py'
      run: uv run --only-dev ruff format {staged_files}
      stage_fixed: true

    check-istartswith:
      root: 'studio_api/'
      glob: 'studio_api/**/*.py'
      exclude:
        - '*/migrations/*.py'
        - '*/migrations/**/*.py'
      run: |
        if echo "{staged_files}" | xargs grep -l -E "istartswith|icontains" 2>/dev/null; then
          echo "❌ ERROR: Found usage of 'istartswith' or 'icontains' in staged files. This can break the database, please reach out to #pod-core for more info."
          exit 1
        fi

    format-suno-utils:
      root: 'suno_utils/'
      glob: 'suno_utils/**/*.py'
      run: uv run --only-dev ruff format {staged_files}
      stage_fixed: true

    check-deployment-type:
      glob: 'suno_utils/suno_utils/worker/deployment_utils.py'
      run: |
        if ! grep -q '_STATIC_DEPLOYMENT_TYPE = "NOT_SET"' suno_utils/suno_utils/worker/deployment_utils.py; then
          echo "❌ ERROR: deployment_utils.py must have _STATIC_DEPLOYMENT_TYPE = \"NOT_SET\""
          echo "The deployment scripts temporarily modify this value, but it must be \"NOT_SET\" in the repository."
          exit 1
        fi

    lint-ui:
      root: 'ui/app-ui/'
      glob: 'ui/app-ui/**/*.{js,jsx,ts,tsx}'
      run: pnpm lint-staged
      stage_fixed: true
      interactive: true
