src/dlw/git_ops.py aktualisiert

This commit is contained in:
Kim Diallo 2026-01-03 02:30:44 +01:00
parent 67f73d5286
commit 1fc53588da
1 changed files with 26 additions and 50 deletions

View File

@ -1,50 +1,26 @@
from git import Repo, exc
import os
# Das Repository-Root wird beim Start aus dem commands.py übergeben
REPO_PATH = os.getcwd()
def initialize_repo():
"""Öffnet das lokale Repository."""
try:
repo = Repo(REPO_PATH)
return repo
except exc.InvalidGitRepositoryError:
print(f"FEHLER: Kein Git-Repository in {REPO_PATH} gefunden.")
# Optional: Hier könnte eine Initialisierung oder ein Klon-Versuch erfolgen
return None
def commit_and_push_article(article_path, download_paths, title):
"""Fügt Dateien hinzu, committet und pusht zum Master."""
repo = initialize_repo()
if repo is None:
return False, "Repository nicht gefunden."
try:
# Füge den Artikel hinzu
repo.index.add([article_path])
# Füge die Download-Dateien hinzu
if download_paths:
repo.index.add(download_paths)
commit_message = f"FEAT: Neuer Artikel veröffentlicht {title}"
# Commit
repo.index.commit(commit_message)
print(f"Commit erfolgreich: {commit_message}")
# Push zum 'master' (oder 'main') Branch
# Annahme: 'origin' ist die Remote, 'main' der Zielbranch
origin = repo.remotes.origin
# Stellen Sie sicher, dass die SSH-Schlüssel für den Push eingerichtet sind!
origin.push(refspec='master:master')
print("Push zu Forgejo erfolgreich. CI/CD Pipeline gestartet.")
return True, "Artikel erfolgreich veröffentlicht und Deployment gestartet."
except exc.GitCommandError as e:
return False, f"Git Fehler: {str(e)}"
except Exception as e:
return False, f"Allgemeiner Fehler während des Pushes: {str(e)}"
from git import Repo, exc
import os
REPO_PATH = os.getcwd()
def initialize_repo():
try:
return Repo(REPO_PATH)
except exc.InvalidGitRepositoryError:
return None
def commit_and_push_article(article_path, download_paths, title):
repo = initialize_repo()
if not repo:
return False, "Kein Git-Repository gefunden."
try:
files_to_add = [article_path] + download_paths
repo.index.add(files_to_add)
repo.index.commit(f"FEAT: Neuer Artikel - {title}")
origin = repo.remotes.origin
origin.push()
return True, "Erfolgreich gepusht!"
except Exception as e:
return False, f"Fehler: {str(e)}"