TODO: parse URL paramters correctly

This commit is contained in:
2025-05-29 17:29:48 +10:00
parent 1bb99c2343
commit 546b86738a
2 changed files with 25 additions and 5 deletions
+6 -5
View File
@@ -10,6 +10,7 @@ class GitRepository:
def __init__(self, repo_path, username=None, password=None):
git_protocol = os.environ["GIT_PROTOCOL"]
git_remote = os.environ["GIT_REMOTE"]
#TODO: Parse the URL correctly https://stackoverflow.com/questions/1695183/how-can-i-percent-encode-url-parameters-in-python
remote = f"{git_protocol}://{username}:{password}@{git_remote}"
if os.path.exists(repo_path):
@@ -50,8 +51,8 @@ class GitRepository:
def get_branches(self):
"""List all branches in the repository"""
return [branch.name for branch in self.repo.branches]
def create_branch(self, branch_name, remote_name='origin', ref_name='main'):
"""Create a new branch in the repository with authentication."""
try:
@@ -61,7 +62,7 @@ class GitRepository:
except GitCommandError as e:
print(f"Failed to create branch: {e}")
return False
def add_and_commit(self, message=None):
"""Add and commit changes to the repository."""
try:
@@ -77,7 +78,7 @@ class GitRepository:
except GitCommandError as e:
print(f"Commit failed: {e}")
return False
def create_copy_commit_push(self, file_path, title, commit_messge):
self.create_branch(title)
@@ -88,4 +89,4 @@ class GitRepository:
self.repo.git.push(remote_name='origin', ref_name=title, force=True)
def remove_repo(self):
shutil.rmtree(self.repo_path)
shutil.rmtree(self.repo_path)