Ai-programmer / github /github_manager.py
SpectraSoft's picture
Rename github_manager.py to github/github_manager.py
ae51853 verified
Raw
History Blame Contribute Delete
1.04 kB
import os
from git import Repo
import shutil
class GitHubManager:
def __init__(self, token: str, username: str, repo_prefix: str = "ai-worker-"):
self.token = token
self.username = username
self.repo_prefix = repo_prefix
def init_repo(self, repo_name: str, local_path: str):
full_repo_name = f"{self.repo_prefix}{repo_name}"
remote_url = f"https://{self.username}:{self.token}@github.com/{self.username}/{full_repo_name}.git"
if not os.path.exists(local_path):
os.makedirs(local_path)
repo = Repo.init(local_path)
else:
repo = Repo(local_path)
# In a real scenario, we'd check if the remote exists and create it via GitHub API if not
return repo
def commit_and_push(self, local_path: str, message: str):
repo = Repo(local_path)
repo.git.add(A=True)
repo.index.commit(message)
# origin = repo.remote(name='origin')
# origin.push()
print(f"Committed: {message}")