From 5755ca705cddfcfc12345afe356a70c0edc3de53 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sun, 1 Feb 2026 19:31:03 +0000 Subject: [PATCH] Initial upload: Git AI Documentation Generator v0.1.0 --- src/commands/changelog.py | 75 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/commands/changelog.py diff --git a/src/commands/changelog.py b/src/commands/changelog.py new file mode 100644 index 0000000..1307995 --- /dev/null +++ b/src/commands/changelog.py @@ -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))