From acf64fcfe891956560554fb8681799da22bf11b7 Mon Sep 17 00:00:00 2001 From: Floke Date: Tue, 27 Jan 2026 10:36:37 +0000 Subject: [PATCH] refactor(workflow): [2f488f42] Deaktiviere post-commit hook und mache git push interaktiv --- dev_session.py | 26 +++--------- notion_commit_hook.py | 93 ------------------------------------------- 2 files changed, 5 insertions(+), 114 deletions(-) delete mode 100644 notion_commit_hook.py diff --git a/dev_session.py b/dev_session.py index 478876c4..9d4f8b1c 100644 --- a/dev_session.py +++ b/dev_session.py @@ -701,7 +701,10 @@ def report_status_to_notion( subprocess.run(["git", "commit", "-m", commit_message], check=True) print("✅ Git commit erfolgreich.") - git_push_with_retry() + # Interaktive Abfrage für git push + push_choice = input("\n✅ Commit erfolgreich erstellt. Sollen die Änderungen jetzt gepusht werden? (j/n): ").lower() + if push_choice == 'j': + git_push_with_retry() except subprocess.CalledProcessError as e: print(f"❌ FEHLER bei Git-Operationen: {e}") @@ -763,26 +766,7 @@ def save_session_info(task_id: str, token: str): def install_git_hook(): """Installiert das notion_commit_hook.py Skript als post-commit Git-Hook.""" - git_hooks_dir = os.path.join(".git", "hooks") - post_commit_hook_path = os.path.join(git_hooks_dir, "post-commit") - source_hook_script = "notion_commit_hook.py" - - if not os.path.exists(git_hooks_dir): - # Wahrscheinlich kein Git-Repository, also nichts tun - return - - if not os.path.exists(source_hook_script): - print(f"Warnung: Hook-Skript {source_hook_script} nicht gefunden. Hook wird nicht installiert.") - return - - try: - # Kopiere das Skript und mache es ausführbar - shutil.copy(source_hook_script, post_commit_hook_path) - os.chmod(post_commit_hook_path, 0o755) - print("✅ Git-Hook für Notion-Kommentare erfolgreich installiert.") - - except (IOError, OSError) as e: - print(f"❌ FEHLER beim Installieren des Git-Hooks: {e}") + pass def cleanup_session(): """Bereinigt die Session-Datei und den Git-Hook.""" diff --git a/notion_commit_hook.py b/notion_commit_hook.py deleted file mode 100644 index 43ec6596..00000000 --- a/notion_commit_hook.py +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/env python3 -import os -import sys -import json -import subprocess -from datetime import datetime -from zoneinfo import ZoneInfo # Für Zeitzonen-Handling - -# Definiere die Zeitzone für Berlin -BERLIN_TZ = ZoneInfo("Europe/Berlin") - -# 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__))) - -try: - from dev_session import append_blocks_to_notion_page, decimal_hours_to_hhmm -except ImportError: - print("Fehler: Konnte dev_session.py nicht importieren.", file=sys.stderr) - sys.exit(1) - -SESSION_DIR = ".dev_session" -SESSION_FILE_PATH = os.path.join(SESSION_DIR, "SESSION_INFO") - -def get_last_commit_message() -> str: - """Holt die letzte Commit-Nachricht mit git.""" - try: - result = subprocess.run( - ["git", "log", "-1", "--pretty=%B"], - capture_output=True, - text=True, - check=True - ) - return result.stdout.strip() - except (subprocess.CalledProcessError, FileNotFoundError): - return "" - -def is_merge_commit() -> bool: - """Prüft, ob der letzte Commit ein Merge-Commit ist.""" - try: - result = subprocess.run(["git", "rev-parse", "--quiet", "--verify", "MERGE_HEAD"], capture_output=True, check=False) - return result.returncode == 0 - except Exception: - return False - -def main(): - """Hauptfunktion des Git-Hooks.""" - # Führe den Hook nur aus, wenn eine aktive Session existiert und es kein Merge-Commit ist - if not os.path.exists(SESSION_FILE_PATH) or is_merge_commit(): - sys.exit(0) - - try: - with open(SESSION_FILE_PATH, "r") as f: - session_data = json.load(f) - - task_id = session_data.get("task_id") - token = session_data.get("token") - session_start_time_str = session_data.get("session_start_time") - - if not task_id or not token: - sys.exit(0) - - commit_message = get_last_commit_message() - - if commit_message: - report_content = f"✅ New Commit:\n---\n{commit_message}" - timestamp = datetime.now(BERLIN_TZ).strftime('%Y-%m-%d %H:%M') - - notion_blocks = [ - { - "object": "block", - "type": "heading_2", - "heading_2": { - "rich_text": [{"type": "text", "text": {"content": f"🤖 Git Commit ({timestamp} Berlin Time)"}}] - } - }, - { - "object": "block", - "type": "code", - "code": { - "rich_text": [{"type": "text", "text": {"content": report_content}}], - "language": "yaml" - } - } - ] - append_blocks_to_notion_page(token, task_id, notion_blocks) - - except (FileNotFoundError, json.JSONDecodeError): - # Wenn die Datei nicht existiert oder fehlerhaft ist, einfach beenden - sys.exit(0) - -if __name__ == "__main__": - main()