45 lines
1.7 KiB
Python
45 lines
1.7 KiB
Python
import click
|
|
from git_commit_ai.core.git_handler import get_staged_changes, get_commit_history
|
|
from git_commit_ai.core.ollama_client import generate_commit_message
|
|
from git_commit_ai.core.prompt_builder import build_prompt
|
|
from git_commit_ai.core.conventional import validate_conventional, fix_conventional
|
|
from git_commit_ai.core.config import load_config
|
|
|
|
@click.group()
|
|
def cli():
|
|
"""AI-powered Git commit message generator."""
|
|
pass
|
|
|
|
@cli.command()
|
|
@click.option('--conventional', is_flag=True, help='Generate conventional commit format')
|
|
@click.option('--model', default=None, help='Ollama model to use')
|
|
@click.option('--base-url', default=None, help='Ollama API base URL')
|
|
def generate(conventional, model, base_url):
|
|
"""Generate a commit message for staged changes."""
|
|
try:
|
|
config = load_config()
|
|
model = model or config.get('model', 'qwen2.5-coder:3b')
|
|
base_url = base_url or config.get('base_url', 'http://localhost:11434')
|
|
|
|
staged = get_staged_changes()
|
|
if not staged:
|
|
click.echo("No staged changes found. Stage your changes first.")
|
|
return
|
|
|
|
history = get_commit_history()
|
|
prompt = build_prompt(staged, conventional=conventional, history=history)
|
|
|
|
message = generate_commit_message(prompt, model=model, base_url=base_url)
|
|
|
|
if conventional:
|
|
is_valid, suggestion = validate_conventional(message)
|
|
if not is_valid:
|
|
fixed = fix_conventional(message, staged)
|
|
if fixed:
|
|
message = fixed
|
|
|
|
click.echo(f"\nSuggested commit message:\n{message}")
|
|
|
|
except Exception as e:
|
|
click.echo(f"Error: {e}")
|