generated from Templates/Docker_Image
feat: initial release, refs NOISSUE
This commit is contained in:
75
ai_software_factory/agents/git_manager.py
Normal file
75
ai_software_factory/agents/git_manager.py
Normal file
@@ -0,0 +1,75 @@
|
||||
"""Git manager for project operations."""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class GitManager:
|
||||
"""Manages git operations for the project."""
|
||||
|
||||
def __init__(self, project_id: str):
|
||||
if not project_id:
|
||||
raise ValueError("project_id cannot be empty or None")
|
||||
self.project_id = project_id
|
||||
self.project_dir = f"{os.path.dirname(__file__)}/../../test-project/{project_id}"
|
||||
|
||||
def init_repo(self):
|
||||
"""Initialize git repository."""
|
||||
os.makedirs(self.project_dir, exist_ok=True)
|
||||
os.chdir(self.project_dir)
|
||||
subprocess.run(["git", "init"], check=True, capture_output=True)
|
||||
|
||||
def add_files(self, paths: list[str]):
|
||||
"""Add files to git staging."""
|
||||
subprocess.run(["git", "add"] + paths, check=True, capture_output=True)
|
||||
|
||||
def commit(self, message: str):
|
||||
"""Create a git commit."""
|
||||
subprocess.run(
|
||||
["git", "commit", "-m", message],
|
||||
check=True,
|
||||
capture_output=True
|
||||
)
|
||||
|
||||
def push(self, remote: str = "origin", branch: str = "main"):
|
||||
"""Push changes to remote."""
|
||||
subprocess.run(
|
||||
["git", "push", "-u", remote, branch],
|
||||
check=True,
|
||||
capture_output=True
|
||||
)
|
||||
|
||||
def create_branch(self, branch_name: str):
|
||||
"""Create and switch to a new branch."""
|
||||
subprocess.run(
|
||||
["git", "checkout", "-b", branch_name],
|
||||
check=True,
|
||||
capture_output=True
|
||||
)
|
||||
|
||||
def create_pr(
|
||||
self,
|
||||
title: str,
|
||||
body: str,
|
||||
base: str = "main",
|
||||
head: Optional[str] = None
|
||||
) -> dict:
|
||||
"""Create a pull request via gitea API."""
|
||||
# This would integrate with gitea API
|
||||
# For now, return placeholder
|
||||
return {
|
||||
"title": title,
|
||||
"body": body,
|
||||
"base": base,
|
||||
"head": head or f"ai-gen-{self.project_id}"
|
||||
}
|
||||
|
||||
def get_status(self) -> str:
|
||||
"""Get git status."""
|
||||
result = subprocess.run(
|
||||
["git", "status", "--porcelain"],
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
return result.stdout.strip()
|
||||
Reference in New Issue
Block a user