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.
This commit is contained in:
@@ -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}")
|
print(f"Antwort des Servers: {e.response.text}")
|
||||||
return False
|
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 Management ---
|
||||||
|
|
||||||
SESSION_DIR = ".dev_session"
|
SESSION_DIR = ".dev_session"
|
||||||
@@ -535,35 +557,50 @@ def report_status_to_notion(
|
|||||||
|
|
||||||
# Kommentar zusammenstellen
|
# Kommentar zusammenstellen
|
||||||
report_lines = []
|
report_lines = []
|
||||||
report_lines.append(f"**Status Update ({datetime.now().strftime('%Y-%m-%d %H:%M')})**")
|
# Diese Zeilen werden jetzt innerhalb des Code-Blocks formatiert
|
||||||
report_lines.append(f"**Neuer Status:** `{actual_status}`")
|
report_lines.append(f"Neuer Status: {actual_status}")
|
||||||
|
|
||||||
if actual_summary:
|
if actual_summary:
|
||||||
report_lines.append("\n**Arbeitszusammenfassung:**")
|
report_lines.append("\nArbeitszusammenfassung:")
|
||||||
report_lines.append(actual_summary)
|
report_lines.append(actual_summary)
|
||||||
|
|
||||||
if actual_git_changes or actual_commit_messages:
|
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:
|
if actual_git_changes:
|
||||||
report_lines.append("```diff")
|
report_lines.append(f"```{actual_git_changes}```")
|
||||||
report_lines.append(actual_git_changes)
|
|
||||||
report_lines.append("```")
|
|
||||||
if actual_commit_messages:
|
if actual_commit_messages:
|
||||||
report_lines.append("\n**Commit Nachrichten:**")
|
report_lines.append("\nCommit Nachrichten:")
|
||||||
report_lines.append("```")
|
report_lines.append(f"```{actual_commit_messages}```")
|
||||||
report_lines.append(actual_commit_messages)
|
|
||||||
report_lines.append("```")
|
|
||||||
|
|
||||||
if actual_todos:
|
if actual_todos:
|
||||||
report_lines.append("\n**Offene To-Dos / Nächste Schritte:**")
|
report_lines.append("\nOffene To-Dos / Nächste Schritte:")
|
||||||
# Sicherstellen, dass To-Dos als Liste oder einzelne Zeilen formatiert sind
|
|
||||||
for todo_item in actual_todos.split('\n'):
|
for todo_item in actual_todos.split('\n'):
|
||||||
report_lines.append(f"- {todo_item.strip()}")
|
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
|
# 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)
|
update_notion_task_status(token, task_id, actual_status)
|
||||||
|
|
||||||
except (FileNotFoundError, json.JSONDecodeError) as e:
|
except (FileNotFoundError, json.JSONDecodeError) as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user