Fix wiki report posting - handle root-level parent doc creation

This commit is contained in:
2026-04-13 16:12:27 +00:00
parent 4d8451c987
commit f39bd13fc6
+8 -15
View File
@@ -196,20 +196,11 @@ def post_report_to_wiki(report_md, project_name, collection_id):
if not collection_id: if not collection_id:
return None return None
from shared import ensure_child_doc, find_child_doc
now = datetime.now(MT) now = datetime.now(MT)
headers = wiki_headers() headers = wiki_headers()
# Ensure "Project Status Reports" parent doc exists in this collection # Find or create "Project Status Reports" parent doc at root of this collection
reports_parent_id = ensure_child_doc( reports_parent_id = None
None, "Project Status Reports",
"Automated project status reports generated by the Project Monitor agent.",
collection_id=collection_id,
)
# ensure_child_doc with parent_id=None won't find via parentDocumentId match.
# Search manually for root-level doc in this collection.
if not reports_parent_id:
try: try:
search = api_request( search = api_request(
f"{WIKI_API}/documents.search", f"{WIKI_API}/documents.search",
@@ -218,23 +209,25 @@ def post_report_to_wiki(report_md, project_name, collection_id):
) )
for doc in search.get("data", []): for doc in search.get("data", []):
d = doc.get("document", {}) d = doc.get("document", {})
if d.get("title") == "Project Status Reports" and d.get("collectionId") == collection_id: if d.get("title") == "Project Status Reports" and not d.get("parentDocumentId"):
reports_parent_id = d["id"] reports_parent_id = d["id"]
break break
except Exception: except Exception:
pass pass
if not reports_parent_id: if not reports_parent_id:
try: try:
result = api_request( result = api_request(
f"{WIKI_API}/documents.create", f"{WIKI_API}/documents.create",
data={"title": "Project Status Reports", data={"title": "Project Status Reports",
"text": "Automated project status reports.", "text": "Automated project status reports generated by the Project Monitor agent.",
"collectionId": collection_id, "publish": True}, "collectionId": collection_id, "publish": True},
headers=headers, method="POST", headers=headers, method="POST",
) )
reports_parent_id = result["data"]["id"] reports_parent_id = result["data"]["id"]
except Exception: print(f" Created Project Status Reports parent: {reports_parent_id}")
reports_parent_id = None except Exception as e:
print(f" Warning: could not create reports parent: {e}", file=sys.stderr)
title = f"Project Status — {project_name}{now.strftime('%Y-%m-%d')}" title = f"Project Status — {project_name}{now.strftime('%Y-%m-%d')}"