#!/usr/bin/env python3 """ HiveGrid -> Plane Ticket-Sync (idempotent). Liest Zugang aus ~/.cli-tokens/plane (env-Format). ZIEL-PROJEKT ist HARDCODED auf HiveGrid (NICHT die PLANE_PROJECT-Variable, die faelschlich auf PowerLinked zeigt). Phase A: Cycles (W1-W4) + 7 Module + Labels + Modul "Externals" (12 Issues). Phase B (spaeter): restliche Module-Issues + modueluebergreifende Relations. Aufruf: python3 sync_plane.py Re-Run-sicher: existierende Objekte werden per Name erkannt, nicht dupliziert. """ import json, os, sys, urllib.request, urllib.error # ⚠ BOOTSTRAP-GUARD (seit 2026-06-16): Plane ist LIVE + manuell gescrubbt (Umlaute, PWA-Umbau, # v3-Defers). Dieses Skript matcht Issues per VOLLNAMEN — ein Re-Run nach dem Scrub fände # umbenannte Tickets NICHT wieder und legte DUPLIKATE an. Laufende Pflege -> scrub_plane.py # (Working-ID-Match, idempotent). Bewusster Neu-Bootstrap nur mit --force-bootstrap. if "--force-bootstrap" not in sys.argv: raise SystemExit( "✋ Bootstrap gesperrt: Plane ist live + gescrubbt — Re-Run würde Duplikate erzeugen.\n" " Laufende Änderungen -> .planning/plane-sync/scrub_plane.py (idempotent).\n" " Echter Neu-Bootstrap nur bewusst mit --force-bootstrap." ) # ---- Zugang ---- TOK = {} with open(os.path.expanduser("~/.cli-tokens/plane")) as f: for line in f: line = line.strip() if "=" in line and not line.startswith("#"): k, v = line.split("=", 1) TOK[k.strip()] = v.strip() BASE = TOK["PLANE_BASE_URL"].rstrip("/") WS = TOK["PLANE_WORKSPACE"] KEY = TOK["PLANE_API_KEY"] # HARDCODED: HiveGrid-Projekt (NICHT PowerLinked!) PID = "35d0d968-8ab3-40cc-97b8-b81d917dc5df" API = f"{BASE}/api/v1/workspaces/{WS}/projects/{PID}" GITEA = "https://git.tool-ctrl.de/toolctrl-labs/HiveGrid-Cloud/src/branch/main" MEMBERS = { "raffael": "8e34a88c-19c9-4565-b4f5-50415d623ce8", "akeshan": "8bf43e86-dc8a-4963-b57a-aeb5f2cc450a", "david": "6c1fc63f-133d-4f40-86e4-7f658a6edcc7", "dejan": "a5883f5e-3038-453c-9401-39ab1f40be9e", "haris": "48367c1f-20d2-44f1-8ae2-faf35aa2052a", } def req(method, path, body=None): url = path if path.startswith("http") else API + path data = json.dumps(body).encode() if body is not None else None r = urllib.request.Request(url, data=data, method=method) r.add_header("X-API-Key", KEY) r.add_header("Content-Type", "application/json") try: with urllib.request.urlopen(r, timeout=30) as resp: raw = resp.read().decode() return resp.status, (json.loads(raw) if raw else {}) except urllib.error.HTTPError as e: return e.code, {"_error": e.read().decode()[:400]} def get_all(path): """Cursor-paginierte Liste -> alle results.""" out, cursor = [], None while True: p = path + (("?cursor=" + cursor) if cursor else "") st, d = req("GET", p) if st >= 400: print(" GET FAIL", path, st, d); break if isinstance(d, list): out += d; break out += d.get("results", []) if d.get("next_page_results") and d.get("next_cursor"): cursor = d["next_cursor"] else: break return out # ---- States ---- states = {s["name"]: s["id"] for s in get_all("/states/")} BACKLOG = states.get("Backlog") print("States:", list(states.keys()), "| Backlog-id ok:", bool(BACKLOG)) # ---- Cycles (idempotent by name) ---- CYCLES = [ ("W1 — Fundament & Identitaet", "2026-06-16", "2026-06-19"), ("W2 — Plattform & CRM (Demo 1)", "2026-06-20", "2026-06-26"), ("W3 — Kern-Kette & Kommunikation (Demo 2)", "2026-06-27", "2026-07-03"), ("W4 — USP, Haertung & Launch", "2026-07-04", "2026-07-10"), ] existing_cycles = {c["name"]: c["id"] for c in get_all("/cycles/")} cycle_id = {} for name, start, end in CYCLES: if name in existing_cycles: cycle_id[name] = existing_cycles[name]; print("Cycle vorhanden:", name) else: st, d = req("POST", "/cycles/", {"name": name, "start_date": start, "end_date": end, "project_id": PID}) if st < 400: cycle_id[name] = d["id"]; print("Cycle angelegt:", name) else: print("Cycle FAIL:", name, st, d) W = {"W1": CYCLES[0][0], "W2": CYCLES[1][0], "W3": CYCLES[2][0], "W4": CYCLES[3][0]} # ---- Module (idempotent by name) ---- MODULES = ["Externals", "Raffael (Dev)", "Akeshan (Dev)", "David (Screens)", "Dejan (Website)", "Haris (Vertrieb)", "Noah (Validierung)"] existing_mods = {m["name"]: m["id"] for m in get_all("/modules/")} module_id = {} for name in MODULES: if name in existing_mods: module_id[name] = existing_mods[name]; print("Modul vorhanden:", name) else: st, d = req("POST", "/modules/", {"name": name}) if st < 400: module_id[name] = d["id"]; print("Modul angelegt:", name) else: print("Modul FAIL:", name, st, d) # ---- Labels (idempotent by name) ---- LABELS = { "typ:phase": "#2563eb", "typ:screen": "#db2777", "typ:external": "#d97706", "typ:website": "#0891b2", "typ:vertrieb": "#16a34a", "typ:validierung": "#7c3aed", "gate:W1": "#9ca3af", "gate:W2": "#6b7280", "gate:W3": "#4b5563", "gate:W4": "#374151", } existing_labels = {l["name"]: l["id"] for l in get_all("/labels/")} label_id = {} for name, color in LABELS.items(): if name in existing_labels: label_id[name] = existing_labels[name] else: st, d = req("POST", "/labels/", {"name": name, "color": color}) if st < 400: label_id[name] = d["id"]; print("Label angelegt:", name) else: print("Label FAIL:", name, st, d) # ---- Helper: Doku-HTML + Issue-Description ---- def doku_link(path, section): return f'{path.split("/")[-1]} — {section}' def desc(doku, blocked_by, blocks, owner, window, dod): lis = "".join(f"
📚 Doku
{doku}
⛔ blocked-by: {blocked_by or '—'}
"
f"➡️ blocks: {blocks or '—'}
"
f"👤 Owner: {owner} · 🗓 Fenster: {window}
✅ Definition of Done