From 4a20da2ed28fdc3ffbaca6c0eb69764fba4f1e57 Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 1 Sep 2026 07:27:14 +0200 Subject: [PATCH] humhub: comment-list/comment-create (POST /comment via Content-ID/Perma-URL) Co-Authored-By: Claude Fable 5 --- plugins/humhub/.claude-plugin/plugin.json | 4 +- plugins/humhub/skills/humhub/SKILL.md | 11 +++++ plugins/humhub/skills/humhub/humhub.py | 53 +++++++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/plugins/humhub/.claude-plugin/plugin.json b/plugins/humhub/.claude-plugin/plugin.json index ed8e959..dad056a 100644 --- a/plugins/humhub/.claude-plugin/plugin.json +++ b/plugins/humhub/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "humhub", - "version": "0.2.0", - "description": "HumHub via REST-API: Wiki-Seiten, Posts und Umfragen auflisten, anzeigen, anlegen und aktualisieren (humhub.py).", + "version": "0.3.0", + "description": "HumHub via REST-API: Wiki-Seiten, Posts, Umfragen und Kommentare auflisten, anzeigen, anlegen und aktualisieren (humhub.py).", "author": { "name": "inmedias.it" } diff --git a/plugins/humhub/skills/humhub/SKILL.md b/plugins/humhub/skills/humhub/SKILL.md index 7463e2d..145f442 100644 --- a/plugins/humhub/skills/humhub/SKILL.md +++ b/plugins/humhub/skills/humhub/SKILL.md @@ -80,6 +80,17 @@ und nicht Komfort — ohne Begrenzung antwortet die Instanz ab ~25 Umfragen ebenfalls mit 500. Ein fehlgeschlagener POST legt nichts an; vor einem zweiten Versuch trotzdem mit `poll-list` prüfen. +### Kommentare + +```bash +./humhub.py comment-list # Kommentare eines Inhalts +./humhub.py comment-create [datei|-] # Kommentar schreiben +``` + +Beide nehmen wie `fetch` eine **Content-ID** oder Perma-URL (nicht die Post-/ +Wiki-Seiten-ID) und lösen das Zielobjekt selbst auf — funktioniert für Posts +und Wiki-Seiten. + Inhalte (Markdown) aus Datei oder `-` (stdin) übergeben — nicht als langes Shell-Argument (Sonderzeichen). `container_id` akzeptiert eine numerische Container-ID, einen **Space-Slug** oder eine **Space-URL** (`resolve_container` diff --git a/plugins/humhub/skills/humhub/humhub.py b/plugins/humhub/skills/humhub/humhub.py index 03597ec..721a208 100755 --- a/plugins/humhub/skills/humhub/humhub.py +++ b/plugins/humhub/skills/humhub/humhub.py @@ -306,6 +306,48 @@ def cmd_space_list(args: argparse.Namespace) -> None: print("(keine Spaces gefunden)") +# ── Comment commands ───────────────────────────────────────────────────────── + +def cmd_comment_list(args: argparse.Namespace) -> None: + session, _ = get_session() + content_id = parse_content_ref(args.ref) + data = api_get(session, f"/comment/content/{content_id}") + results = data.get("results", data if isinstance(data, list) else []) + if not results: + print("(keine Kommentare)") + return + for c in results: + cid = c.get("id") + author = (c.get("createdBy") or {}).get("display_name", "?") + created = c.get("createdAt", "") + msg = (c.get("message") or "").replace("\n", " ")[:100] + print(f"ID {cid:>5} [{created}] {author}: {msg}") + + +def cmd_comment_create(args: argparse.Namespace) -> None: + session, _ = get_session() + content_id = parse_content_ref(args.ref) + message = read_file(args.file) + + envelope = api_get(session, f"/content/{content_id}") + meta = envelope.get("metadata", {}) + model = meta.get("object_model", "") + object_id = meta.get("object_id") + if not model or not object_id: + sys.exit(f"Error: Content {content_id} nicht auflösbar (object_model/object_id fehlen)") + + payload = { + "objectModel": model, + "objectId": object_id, + "Comment": {"message": message}, + } + data = api_post(session, "/comment", payload) + cid = data.get("id") + short_model = model.split("\\")[-1] + print(f"Kommentar erstellt (ID {cid}) auf {short_model} {object_id}") + print(f"Perma: https://humhub.inmedias.it/content/perma?id={content_id}") + + # ── Fetch (perma-/content-id-agnostisch) ───────────────────────────────────── def parse_content_ref(ref: str) -> int: @@ -460,6 +502,17 @@ def main() -> None: p.add_argument("--topics", default=None, help="Komma-getrennte Topic-Namen") p.set_defaults(func=cmd_post_create) + # comment-list + p = sub.add_parser("comment-list", help="Kommentare eines Inhalts auflisten") + p.add_argument("ref", help="Content-ID oder Perma-Link (…/content/perma?id=NNNN)") + p.set_defaults(func=cmd_comment_list) + + # comment-create + p = sub.add_parser("comment-create", help="Kommentar auf einen Inhalt (Post/Wiki-Seite) schreiben") + p.add_argument("ref", help="Content-ID oder Perma-Link (…/content/perma?id=NNNN)") + p.add_argument("file", help="Markdown-Datei oder '-' für stdin") + p.set_defaults(func=cmd_comment_create) + # post-update p = sub.add_parser("post-update", help="Post aktualisieren") p.add_argument("id", type=int, help="Post-ID")