Skip to content

Commit

Permalink
feat: Enhance generate_commit_message to generate multiple commit opt…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
Undertone0809 committed Jul 4, 2024
1 parent c80a9d2 commit a61407b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
26 changes: 15 additions & 11 deletions gcop/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import subprocess
from enum import Enum
from pathlib import Path
from typing import Literal
from typing import List, Literal

import click
import pne
Expand All @@ -17,7 +17,6 @@

load_dotenv()


app = typer.Typer(
name="gcop",
help="gcop is your local git command copilot",
Expand All @@ -36,9 +35,9 @@ class Color(str, Enum):


class LLMResponse(BaseModel):
content: str = Field(
content: List[str] = Field(
...,
description="git commit message, eg: feat: Add type annotation to generate_commit_message function", # noqa
description="three of alternative git commit messages, eg: feat: Add type annotation to generate_commit_message function", # noqa
)


Expand All @@ -60,7 +59,7 @@ def get_git_diff(diff_type: Literal["--staged", "--cached"]) -> str:
raise ValueError(f"Error getting git diff: {e}")


def generate_commit_message(diff: str) -> str:
def generate_commit_message(diff: str) -> List[str]:
"""Generate a git commit message based on the given diff.
Args:
Expand Down Expand Up @@ -147,14 +146,19 @@ def commit_command():

console.print(f"[yellow]Staged: {diff}[/]")

commit_message: str = generate_commit_message(diff)
commit_messages: List[str] = generate_commit_message(diff)

response = questionary.confirm(
f"Ready to run command: git commit -m '{commit_message}', continue?"
response = questionary.select(
"Select a commit message to commit", choices=[*commit_messages, "retry"]
).ask()

if response == "retry":
commit_command()
return

if response:
console.print(f"[green]Command: git commit -m '{commit_message}'[/]")
subprocess.run(["git", "commit", "-m", f"{commit_message}"])
console.print(f"[green]Command: git commit -m '{response}'[/]")
subprocess.run(["git", "commit", "-m", f"{response}"])
else:
console.print("[red]Canceled[/]")

Expand All @@ -170,7 +174,7 @@ def help_command():
console.print("[bold] git ghelp Add command into git config")
console.print("[bold] git gconfig Open the config file in the default editor")
console.print(
"[bold] git gcommit Generate a git commit message based on the staged changes and commit the changes" # noqa
"[bold] git gcommit Generate a git commit message based on the staged changes and commit the changes" # noqa
)


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ requires = ["poetry-core"]

[tool.poetry]
name = "gcop"
version = "1.0.1"
version = "1.1.0"
description = "gcop is your git AI copilot."
readme = "README.md"
authors = ["gcop <[email protected]>"]
Expand Down

0 comments on commit a61407b

Please sign in to comment.