diff --git a/src/gpt_review/_git.py b/src/gpt_review/_git.py index 957f43de..97a42478 100644 --- a/src/gpt_review/_git.py +++ b/src/gpt_review/_git.py @@ -4,6 +4,7 @@ from typing import Dict from knack import CLICommandsLoader +from knack.arguments import ArgumentsContext from knack.commands import CommandGroup from git.repo import Repo @@ -39,10 +40,14 @@ def _diff() -> str: return Repo.init(_find_git_dir()).git.diff(None, cached=True) -def _commit_message() -> str: +def _commit_message(gpt4: bool = False, large: bool = False) -> str: """ Create a commit message with GPT. + Args: + gpt4 (bool, optional): Whether to use gpt-4. Defaults to False. + large (bool, optional): Whether to use gpt-4-32k. Defaults to False. + Returns: response (str): The response from GPT-4. """ @@ -53,17 +58,12 @@ def _commit_message() -> str: diff = _diff() logging.debug("Diff: %s", diff) - return _request_goal(diff, goal) + return _request_goal(diff, goal, fast=not gpt4, large=large) -def _commit() -> Dict[str, str]: - """ - Run git commit with a commit message generated by GPT. - - Returns: - response (dict): The response from GPT-4. - """ - message = _commit_message() +def _commit(gpt4: bool = False, large: bool = False) -> Dict[str, str]: + """Run git commit with a commit message generated by GPT.""" + message = _commit_message(gpt4=gpt4, large=large) logging.debug("Commit Message: %s", message) repo = Repo.init(_find_git_dir()) commit = repo.git.commit(message=message) @@ -75,5 +75,21 @@ class GitCommandGroup(GPTCommandGroup): @staticmethod def load_command_table(loader: CLICommandsLoader) -> None: - with CommandGroup(loader, "git", "gpt_review._git#{}") as group: + with CommandGroup(loader, "git", "gpt_review._git#{}", is_preview=True) as group: group.command("commit", "_commit", is_preview=True) + + @staticmethod + def load_arguments(loader: CLICommandsLoader) -> None: + with ArgumentsContext(loader, "git commit") as args: + args.argument( + "gpt4", + help="Use gpt-4 for generating commit messages instead of gpt-35-turbo.", + default=False, + action="store_true", + ) + args.argument( + "large", + help="Use gpt-4-32k model for generating commit messages.", + default=False, + action="store_true", + ) diff --git a/tests/test_gpt_cli.py b/tests/test_gpt_cli.py index e404d2d3..ea68bc46 100644 --- a/tests/test_gpt_cli.py +++ b/tests/test_gpt_cli.py @@ -105,8 +105,6 @@ class CLICase: CLICase( "ask --files src/gpt_review/main.py --files src/gpt_review/main.py what programming language is this code written in?" ), - CLICase("git commit --help"), - # CLICase("git commit"), CLICase("github review --help"), CLICase("github review"), CLICase( @@ -115,13 +113,20 @@ class CLICase: CLICase("ask --fast -f src/gpt_review/__init__.py what programming language is this code written in?"), ] +GIT_COMMANDS = [ + CLICase("git commit --help"), + # CLICase("git commit"), + # CLICase("git commit --large"), + # CLICase("git commit --gpt4"), +] + REVIEW_COMMANDS = [ CLICase("review --help"), CLICase("review diff --help"), CLICase("review diff --diff tests/mock.diff --config tests/config.summary.test.yml"), ] -ARGS = ROOT_COMMANDS + ASK_COMMANDS + REVIEW_COMMANDS +ARGS = ROOT_COMMANDS + ASK_COMMANDS + GIT_COMMANDS + REVIEW_COMMANDS def gpt_cli_test(command: CLICase) -> None: