src/dlw/git_ops.py aktualisiert
This commit is contained in:
parent
67f73d5286
commit
1fc53588da
|
|
@ -1,50 +1,26 @@
|
||||||
|
from git import Repo, exc
|
||||||
from git import Repo, exc
|
import os
|
||||||
import os
|
|
||||||
|
REPO_PATH = os.getcwd()
|
||||||
# Das Repository-Root wird beim Start aus dem commands.py übergeben
|
|
||||||
REPO_PATH = os.getcwd()
|
def initialize_repo():
|
||||||
|
try:
|
||||||
def initialize_repo():
|
return Repo(REPO_PATH)
|
||||||
"""Öffnet das lokale Repository."""
|
except exc.InvalidGitRepositoryError:
|
||||||
try:
|
return None
|
||||||
repo = Repo(REPO_PATH)
|
|
||||||
return repo
|
def commit_and_push_article(article_path, download_paths, title):
|
||||||
except exc.InvalidGitRepositoryError:
|
repo = initialize_repo()
|
||||||
print(f"FEHLER: Kein Git-Repository in {REPO_PATH} gefunden.")
|
if not repo:
|
||||||
# Optional: Hier könnte eine Initialisierung oder ein Klon-Versuch erfolgen
|
return False, "Kein Git-Repository gefunden."
|
||||||
return None
|
|
||||||
|
try:
|
||||||
def commit_and_push_article(article_path, download_paths, title):
|
files_to_add = [article_path] + download_paths
|
||||||
"""Fügt Dateien hinzu, committet und pusht zum Master."""
|
repo.index.add(files_to_add)
|
||||||
repo = initialize_repo()
|
repo.index.commit(f"FEAT: Neuer Artikel - {title}")
|
||||||
if repo is None:
|
|
||||||
return False, "Repository nicht gefunden."
|
origin = repo.remotes.origin
|
||||||
|
origin.push()
|
||||||
try:
|
return True, "Erfolgreich gepusht!"
|
||||||
# Füge den Artikel hinzu
|
except Exception as e:
|
||||||
repo.index.add([article_path])
|
return False, f"Fehler: {str(e)}"
|
||||||
|
|
||||||
# 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)}"
|
|
||||||
Loading…
Reference in New Issue