Skip to content

Commit 8d2ab73

Browse files
authored
Merge pull request #5 from popyson1648/chore/setup-ci-and-pre-commit
Add CI and pre-commit hooks
2 parents 69c6c29 + 8ce87c6 commit 8d2ab73

File tree

11 files changed

+311
-147
lines changed

11 files changed

+311
-147
lines changed

git_scribe/commands/commit.py

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22
from rich.console import Console
33
from rich.panel import Panel
44
from pathlib import Path
5-
from typing import List
65
from ..core import config, git_utils, llm, editor
76

87
console = Console()
98

9+
1010
def commit(ctx: typer.Context):
1111
"""
1212
Generates a commit message for staged changes, accepting git commit options.
13-
13+
1414
All unknown options will be passed directly to the underlying 'git commit' command.
1515
"""
1616
cfg = config.load_config()
1717
gemini_api_key = cfg.get("api_keys", {}).get("gemini", "")
1818
if "YOUR_GEMINI_API_KEY" in gemini_api_key or not gemini_api_key:
19-
console.print("[red]Error: Gemini API key not found or not set in config.toml[/red]")
19+
console.print(
20+
"[red]Error: Gemini API key not found or not set in config.toml[/red]"
21+
)
2022
raise typer.Exit(1)
2123

2224
repo = git_utils.get_repo()
@@ -25,7 +27,7 @@ def commit(ctx: typer.Context):
2527
raise typer.Exit(1)
2628

2729
passthrough_args = ctx.args
28-
30+
2931
use_all = "--all" in passthrough_args or "-a" in passthrough_args
3032
use_amend = "--amend" in passthrough_args
3133

@@ -35,31 +37,37 @@ def commit(ctx: typer.Context):
3537
diff = git_utils.get_staged_diff(repo)
3638

3739
if not diff.strip() and not use_amend:
38-
console.print("[yellow]No changes to commit. Please stage your changes or use --all.[/yellow]")
40+
console.print(
41+
"[yellow]No changes to commit. Please stage your changes or use --all.[/yellow]"
42+
)
3943
raise typer.Exit()
4044

4145
try:
42-
prompt_paths = cfg['prompt_paths']
43-
system_prompt_path = Path(prompt_paths['system_commit']).expanduser()
44-
user_prompt_path = Path(prompt_paths['user_commit']).expanduser()
46+
prompt_paths = cfg["prompt_paths"]
47+
system_prompt_path = Path(prompt_paths["system_commit"]).expanduser()
48+
user_prompt_path = Path(prompt_paths["user_commit"]).expanduser()
4549

46-
with open(system_prompt_path, 'r', encoding='utf-8') as f:
50+
with open(system_prompt_path, "r", encoding="utf-8") as f:
4751
system_prompt = f.read()
48-
with open(user_prompt_path, 'r', encoding='utf-8') as f:
52+
with open(user_prompt_path, "r", encoding="utf-8") as f:
4953
user_prompt = f.read()
5054
except (KeyError, FileNotFoundError) as e:
5155
console.print(f"[red]Error loading prompt files: {e}[/red]")
5256
raise typer.Exit(1)
5357

5458
final_user_prompt = f"{user_prompt}\n\n--- Git Diff ---\n{diff}"
55-
59+
5660
if use_amend:
5761
try:
5862
last_message = git_utils.get_last_commit_message(repo)
59-
final_user_prompt += f"\n\n--- Previous Commit Message (to amend) ---\n{last_message}"
63+
final_user_prompt += (
64+
f"\n\n--- Previous Commit Message (to amend) ---\n{last_message}"
65+
)
6066
system_prompt += "\n\nYou are amending a previous commit. Refine the provided message based on the new diff."
6167
except Exception:
62-
console.print("[yellow]Could not find previous commit to amend. Proceeding without it.[/yellow]")
68+
console.print(
69+
"[yellow]Could not find previous commit to amend. Proceeding without it.[/yellow]"
70+
)
6371

6472
console.print("[cyan]Generating commit message from LLM...[/cyan]")
6573
try:
@@ -69,21 +77,28 @@ def commit(ctx: typer.Context):
6977
raise typer.Exit(1)
7078

7179
while True:
72-
console.print(Panel(commit_msg, title="[bold green]Generated Commit Message[/bold green]", border_style="green", expand=False))
80+
console.print(
81+
Panel(
82+
commit_msg,
83+
title="[bold green]Generated Commit Message[/bold green]",
84+
border_style="green",
85+
expand=False,
86+
)
87+
)
7388
action = typer.prompt("Adopt this message? (y/n/e) [e]dit", default="y").lower()
7489

75-
if action == 'y':
90+
if action == "y":
7691
try:
7792
git_utils.commit(commit_msg, passthrough_args)
7893
console.print("[bold green]Successfully committed.[/bold green]")
7994
except Exception as e:
8095
console.print(f"[bold red]Failed to commit: {e}[/red]")
8196
raise typer.Exit(1)
8297
break
83-
elif action == 'e':
98+
elif action == "e":
8499
editor_command = editor.get_editor(cfg)
85100
commit_msg = editor.edit_content(commit_msg, editor_command)
86101
console.print("[cyan]Content updated. Please review.[/cyan]")
87102
else:
88103
console.print("[yellow]Operation cancelled.[/yellow]")
89-
break
104+
break

git_scribe/commands/init.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import typer
22
from rich.console import Console
3-
from rich.panel import Panel
43
from ..core import config
54

65
console = Console()
76

7+
88
def init():
99
"""
1010
Creates a default set of configuration and prompt files.
1111
"""
1212
if config.config_file_exists():
13-
console.print(f"[yellow]Configuration file already exists at:[/yellow] [cyan]{config.CONFIG_FILE}[/cyan]")
13+
console.print(
14+
f"[yellow]Configuration file already exists at:[/yellow] [cyan]{config.CONFIG_FILE}[/cyan]"
15+
)
1416
if typer.confirm("Do you want to overwrite it and all default prompt files?"):
1517
pass
1618
else:
1719
console.print("Operation cancelled.")
1820
raise typer.Exit()
19-
21+
2022
config.create_default_config_files()

0 commit comments

Comments
 (0)