Skip to content

Commit

Permalink
Improve commit command with a pre-commit check
Browse files Browse the repository at this point in the history
  • Loading branch information
TechNickAI committed Jun 24, 2023
1 parent d1d487a commit 7e21b78
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion aicodebot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
Expand Down

0 comments on commit 7e21b78

Please sign in to comment.