Initial upload: Git AI Documentation Generator v0.1.0
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
This commit is contained in:
75
src/commands/changelog.py
Normal file
75
src/commands/changelog.py
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
"""Changelog generation command."""
|
||||||
|
|
||||||
|
|
||||||
|
import click
|
||||||
|
|
||||||
|
from src.config import Config
|
||||||
|
from src.git_utils import GitError, NotGitRepositoryError, get_commit_history, get_repo
|
||||||
|
from src.ollama_client import OllamaClient, OllamaConnectionError
|
||||||
|
from src.output import (
|
||||||
|
console,
|
||||||
|
display_changelog,
|
||||||
|
display_error,
|
||||||
|
display_info,
|
||||||
|
display_model_info,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@click.command()
|
||||||
|
@click.option("--from", "-f", "from_ref", help="Starting reference (tag, commit, branch)")
|
||||||
|
@click.option("--to", "-t", "to_ref", help="Ending reference (default: HEAD)")
|
||||||
|
@click.option("--limit", "-l", default=100, help="Maximum number of commits to process")
|
||||||
|
@click.option("--format", "output_format", type=click.Choice(["markdown", "json"]), default="markdown", help="Output format")
|
||||||
|
@click.pass_context
|
||||||
|
def changelog(ctx: click.Context, from_ref: str | None, to_ref: str | None, limit: int, output_format: str) -> None:
|
||||||
|
"""Generate a changelog from git commit history."""
|
||||||
|
config: Config = ctx.obj["config"]
|
||||||
|
client = OllamaClient(config)
|
||||||
|
|
||||||
|
try:
|
||||||
|
display_info("Connecting to Ollama...")
|
||||||
|
client.connect_with_retry()
|
||||||
|
display_model_info(config.ollama_host, config.model)
|
||||||
|
except OllamaConnectionError as e:
|
||||||
|
display_error(str(e))
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
repo = get_repo()
|
||||||
|
except NotGitRepositoryError:
|
||||||
|
display_error("Current directory is not a git repository")
|
||||||
|
return
|
||||||
|
|
||||||
|
with console.status("Fetching commit history..."):
|
||||||
|
try:
|
||||||
|
commits = get_commit_history(repo, from_ref, to_ref, limit)
|
||||||
|
except GitError as e:
|
||||||
|
display_error(str(e))
|
||||||
|
return
|
||||||
|
|
||||||
|
if not commits:
|
||||||
|
display_info("No commits found in the specified range")
|
||||||
|
return
|
||||||
|
|
||||||
|
commit_data = [
|
||||||
|
{
|
||||||
|
"sha": c.sha,
|
||||||
|
"message": c.message,
|
||||||
|
"author": c.author,
|
||||||
|
"date": c.date.isoformat() if c.date else None,
|
||||||
|
"type": c.commit_type,
|
||||||
|
"scope": c.scope,
|
||||||
|
}
|
||||||
|
for c in commits
|
||||||
|
]
|
||||||
|
|
||||||
|
with console.status("Generating changelog..."):
|
||||||
|
try:
|
||||||
|
changelog_text = client.generate_changelog(
|
||||||
|
commit_data,
|
||||||
|
from_version=from_ref,
|
||||||
|
to_version=to_ref,
|
||||||
|
)
|
||||||
|
display_changelog(changelog_text, from_ref, to_ref or "current")
|
||||||
|
except OllamaConnectionError as e:
|
||||||
|
display_error(str(e))
|
||||||
Reference in New Issue
Block a user