Skip to content

Commit

Permalink
Refactor CommitDocGenHook to allow editing commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
sumansaurabh committed Aug 24, 2024
1 parent 8038059 commit 306de81
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions penify_hook/commit_analyzer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import re
import subprocess
import tempfile
from typing import Optional
from git import Repo
from tqdm import tqdm
Expand Down Expand Up @@ -96,12 +98,31 @@ def run(self, msg: Optional[str], edit_commit_message: bool):

# commit the changes to the repository with above details
commit_msg = f"{title}\n\n{description}"
self.repo.git.commit('-m', commit_msg)
if edit_commit_message:
# Open the git commit edit terminal
print("Opening git commit edit terminal...")
self.repo.git.commit('-e', '-m', commit_msg)
else:
# Commit the changes to the repository with the generated message
print(f"Committing changes with message:\n{commit_msg}")
self.repo.git.commit('-m', commit_msg)
self._amend_commit()


def _amend_commit(self):
"""
Open the default git editor for editing the commit message.
Args:
initial_message (str): The initial commit message to populate the editor with.
"""
try:
# Change to the repository directory
os.chdir(self.repo_path)

# Run git commit --amend
subprocess.run(['git', 'commit', '--amend'], check=True)

print("Commit message amended successfully.")
except subprocess.CalledProcessError as e:
print(f"Error amending commit message: {e}")
finally:
# Change back to the original directory
os.chdir(os.path.dirname(os.path.abspath(__file__)))

0 comments on commit 306de81

Please sign in to comment.