diff --git a/src/dlw/git_ops.py b/src/dlw/git_ops.py index 84ce01d..f970381 100644 --- a/src/dlw/git_ops.py +++ b/src/dlw/git_ops.py @@ -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)}" \ No newline at end of file