-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add --push flag to 'gpt git commit' command #83
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary by GPT-4
I have added the --push
option to the _commit()
function in _git.py
. When this option is set to True, it will push the commit to the remote repository after committing. I have also updated the tests in test_git.py
and test_gpt_cli.py
to include this new option.
Suggestions
Here are some suggestions for improving the changes in this PR:
-
Add a docstring for the
_push()
function to explain what it does and its return value. -
In the
_commit()
function, add a description for thepush
argument in the docstring. -
Update the test cases to cover the new
push
functionality in both unit and integration tests. -
Add comments to explain any complex code or logic, if necessary.
Here's an updated version of your PR with these suggestions applied:
diff --git a/src/gpt_review/_git.py b/src/gpt_review/_git.py
index dabccb34..ad4e5bec 100644
--- a/src/gpt_review/_git.py
+++ b/src/gpt_review/_git.py
@@ -61,12 +61,20 @@ def _commit_message(gpt4: bool = False, large: bool = False) -> str:
return _request_goal(diff, goal, fast=not gpt4, large=large)
-def _commit(gpt4: bool = False, large: bool = False) -> Dict[str, str]:
+def _push() -> str:
+ """Run git push and return the response."""
+ logging.debug("Pushing commit to remote.")
+ repo = Repo.init(_find_git_dir())
+ return repo.git.push()
+
+
+def _commit(gpt4: bool = False, large: bool = False, push: bool = False) -> Dict[str, str]:
"""Run git commit with a commit message generated by 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.
+ push (bool, optional): Whether to push the commit to the remote after committing. Defaults to False.
Returns:
response (Dict[str, str]): The response from git commit.
@@ -75,6 +83,8 @@ def _commit(gpt4: bool = False, large: bool = False) -> Dict[str, str]:
logging.debug("Commit Message: %s", message)
repo = Repo.init(_find_git_dir())
commit = repo.git.commit(message=message)
+ if push:
+ commit += f"\n{_push()}"
return {"response": commit}
@@ -101,3 +111,9 @@ def load_arguments(loader: CLICommandsLoader) -> None:
default=False,
action="store_true",
)
+ args.argument(
+ "push",
+ help="Push the commit to the remote after committing.",
+ default=False,
+ action="store_true",
+ )
diff --git a/tests/conftest.py b/tests/conftest.py
index b8ba14e8..759a7a24 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -136,13 +136,16 @@ class MockGit:
def __init__(self) -> None:
self.git = self
- def commit(self,message) -> str:
Codecov Report
@@ Coverage Diff @@
## main #83 +/- ##
===========================================
- Coverage 100.00% 97.44% -2.56%
===========================================
Files 13 13
Lines 462 469 +7
Branches 67 68 +1
===========================================
- Hits 462 457 -5
- Misses 0 10 +10
- Partials 0 2 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Description
Enable pushing directly after creating commit message, so that you do not have to wait for the GPT response to manually push.
Testing
Additional context