untested git stuff
This commit is contained in:
parent
c606f72d90
commit
01b7f1cd78
@ -150,3 +150,10 @@ class OllamaGenerator:
|
||||
def save_to_file(self, filename: str) -> None:
|
||||
with open(filename, "w") as f:
|
||||
f.write(self.generate_markdown())
|
||||
|
||||
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}"
|
||||
messages = [("system", prompt_system), ("human", prompt_human),]
|
||||
commit_message = self.llm.invoke(messages).text()
|
||||
return commit_message
|
12
src/main.py
12
src/main.py
@ -1,6 +1,7 @@
|
||||
import ai_generators.ollama_md_generator as omg
|
||||
import trilium.notes as tn
|
||||
import string
|
||||
import repo_management.repo_manager as git_repo
|
||||
import string,os
|
||||
|
||||
tril = tn.TrilumNotes()
|
||||
|
||||
@ -23,4 +24,11 @@ for note in tril_notes:
|
||||
ai_gen = omg.OllamaGenerator(os_friendly_title,
|
||||
tril_notes[note]['content'],
|
||||
tril_notes[note]['title'])
|
||||
ai_gen.save_to_file(f"/blog_creator/generated_files/{os_friendly_title}.md")
|
||||
blog_path = f"/blog_creator/generated_files/{os_friendly_title}.md"
|
||||
ai_gen.save_to_file(blog_path)
|
||||
# Generate commit messages and push to repo
|
||||
commit_message = ai_gen.generate_commit_message()
|
||||
git_user = os.environp["GIT_USER"]
|
||||
git_pass = os.environ["GIT_PASS"]
|
||||
repo_manager = git_repo("blog/", git_user, git_pass)
|
||||
repo_manager.create_copy_commit_push(blog_path, os_friendly_title, commit_message)
|
||||
|
@ -14,7 +14,7 @@ class GitRepository:
|
||||
|
||||
if os.path.exists(repo_path):
|
||||
shutil.rmtree(repo_path)
|
||||
|
||||
self.repo_path = repo_path
|
||||
Repo.clone_from(remote, repo_path)
|
||||
self.repo = Repo(repo_path)
|
||||
self.username = username
|
||||
@ -50,3 +50,42 @@ 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:
|
||||
# Use the same remote and ref as before
|
||||
self.repo.git.branch(branch_name, commit=True)
|
||||
return True
|
||||
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:
|
||||
# Add all changes
|
||||
self.repo.git.add(all=True)
|
||||
# Commit with the provided message or a default
|
||||
if message is None:
|
||||
commit_message = "Added and committed new content"
|
||||
else:
|
||||
commit_message = message
|
||||
self.repo.git.commit(commit_message=commit_message)
|
||||
return True
|
||||
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)
|
||||
|
||||
shutil.copy(f"{file_path}", f"{self.repo_path}src/content/")
|
||||
|
||||
self.add_and_commit(commit_messge)
|
||||
|
||||
self.repo.git.push(remote_name='origin', ref_name=title, force=True)
|
||||
|
||||
def remove_repo(self):
|
||||
shutil.rmtree(self.repo_path)
|
Loading…
x
Reference in New Issue
Block a user