|
| 1 | +""" |
| 2 | +Changelog management CLI commands. |
| 3 | +""" |
| 4 | + |
| 5 | +import asyncio |
| 6 | +from typing import Annotated, List, Optional |
| 7 | + |
| 8 | +import typer |
| 9 | +from pipelex.core.pipes.pipe_run_params import PipeRunMode |
| 10 | +from pipelex.hub import get_pipeline_tracker |
| 11 | + |
| 12 | +from cocode.common import get_output_dir, validate_repo_path |
| 13 | +from cocode.swe.swe_cmd import swe_from_repo_diff |
| 14 | + |
| 15 | +changelog_app = typer.Typer( |
| 16 | + name="changelog", |
| 17 | + help="Changelog management and generation commands", |
| 18 | + add_completion=False, |
| 19 | + rich_markup_mode="rich", |
| 20 | + no_args_is_help=True, |
| 21 | +) |
| 22 | + |
| 23 | + |
| 24 | +@changelog_app.command("update") |
| 25 | +def changelog_update_cmd( |
| 26 | + version: Annotated[ |
| 27 | + str, |
| 28 | + typer.Argument(help="Git version/tag/commit to compare current version against"), |
| 29 | + ], |
| 30 | + repo_path: Annotated[ |
| 31 | + str, |
| 32 | + typer.Argument(help="Repository path (local directory) or GitHub URL/identifier (owner/repo or https://github.com/owner/repo)"), |
| 33 | + ] = ".", |
| 34 | + output_dir: Annotated[ |
| 35 | + Optional[str], |
| 36 | + typer.Option("--output-dir", "-o", help="Output directory path. Use 'stdout' to print to console. Defaults to config value if not provided"), |
| 37 | + ] = None, |
| 38 | + output_filename: Annotated[ |
| 39 | + str, |
| 40 | + typer.Option("--output-filename", "-n", help="Output filename"), |
| 41 | + ] = "changelog-update.md", |
| 42 | + dry_run: Annotated[ |
| 43 | + bool, |
| 44 | + typer.Option("--dry", help="Run pipeline in dry mode (no actual execution)"), |
| 45 | + ] = False, |
| 46 | + ignore_patterns: Annotated[ |
| 47 | + Optional[List[str]], |
| 48 | + typer.Option( |
| 49 | + "--ignore-pattern", "-i", help="Patterns to exclude from git diff (e.g., '*.log', 'temp/', 'build/'). Can be specified multiple times." |
| 50 | + ), |
| 51 | + ] = None, |
| 52 | +) -> None: |
| 53 | + """Generate changelog from git diff comparing current version to specified version. Supports both local repositories and GitHub repositories.""" |
| 54 | + repo_path = validate_repo_path(repo_path) |
| 55 | + output_dir = get_output_dir(output_dir) |
| 56 | + to_stdout = output_dir == "stdout" |
| 57 | + pipe_run_mode = PipeRunMode.DRY if dry_run else PipeRunMode.LIVE |
| 58 | + |
| 59 | + asyncio.run( |
| 60 | + swe_from_repo_diff( |
| 61 | + pipe_code="write_changelog", |
| 62 | + repo_path=repo_path, |
| 63 | + version=version, |
| 64 | + output_filename=output_filename, |
| 65 | + output_dir=output_dir, |
| 66 | + to_stdout=to_stdout, |
| 67 | + pipe_run_mode=pipe_run_mode, |
| 68 | + ignore_patterns=ignore_patterns, |
| 69 | + ) |
| 70 | + ) |
| 71 | + get_pipeline_tracker().output_flowchart() |
0 commit comments