finailising repo manager

This commit is contained in:
2025-05-29 23:55:12 +10:00
parent 546b86738a
commit 328e870bf0
4 changed files with 135 additions and 23 deletions
+3 -3
View File
@@ -86,7 +86,7 @@ class OllamaGenerator:
'''Get embeddings for the draft chunks'''
embeds = self.ollama_client.embed(model=self.embed_model, input=draft_chunks)
return embeds.get('embeddings', [])
def id_generator(self, size=6, chars=string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
@@ -155,7 +155,7 @@ class OllamaGenerator:
def generate_commit_message(self):
prompt_system = "You are a blog creator commiting a piece of content to a central git repo"
prompt_human = f"Generate a 10 word git commit message describing {self.response}"
prompt_human = f"Generate a 5 word git commit message describing {self.response}"
messages = [("system", prompt_system), ("human", prompt_human),]
commit_message = self.llm.invoke(messages).text()
return commit_message
return commit_message
+16 -6
View File
@@ -1,4 +1,5 @@
import os, shutil
from urllib.parse import quote
from git import Repo
from git.exc import GitCommandError
@@ -10,8 +11,15 @@ 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 username is not set we don't need parse to the url
if username==None or password == None:
remote = f"{git_protocol}://{git_remote}"
else:
# of course if it is we need to parse and escape it so that it
# can generate a url
git_user = quote(username)
git_password = quote(password)
remote = f"{git_protocol}://{git_user}:{git_password}@{git_remote}"
if os.path.exists(repo_path):
shutil.rmtree(repo_path)
@@ -20,6 +28,8 @@ class GitRepository:
self.repo = Repo(repo_path)
self.username = username
self.password = password
self.repo.config_writer().set_value("user", "name", "blog_creator")
self.repo.config_writer().set_value("user", "email", "ridgway.infrastructure@gmail.com")
def clone(self, remote_url, destination_path):
"""Clone a Git repository with authentication"""
@@ -57,7 +67,7 @@ class GitRepository:
"""Create a new branch in the repository with authentication."""
try:
# Use the same remote and ref as before
self.repo.git.branch(branch_name, commit=True)
self.repo.git.branch(branch_name)
return True
except GitCommandError as e:
print(f"Failed to create branch: {e}")
@@ -73,7 +83,7 @@ class GitRepository:
commit_message = "Added and committed new content"
else:
commit_message = message
self.repo.git.commit(commit_message=commit_message)
self.repo.git.commit(message=commit_message)
return True
except GitCommandError as e:
print(f"Commit failed: {e}")
@@ -84,9 +94,9 @@ class GitRepository:
shutil.copy(f"{file_path}", f"{self.repo_path}src/content/")
self.add_and_commit(commit_messge)
self.add_and_commit(f"'{commit_messge}'")
self.repo.git.push(remote_name='origin', ref_name=title, force=True)
self.repo.git.push()
def remove_repo(self):
shutil.rmtree(self.repo_path)