Files
Brancheneinstufung2/notion_commit_hook.py
Floke 125080a0ba feat(dev-session): Containerize dev session manager
This commit introduces a containerized workflow for the development session manager (dev_session.py).

- Dockerization: Added gemini.Dockerfile to create a self-contained environment with all Python dependencies, removing the need for manual host setup.
- Start Script: Updated start-gemini.sh to build and run the container, executing dev_session.py as the entrypoint.
- Session Management: Implemented --done flag to properly terminate a session, update the Notion task status, and clean up the git hook.
- Notion Integration: Created and integrated notion_commit_hook.py which is automatically installed/uninstalled to post commit messages to the active Notion task.
- Documentation: Updated README_dev_session.md to reflect the new container-based setup, usage, and features.
2026-01-25 19:22:18 +00:00

62 lines
1.8 KiB
Python

#!/usr/bin/env python3
import os
import sys
import json
import subprocess
# Fügen Sie das Hauptverzeichnis zum Python-Pfad hinzu, damit wir dev_session importieren können
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
try:
from dev_session import add_comment_to_notion_task
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:
# Führt 'git log -1 --pretty=%B' aus, um die vollständige Commit-Nachricht zu erhalten
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 main():
"""Hauptfunktion des Git-Hooks."""
# Führe den Hook nur aus, wenn eine aktive Session existiert
if not os.path.exists(SESSION_FILE_PATH):
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")
if not task_id or not token:
sys.exit(0)
commit_message = get_last_commit_message()
if commit_message:
# Formatieren der Nachricht für Notion
comment = f"✅ New Commit:\n---\n{commit_message}"
add_comment_to_notion_task(token, task_id, comment)
except (FileNotFoundError, json.JSONDecodeError):
# Wenn die Datei nicht existiert oder fehlerhaft ist, einfach beenden
sys.exit(0)
if __name__ == "__main__":
main()