Initial upload: Local AI Commit Reviewer CLI with CI/CD workflow
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled

This commit is contained in:
2026-02-05 06:34:38 +00:00
parent dab02f931a
commit e7e9a96b15

69
src/hooks/hooks.py Normal file
View File

@@ -0,0 +1,69 @@
from pathlib import Path
def get_hook_script() -> str:
return """#!/bin/bash
# Local AI Commit Reviewer - Pre-commit Hook
# Automatically reviews staged changes before committing
set -e
# Allow bypass with --no-verify
if [ "$1" = "--no-verify" ]; then
exit 0
fi
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Change to repository root
cd "$SCRIPT_DIR/../.."
# Run the AI commit reviewer
python -m aicr review --hook --strictness balanced || exit 1
"""
def install_pre_commit_hook(
repo_path: Path,
content: str | None = None,
force: bool = False
) -> bool:
hooks_dir = repo_path / ".git" / "hooks"
hooks_dir.mkdir(parents=True, exist_ok=True)
hook_path = hooks_dir / "pre-commit"
if hook_path.exists() and not force:
return False
if content is None:
content = get_hook_script()
try:
hook_path.write_text(content)
hook_path.chmod(0o755)
return True
except OSError:
return False
def check_hook_installed(repo_path: Path) -> bool:
hook_path = repo_path / ".git" / "hooks" / "pre-commit"
if not hook_path.exists():
return False
content = hook_path.read_text()
return "aicr" in content or "local-ai-commit-reviewer" in content
def uninstall_hook(repo_path: Path) -> bool:
hook_path = repo_path / ".git" / "hooks" / "pre-commit"
if not hook_path.exists():
return True
try:
hook_path.unlink()
return True
except OSError:
return False