🔧 FIX: Git identity setzen + Changes-Status checken via git status
docker-build-and-push / build (push) Successful in 18s
docker-build-and-push / build (push) Successful in 18s
This commit is contained in:
@@ -140,3 +140,35 @@ def push_changes(repo_path: Path, message: str = "Update 🧠", changelog_conten
|
|||||||
)
|
)
|
||||||
|
|
||||||
return {"success": result.returncode == 0, "output": result.stdout}
|
return {"success": result.returncode == 0, "output": result.stdout}
|
||||||
|
|
||||||
|
|
||||||
|
def get_git_status(repo_path: Path) -> dict:
|
||||||
|
"""Prueft den Status eines Git-Repo fuer aenderungen."""
|
||||||
|
# Setze git identity if not set (fuer Push ohne manuelle Konfig)
|
||||||
|
try:
|
||||||
|
subprocess.run(
|
||||||
|
["git", "config", "--global", "user.name", "KI-Sparringpartner"],
|
||||||
|
cwd=repo_path, capture_output=True
|
||||||
|
)
|
||||||
|
subprocess.run(
|
||||||
|
["git", "config", "--global", "user.email", "ai@local.internal"],
|
||||||
|
cwd=repo_path, capture_output=True
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
pass # Falls git config fehlschlaegt, versuch trotzdem push
|
||||||
|
|
||||||
|
# Check fuer uncommitted changes
|
||||||
|
result = subprocess.run(
|
||||||
|
["git", "status", "--porcelain"],
|
||||||
|
cwd=repo_path,
|
||||||
|
capture_output=True,
|
||||||
|
text=True
|
||||||
|
)
|
||||||
|
|
||||||
|
has_changes = bool(result.stdout.strip())
|
||||||
|
|
||||||
|
return {
|
||||||
|
"has_changes": has_changes,
|
||||||
|
"uncommitted_files": result.stdout.strip().split("\n") if result.stdout else [],
|
||||||
|
"can_push": has_changes
|
||||||
|
}
|
||||||
+23
-6
@@ -28,8 +28,9 @@ class PushRequest(BaseModel):
|
|||||||
|
|
||||||
@router.get("/projects") # Listet abonierte Projekte!
|
@router.get("/projects") # Listet abonierte Projekte!
|
||||||
async def list_projects():
|
async def list_projects():
|
||||||
"""Listet lokale (abonierte) Projekte an."""
|
"""Listet lokale (abonierte) Projekte an mit Git-Status."""
|
||||||
from .main import PROJECTS_DIR
|
from .main import PROJECTS_DIR
|
||||||
|
from .git_manager import get_git_status
|
||||||
|
|
||||||
projects = []
|
projects = []
|
||||||
|
|
||||||
@@ -39,18 +40,28 @@ async def list_projects():
|
|||||||
if project_dir.is_dir() and not project_dir.name.startswith('.'):
|
if project_dir.is_dir() and not project_dir.name.startswith('.'):
|
||||||
has_git = (project_dir / '.git').exists()
|
has_git = (project_dir / '.git').exists()
|
||||||
|
|
||||||
# Pruefe ob dieses Projekt bearbeitet werden darf
|
|
||||||
can_write = os.access(str(project_dir), os.W_OK) if project_dir.exists() else False
|
can_write = os.access(str(project_dir), os.W_OK) if project_dir.exists() else False
|
||||||
|
|
||||||
|
# Git Status checken
|
||||||
|
git_status = {"has_changes": False, "uncommitted_files": []}
|
||||||
|
if has_git:
|
||||||
|
try:
|
||||||
|
git_status = get_git_status(project_dir)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Git status error: {e}")
|
||||||
|
|
||||||
all_projects.append({
|
all_projects.append({
|
||||||
"name": project_dir.name,
|
"name": project_dir.name,
|
||||||
"path": str(project_dir),
|
"path": str(project_dir),
|
||||||
"subscribed": True,
|
"subscribed": True,
|
||||||
"has_git": bool(has_git),
|
"has_git": bool(has_git),
|
||||||
"can_write": can_write
|
"can_write": can_write,
|
||||||
|
"has_changes": git_status.get("has_changes", False),
|
||||||
|
"uncommitted_files": git_status.get("uncommitted_files", [])
|
||||||
})
|
})
|
||||||
|
|
||||||
projects = sorted(all_projects, key=lambda x: ("" in x["name"]), reverse=True)
|
# Sortiere: Projects mit Changes zuerst
|
||||||
|
projects = sorted(all_projects, key=lambda x: (not x["has_changes"]))
|
||||||
|
|
||||||
return {"projects": projects}
|
return {"projects": projects}
|
||||||
|
|
||||||
@@ -122,6 +133,12 @@ async def subscribe_repo(req: SubscribeRequest):
|
|||||||
|
|
||||||
generate_changelog(target_dir)
|
generate_changelog(target_dir)
|
||||||
|
|
||||||
|
# Initialen Push nach dem ersten Clone (optional)
|
||||||
|
try:
|
||||||
|
push_changes(target_dir, "Initial commit from gitea-sync-ai")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Initial push skipped: {e}")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"message": f"✅ {req.target_name} geklont!",
|
"message": f"✅ {req.target_name} geklont!",
|
||||||
"path": str(target_dir),
|
"path": str(target_dir),
|
||||||
@@ -134,7 +151,6 @@ async def subscribe_repo(req: SubscribeRequest):
|
|||||||
async def push_to_gitea(req: PushRequest):
|
async def push_to_gitea(req: PushRequest):
|
||||||
"""Pusht Changes eines Projekts zurueck zu Gitea."""
|
"""Pusht Changes eines Projekts zurueck zu Gitea."""
|
||||||
from .main import PROJECTS_DIR
|
from .main import PROJECTS_DIR
|
||||||
import stat
|
|
||||||
|
|
||||||
target_dir = PROJECTS_DIR / req.project_name
|
target_dir = PROJECTS_DIR / req.project_name
|
||||||
|
|
||||||
@@ -161,6 +177,7 @@ async def push_to_gitea(req: PushRequest):
|
|||||||
async def push_project(project_name: str):
|
async def push_project(project_name: str):
|
||||||
"""Pusht Changes eines Projekts zurueck zu Gitea (ohne ChangelogContent)."""
|
"""Pusht Changes eines Projekts zurueck zu Gitea (ohne ChangelogContent)."""
|
||||||
from .main import PROJECTS_DIR
|
from .main import PROJECTS_DIR
|
||||||
|
import stat
|
||||||
|
|
||||||
target_dir = PROJECTS_DIR / project_name
|
target_dir = PROJECTS_DIR / project_name
|
||||||
|
|
||||||
@@ -184,5 +201,5 @@ async def push_project(project_name: str):
|
|||||||
|
|
||||||
|
|
||||||
# Importiere die Funktionen am Ende damit sie verfügbar sind!
|
# Importiere die Funktionen am Ende damit sie verfügbar sind!
|
||||||
from .git_manager import clone_repo, set_permissions, push_changes, force_remove_all
|
from .git_manager import clone_repo, set_permissions, push_changes, force_remove_all, get_git_status
|
||||||
from .changelog_gen import generate_changelog
|
from .changelog_gen import generate_changelog
|
||||||
Reference in New Issue
Block a user