Skip to content

Commit

Permalink
Merge pull request #115 from Bishoy-at-pieces/edit-autocommit
Browse files Browse the repository at this point in the history
feat: add staging all files and issue number flag (issue: #113)
  • Loading branch information
Bishoy-at-pieces authored May 16, 2024
2 parents ca55f4b + 9696c69 commit 63c785f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/pieces/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ def add_subparsers(self):
# Subparser for the 'commit' command
commit_parser = self.command_parser.add_parser('commit', help='Auto generate a github commit messaage and commit changes')
commit_parser.add_argument("-p","--push",dest="push",action="store_true", help="push the code to github")
commit_parser.add_argument("-a","--all",dest="all_flag",action="store_true", help="stage all the files before commiting")
commit_parser.add_argument("-i","--issues",dest="issue_flag",action="store_true", help="add issue number in the commit message")
commit_parser.set_defaults(func=git_commit)

def run(self):
Expand Down
13 changes: 9 additions & 4 deletions src/pieces/autocommit/autocommit.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def get_current_working_changes() -> Tuple[str,list]:


def git_commit(**kwargs):
if kwargs.get("all_flag",False):
subprocess.run(["git", "add", "-A"], check=True)

issue_flag = kwargs.get('issue_flag')
model = Settings.model_id
try:
Expand Down Expand Up @@ -171,12 +174,11 @@ def git_commit(**kwargs):


# Check if the user wants to commit the changes or change the commit message
r_message = input(f"The generated commit message is:\n\n {commit_message}\n\nAre you sure you want to commit these changes?\n\n- y: Yes\n- n: No\n- c: Change the commit message\n\nPlease enter your choice (y/n/c): ")
r_message = input(f"The generated commit message is:\n\n {commit_message}\n\nAre you sure you want to commit these changes?\n\n- y: Yes\n- n: No\n- c: Change the commit message\n\nPlease enter your choice (y/n/c): ").lower().strip()

if r_message.lower() == "y" or r_message.lower() == "c":

if r_message == "y" or r_message == "c" or not r_message: # Accept by default if the user did not write anything
# Changing the commit message if the user wants to
if r_message.lower() == "c":
if r_message == "c":
edit = input(f"Enter the new commit message [generated message is: '{commit_message}']: ")
if edit:
commit_message = edit
Expand Down Expand Up @@ -211,7 +213,10 @@ def git_commit(**kwargs):
try:
subprocess.run(["git", "commit", "-m", commit_message], check=True)
print("Successfully committed with message:", commit_message)
if kwargs.get('push',False):
subprocess.run(["git", "push"])
except subprocess.CalledProcessError as e:
print("Failed to commit changes:", e)

else:
print("Committing changes cancelled")

0 comments on commit 63c785f

Please sign in to comment.