Skip to content
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

Merged
merged 6 commits into from
May 15, 2023

Conversation

dciborow
Copy link
Collaborator

@dciborow dciborow commented May 13, 2023

Description

Enable pushing directly after creating commit message, so that you do not have to wait for the GPT response to manually push.

gpt git commit --push

Testing

Additional context

Copy link
Contributor

@github-actions github-actions bot left a 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:

  1. Add a docstring for the _push() function to explain what it does and its return value.

  2. In the _commit() function, add a description for the push argument in the docstring.

  3. Update the test cases to cover the new push functionality in both unit and integration tests.

  4. 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-commenter
Copy link

codecov-commenter commented May 13, 2023

Codecov Report

Merging #83 (222b2cf) into main (60c0d8e) will decrease coverage by 2.56%.
The diff coverage is 100.00%.

@@             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     
Flag Coverage Δ
integration ?
unittests 97.01% <100.00%> (+0.04%) ⬆️
unittests-3.10 92.53% <100.00%> (+0.11%) ⬆️
unittests-3.11 92.53% <100.00%> (+0.11%) ⬆️
unittests-3.8 92.53% <100.00%> (+0.11%) ⬆️
unittests-3.9 92.53% <100.00%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/gpt_review/_git.py 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

src/gpt_review/_git.py Outdated Show resolved Hide resolved
src/gpt_review/_git.py Outdated Show resolved Hide resolved
src/gpt_review/_git.py Outdated Show resolved Hide resolved
tests/conftest.py Outdated Show resolved Hide resolved
tests/test_git.py Outdated Show resolved Hide resolved
tests/test_gpt_cli.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
@dciborow dciborow merged commit d5cf49e into microsoft:main May 15, 2023
@dciborow dciborow deleted the dciborow/commit-push-flag branch May 15, 2023 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants