メインコンテンツまでスキップ

Pre-commit Integration

Integrate Upsilon with pre-commit hooks to automatically review code before commits.

What is Pre-commit?​

Pre-commit is a framework for managing and maintaining multi-language pre-commit hooks. It allows you to run checks automatically before code is committed to version control.

Installation​

1. Install pre-commit​

pip install pre-commit

2. Add Upsilon Hook​

Create or update .pre-commit-config.yaml in your project root:

repos:
- repo: https://github.com/user/upsilon
rev: v1.0.0
hooks:
- id: upsilon
name: Upsilon AI Code Review
args: ['--mock', '--format=text']
language: python
entry: upsilon review
files: \.(py|js|ts|jl|rs|go|cpp|c|hpp|h)$
require_serial: false

3. Install the Hook​

pre-commit install

Configuration Options​

Basic Configuration​

- repo: https://github.com/user/upsilon
rev: v1.0.0
hooks:
- id: upsilon

Advanced Configuration​

- repo: https://github.com/user/upsilon
rev: v1.0.0
hooks:
- id: upsilon
name: Upsilon AI Code Review
args: ['--mock', '--verbose']
files: \.(py|js|ts)$ # Only Python, JS, TS files
exclude: ^(tests/|docs/) # Exclude test and doc files
stages: [commit, push] # Run on commit and push

Arguments​

Common arguments for pre-commit hooks:

  • --mock: Use mock mode (faster, for pre-commit)
  • --real: Use real Claude API (for important commits)
  • --verbose: Show detailed output
  • --format=json: JSON output (for automation)
  • --config=path/to/config.toml: Custom configuration

File Filtering​

Control which files are reviewed:

- id: upsilon
files: \.(py|js|ts)$ # Only specific file types
exclude: |
(?x)^(
tests/.*|
docs/.*|
migrations/.*|
.*\.min\.js$
)$

Performance Optimization​

Fast Pre-commit Setup​

For quick pre-commit checks, use mock mode:

- id: upsilon
args: ['--mock', '--format=text']

Create a separate configuration for thorough reviews:

# .upsilon-precommit.toml
[tool.upsilon]
model = "claude-3-haiku-20240307" # Fastest model
max_tokens = 1000 # Limit tokens for speed
temperature = 0.0 # Deterministic output

[tool.upsilon.builtin-tools]
spell_check = { enabled = true }
syntax_check = { enabled = true }
import_analysis = { enabled = false } # Disable slower checks

[tool.upsilon.rules]
check_typos = true
check_logic = false # Disable complex analysis
check_security = false # Disable external tools
check_style = true
check_imports = false

Use with:

- id: upsilon
args: ['--mock', '--config=.upsilon-precommit.toml']

Multiple Hook Strategy​

Set up different hooks for different scenarios:

repos:
- repo: https://github.com/user/upsilon
rev: v1.0.0
hooks:
# Fast check for all commits
- id: upsilon-fast
name: Upsilon Fast Check
entry: upsilon review
args: ['--mock', '--config=.upsilon-fast.toml']
files: \.(py|js|ts)$

# Thorough check for main branch
- id: upsilon-thorough
name: Upsilon Thorough Review
entry: upsilon review
args: ['--real', '--verbose']
files: \.(py|js|ts)$
stages: [push] # Only on push

Combining with Other Hooks​

Integrate Upsilon with other pre-commit hooks:

repos:
# Code formatting
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black

- repo: https://github.com/pycqa/isort
rev: 5.11.4
hooks:
- id: isort

# Linting
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.6
hooks:
- id: ruff

# Type checking
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
hooks:
- id: mypy

# AI Review (after other tools)
- repo: https://github.com/user/upsilon
rev: v1.0.0
hooks:
- id: upsilon
args: ['--mock']

Troubleshooting​

Hook Installation Issues​

# Reinstall hooks
pre-commit uninstall
pre-commit install

# Update hooks to latest version
pre-commit autoupdate

Performance Issues​

  1. Use mock mode: Much faster than real API calls
  2. Limit file types: Only check relevant files
  3. Exclude large files: Skip generated or vendored code
  4. Reduce token limits: Lower max_tokens for faster processing

API Key Issues​

For real mode in pre-commit:

# Set API key globally
export ANTHROPIC_API_KEY="your-key"

# Or use git hooks with environment
echo 'export ANTHROPIC_API_KEY="your-key"' >> ~/.bashrc

Selective Review​

Only review changed files:

- id: upsilon
args: ['--mock']
# This automatically reviews only staged files

CI/CD Integration​

Use different configurations for different environments:

Local Development (Fast)​

- id: upsilon
args: ['--mock', '--config=.upsilon-dev.toml']

Pull Request (Moderate)​

- id: upsilon
args: ['--real', '--config=.upsilon-pr.toml']
stages: [push]

Production (Thorough)​

- id: upsilon
args: ['--real', '--verbose', '--config=.upsilon-prod.toml']
stages: [manual] # Only when explicitly triggered

Example Workflow​

  1. Developer commits code:

    git add .
    git commit -m "Add new feature"
    # Upsilon runs automatically in mock mode
  2. Pre-commit output:

    Upsilon AI Code Review..............................Passed
    - main.py: ✅ No issues found
    - utils.py: ⚠️ 1 warning (unused import)
  3. If issues found:

    Upsilon AI Code Review..............................Failed
    - main.py: ❌ 1 error (syntax error on line 15)

    # Commit is blocked until issues are fixed

Best Practices​

  1. Start with mock mode: Get familiar with Upsilon before using real API
  2. Gradual adoption: Begin with warnings, then enforce errors
  3. Team configuration: Share configuration files in version control
  4. Performance monitoring: Track hook execution time
  5. Fallback strategy: Allow bypassing in emergencies with --no-verify

Pre-commit integration makes code review automatic and consistent across your team.