From 4c7e99e2495c91a49fedef45a668e41f7fc3ee95 Mon Sep 17 00:00:00 2001 From: Floke Date: Mon, 26 Jan 2026 13:16:52 +0000 Subject: [PATCH] feat(notion): Append status reports directly to page content - Replaces the Notion update mechanism to append content blocks to the task page instead of posting comments. - A new function, , is implemented to handle the Notion Block API. - The function now formats the report into a 'heading_2' block for the title and a 'code' block for the detailed content, preserving formatting. - This provides a much cleaner and more readable changelog directly within the Notion task description. --- dev_session.py | 67 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 15 deletions(-) diff --git a/dev_session.py b/dev_session.py index 690e3850..0dad8ba9 100644 --- a/dev_session.py +++ b/dev_session.py @@ -304,6 +304,28 @@ def add_comment_to_notion_task(token: str, task_id: str, comment: str) -> bool: print(f"Antwort des Servers: {e.response.text}") return False +def append_blocks_to_notion_page(token: str, page_id: str, blocks: List[Dict]) -> bool: + """Hängt Inhaltsblöcke an eine Notion-Seite an.""" + url = f"https://api.notion.com/v1/blocks/{page_id}/children" + headers = { + "Authorization": f"Bearer {token}", + "Content-Type": "application/json", + "Notion-Version": "2022-06-28" + } + payload = {"children": blocks} + try: + response = requests.patch(url, headers=headers, json=payload) + response.raise_for_status() + print(f"✅ Statusbericht erfolgreich an die Notion-Task-Seite angehängt.") + return True + except requests.exceptions.RequestException as e: + print(f"❌ FEHLER beim Anhängen des Statusberichts an die Notion-Seite: {e}") + try: + print(f"Antwort des Servers: {json.dumps(e.response.json(), indent=2)}") + except: + print(f"Antwort des Servers: {e.response.text}") + return False + # --- Session Management --- SESSION_DIR = ".dev_session" @@ -535,35 +557,50 @@ def report_status_to_notion( # Kommentar zusammenstellen report_lines = [] - report_lines.append(f"**Status Update ({datetime.now().strftime('%Y-%m-%d %H:%M')})**") - report_lines.append(f"**Neuer Status:** `{actual_status}`") + # Diese Zeilen werden jetzt innerhalb des Code-Blocks formatiert + report_lines.append(f"Neuer Status: {actual_status}") if actual_summary: - report_lines.append("\n**Arbeitszusammenfassung:**") + report_lines.append("\nArbeitszusammenfassung:") report_lines.append(actual_summary) if actual_git_changes or actual_commit_messages: - report_lines.append("\n**Technische Änderungen (Git):**") + report_lines.append("\nTechnische Änderungen (Git):") if actual_git_changes: - report_lines.append("```diff") - report_lines.append(actual_git_changes) - report_lines.append("```") + report_lines.append(f"```{actual_git_changes}```") if actual_commit_messages: - report_lines.append("\n**Commit Nachrichten:**") - report_lines.append("```") - report_lines.append(actual_commit_messages) - report_lines.append("```") + report_lines.append("\nCommit Nachrichten:") + report_lines.append(f"```{actual_commit_messages}```") if actual_todos: - report_lines.append("\n**Offene To-Dos / Nächste Schritte:**") - # Sicherstellen, dass To-Dos als Liste oder einzelne Zeilen formatiert sind + report_lines.append("\nOffene To-Dos / Nächste Schritte:") for todo_item in actual_todos.split('\n'): report_lines.append(f"- {todo_item.strip()}") - notion_comment = "\n".join(report_lines) + report_content = "\n".join(report_lines) + + # Notion Blöcke für die API erstellen + timestamp = datetime.now().strftime('%Y-%m-%d %H:%M') + notion_blocks = [ + { + "object": "block", + "type": "heading_2", + "heading_2": { + "rich_text": [{"type": "text", "text": {"content": f"🤖 Status-Update ({timestamp})"}}] + } + }, + { + "object": "block", + "type": "code", + "code": { + "rich_text": [{"type": "text", "text": {"content": report_content}}], + "language": "yaml" + } + } + ] # Notion aktualisieren - add_comment_to_notion_task(token, task_id, notion_comment) + append_blocks_to_notion_page(token, task_id, notion_blocks) update_notion_task_status(token, task_id, actual_status) except (FileNotFoundError, json.JSONDecodeError) as e: