[2f488f42] Implement: Atomarer 'fertig' Befehl in dev_session.py mit automatischer Notion-Aktualisierung und Git-Operationen.
This commit is contained in:
@@ -478,6 +478,34 @@ def generate_git_summary() -> Tuple[str, str]:
|
||||
print(f"❌ FEHLER beim Generieren der Git-Zusammenfassung: {e}")
|
||||
return "", ""
|
||||
|
||||
def git_push_with_retry() -> bool:
|
||||
"""Versucht, Änderungen zu pushen, und führt bei einem non-fast-forward-Fehler einen Rebase und erneuten Push durch."""
|
||||
print("\n--- Führe git push aus ---")
|
||||
try:
|
||||
subprocess.run(["git", "push"], check=True)
|
||||
print("✅ Git push erfolgreich.")
|
||||
return True
|
||||
except subprocess.CalledProcessError as e:
|
||||
if "non-fast-forward" in e.stderr.decode("utf-8"):
|
||||
print("⚠️ Git push abgelehnt (non-fast-forward). Versuche git pull --rebase und erneuten Push...")
|
||||
try:
|
||||
subprocess.run(["git", "pull", "--rebase"], check=True)
|
||||
print("✅ Git pull --rebase erfolgreich. Versuche erneuten Push...")
|
||||
subprocess.run(["git", "push"], check=True)
|
||||
print("✅ Git push nach Rebase erfolgreich.")
|
||||
return True
|
||||
except subprocess.CalledProcessError as pull_e:
|
||||
print(f"❌ FEHLER bei git pull --rebase oder erneutem Push: {pull_e}")
|
||||
print("Bitte löse Konflikte manuell und pushe dann.")
|
||||
return False
|
||||
else:
|
||||
print(f"❌ FEHLER bei git push: {e}")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"❌ Unerwarteter Fehler bei git push: {e}")
|
||||
return False
|
||||
|
||||
|
||||
# --- Report Status to Notion ---
|
||||
|
||||
def report_status_to_notion(
|
||||
@@ -576,8 +604,8 @@ def report_status_to_notion(
|
||||
except ValueError:
|
||||
print("Ungültige Eingabe. Bitte eine Zahl eingeben.")
|
||||
else:
|
||||
print("Warnung: Konnte Status-Optionen nicht abrufen. Bitte Status manuell eingeben.")
|
||||
actual_status = input("Bitte gib den neuen Status manuell ein: ")
|
||||
print("❌ FEHLER: Konnte Status-Optionen nicht abrufen. Abbruch des Berichts.")
|
||||
return
|
||||
|
||||
if not actual_status:
|
||||
print("❌ FEHLER: Kein Status festgelegt. Abbruch des Berichts.")
|
||||
@@ -656,6 +684,26 @@ def report_status_to_notion(
|
||||
status_payload = {"Status": {"status": {"name": actual_status}}}
|
||||
update_notion_task_property(token, task_id, status_payload)
|
||||
|
||||
# --- Git Operationen ---
|
||||
print("\n--- Führe Git-Operationen aus ---")
|
||||
try:
|
||||
subprocess.run(["git", "add", "."], check=True)
|
||||
print("✅ Alle Änderungen gestaged (git add .).")
|
||||
|
||||
# Commit-Nachricht erstellen
|
||||
commit_subject = actual_summary.splitlines()[0] if actual_summary else "Notion Status Update"
|
||||
commit_message = f"[{task_id.split('-')[0]}] {commit_subject}\n\n{{actual_summary}}"
|
||||
|
||||
subprocess.run(["git", "commit", "-m", commit_message], check=True)
|
||||
print("✅ Git commit erfolgreich.")
|
||||
|
||||
git_push_with_retry()
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"❌ FEHLER bei Git-Operationen: {e}")
|
||||
except Exception as e:
|
||||
print(f"❌ Unerwarteter Fehler bei Git-Operationen: {e}")
|
||||
|
||||
except (FileNotFoundError, json.JSONDecodeError) as e:
|
||||
print(f"❌ FEHLER beim Lesen der Session-Informationen für Statusbericht: {e}")
|
||||
except Exception as e:
|
||||
|
||||
@@ -1,21 +1,32 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import subprocess
|
||||
import os
|
||||
from datetime import datetime # datetime kann direkt importiert werden
|
||||
|
||||
# Fügen Sie das Projekt-Stammverzeichnis zum Python-Pfad hinzu
|
||||
# Das ist das Verzeichnis, in dem sich das Hook-Skript befindet
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
# Ermittle das Git-Projekt-Root-Verzeichnis
|
||||
try:
|
||||
from dev_session import append_blocks_to_notion_page, decimal_hours_to_hhmm
|
||||
from datetime import datetime
|
||||
except ImportError:
|
||||
print("Fehler: Konnte dev_session.py nicht importieren.", file=sys.stderr)
|
||||
PROJECT_ROOT = subprocess.check_output(["git", "rev-parse", "--show-toplevel"]).decode("utf-8").strip()
|
||||
# Stelle sicher, dass PROJECT_ROOT am Anfang von sys.path steht
|
||||
if PROJECT_ROOT not in sys.path:
|
||||
sys.path.insert(0, PROJECT_ROOT)
|
||||
# DEBUG prints
|
||||
print(f"DEBUG: PROJECT_ROOT = {PROJECT_ROOT}", file=sys.stderr)
|
||||
print(f"DEBUG: sys.path = {sys.path}", file=sys.stderr)
|
||||
except subprocess.CalledProcessError:
|
||||
print("Fehler: Nicht in einem Git-Repository. Kann notion_commit_hook nicht ausführen.", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
SESSION_DIR = ".dev_session"
|
||||
try:
|
||||
import dev_session
|
||||
# Greife auf Funktionen über dev_session.function_name zu
|
||||
append_blocks_to_notion_page = dev_session.append_blocks_to_notion_page
|
||||
decimal_hours_to_hhmm = dev_session.decimal_hours_to_hhmm
|
||||
except ImportError as e:
|
||||
print(f"Fehler: Konnte dev_session.py nicht importieren. Stelle sicher, dass dev_session.py im Projekt-Root liegt. Details: {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
SESSION_DIR = os.path.join(PROJECT_ROOT, ".dev_session")
|
||||
SESSION_FILE_PATH = os.path.join(SESSION_DIR, "SESSION_INFO")
|
||||
|
||||
def get_last_commit_message() -> str:
|
||||
|
||||
Reference in New Issue
Block a user