From 7e21b78ccc0751593ef482a1dad3d892d1197119 Mon Sep 17 00:00:00 2001 From: Nick Sullivan Date: Sat, 24 Jun 2023 10:39:04 -0600 Subject: [PATCH] Improve commit command with a pre-commit check --- aicodebot/cli.py | 11 ++++++++++- pyproject.toml | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/aicodebot/cli.py b/aicodebot/cli.py index d63d6b9..6edcd42 100644 --- a/aicodebot/cli.py +++ b/aicodebot/cli.py @@ -84,10 +84,19 @@ def alignment(verbose): @click.option("-v", "--verbose", count=True) @click.option("-t", "--max-tokens", type=int, default=250) @click.option("-y", "--yes", is_flag=True, default=False, help="Don't ask for confirmation before committing.") -def commit(verbose, max_tokens, yes): +@click.option("--skip-pre-commit", is_flag=True, help="Skip running pre-commit (otherwise run it if it is found).") +def commit(verbose, max_tokens, yes, skip_pre_commit): """Generate a git commit message and commit changes after you approve.""" setup_environment() + # Check if pre-commit is installed and .pre-commit-config.yaml exists + if not skip_pre_commit and Path(".pre-commit-config.yaml").exists(): + console.print("Running pre-commit checks...") + result = subprocess.run(["pre-commit", "run", "--all-files"]) + if result.returncode != 0: + console.print("Pre-commit checks failed. Please fix the issues and try again.") + return + # Load the prompt prompt = load_prompt(Path(__file__).parent / "prompts" / "commit_message.yaml") diff --git a/pyproject.toml b/pyproject.toml index 9761639..386eea5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,6 +38,8 @@ extend-ignore = [ "S308", # Trust us with mark_safe "S311", # Trust us with random "S324", # Trust us with hashlib + "S603", # Trust us with subprocess + "S607", # Trust us with subprocess with partial commands "SIM108", # Don't force ternary operators "TRY003", # long messages in exceptions are ok ]