297 lines
14 KiB
Python
297 lines
14 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
scrub_plane.py — idempotentes Pflege-/Scrub-Skript für die HiveGrid-Plane-Tickets.
|
|
|
|
Anders als sync_plane*.py (Bootstrap, Match per Vollname) matcht dieses Skript Issues
|
|
per WORKING-ID (Präfix vor ' · ') → Namens-Änderungen (Umlaut-Fix, PWA-Umbau) erzeugen
|
|
KEINE Duplikate. Es PATCHt nur bei echtem Diff und ist voll re-run-sicher.
|
|
|
|
Operationen:
|
|
A) Umlaut-Fix: kuratierte Wort-Map (KEIN generisches ae→ä!) auf Name + description_html
|
|
ALLER Issues + die 2 Cycle-Namen mit ASCII-Umlauten.
|
|
B) PWA-only-Umbau (Entscheidung #14 / AD-17, 2026-06-16):
|
|
- VA-P27a/b + VD-3 → Mobile-PWA-Ausbau umgewidmet (Expo/native/Store raus)
|
|
- VEXT-4, VJ-1 → v3-Backlog (aus Cycle entfernt, Label v2→v3)
|
|
- VD-6, EXT-13, VJ-3 → App-Store-/native-Teil entfernt, Rest bleibt
|
|
C) Board-States/Labels-Hygiene (2026-06-28): "In Review" gehört in Gruppe started
|
|
(nicht completed, sonst zählen wartende Tickets als erledigt); neuer State
|
|
"Blocked / On Hold" + Labels wartet-auf-screen / wartet-extern (idempotent angelegt).
|
|
|
|
Default = DRY-RUN (zeigt nur Diffs, schreibt nichts). Mit --apply scharf schalten.
|
|
"""
|
|
import json, os, re, sys, time, urllib.request, urllib.error
|
|
|
|
APPLY = "--apply" in sys.argv
|
|
|
|
TOK = {}
|
|
for line in open(os.path.expanduser("~/.cli-tokens/plane")):
|
|
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"]
|
|
PID = "35d0d968-8ab3-40cc-97b8-b81d917dc5df" # HiveGrid (hardcoded, NICHT PowerLinked)
|
|
API = f"{BASE}/api/v1/workspaces/{WS}/projects/{PID}"
|
|
GITEA = "https://git.tool-ctrl.de/toolctrl-labs/HiveGrid-Cloud/src/branch/main"
|
|
|
|
def _once(method, url, body):
|
|
r = urllib.request.Request(url, data=(json.dumps(body).encode() if body is not None else None), 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()[:300]}
|
|
|
|
def req(method, path, body=None):
|
|
url = path if path.startswith("http") else API + path
|
|
st, d = 0, {}
|
|
for _ in range(8):
|
|
st, d = _once(method, url, body)
|
|
if st == 429:
|
|
time.sleep(25); continue
|
|
if APPLY and method != "GET":
|
|
time.sleep(0.4)
|
|
return st, d
|
|
return st, d
|
|
|
|
def get_all(path):
|
|
out, cursor = [], None
|
|
while True:
|
|
st, d = req("GET", path + (("?per_page=100&cursor=" + cursor) if cursor else "?per_page=100"))
|
|
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
|
|
|
|
# ---------- A) Umlaut-Fix: kuratierte Wort-Map (case-sensitiv, wortgenau) ----------
|
|
UML = {
|
|
"faellig": "fällig", "fuer": "für", "Bruecke": "Brücke",
|
|
"Geschaeftsdaten": "Geschäftsdaten", "Konformitaet": "Konformität",
|
|
"bestaetigt": "bestätigt", "geprueft": "geprüft", "gewaehlt": "gewählt",
|
|
"gruen": "grün", "pruefen": "prüfen",
|
|
}
|
|
_UML_RE = [(re.compile(r'\b' + re.escape(k) + r'\b'), v) for k, v in UML.items()]
|
|
def fix_uml(s):
|
|
if not s: return s
|
|
for rx, v in _UML_RE:
|
|
s = rx.sub(v, s)
|
|
return s
|
|
|
|
CYCLE_RENAME = {
|
|
"W1 — Fundament & Identitaet": "W1 — Fundament & Identität",
|
|
"W4 — USP, Haertung & Launch": "W4 — USP, Härtung & Launch",
|
|
}
|
|
|
|
# ---------- B) PWA-only-Umbau: Spezifikation je Working-ID ----------
|
|
def link(path, sec): return f'<a href="{GITEA}/{path}">{path.split("/")[-1]} — {sec}</a>'
|
|
def desc(doks, bby, blk, owner, win, dod):
|
|
dl = "<br/>".join(link(p, s) for p, s in doks)
|
|
li = "".join(f"<li>{d}</li>" for d in dod)
|
|
return (f"<p><b>📚 Doku</b><br/>{dl}</p>"
|
|
f"<p><b>⛔ blocked-by:</b> {bby or '—'}<br/><b>➡️ blocks:</b> {blk or '—'}<br/>"
|
|
f"<b>👤 Owner:</b> {owner} · <b>🗓 Fenster:</b> {win}</p>"
|
|
f"<p><b>✅ Definition of Done</b></p><ul>{li}</ul>")
|
|
|
|
RM, RV2 = ".planning/ROADMAP.md", ".planning/ROADMAP-V2.md"
|
|
AD = "docs/ARCHITECTURE-DECISIONS.md"
|
|
|
|
# Felder: name, desc-Args, cycle ('keep'|None=raus), set_v3(bool)
|
|
PWA = {
|
|
"VA-P27a": dict(
|
|
name="VA-P27a · Mobile-PWA-Ausbau: Installierbarkeit + Service-Worker-Offline + Web-Push/Kamera (M167/168)",
|
|
doks=[(RM,"Phase 27"),(".planning/ticket-docs/VA-P27a.md","Bau-Spec"),(AD,"AD-17 PWA-only")],
|
|
bby="R-P9b (OfflineSyncQueue), AK-P21 (notify→Web-Push)", blk="VA-P27b", owner="akeshan",
|
|
win="v2-W2 (fällig 2026-07-25)", cycle="keep", set_v3=False,
|
|
dod=["Installierbare PWA: Web-App-Manifest + Add-to-Homescreen + Standalone-Display",
|
|
"Pre-Cache beim Login + Offline-Write-Queue (Foto/Note/Task/Checklist/Acceptance/Chat) über Service-Worker + IndexedDB",
|
|
"Web-Push (VAPID) + Kamera/Foto via Web-APIs (lokaler Resize); 2FA bleibt — kein Expo/EAS, kein nativer Client (AD-17)"]),
|
|
"VA-P27b": dict(
|
|
name="VA-P27b · Mobile-PWA-Ausbau: mobile Navigation + Offline-Sync + PWA-Härtung (M169/170/171)",
|
|
doks=[(RM,"Phase 27"),(".planning/ticket-docs/VA-P27b.md","Bau-Spec"),(AD,"AD-17 PWA-only")],
|
|
bby="VA-P27a", blk="—", owner="akeshan",
|
|
win="v2-W3 (fällig 2026-07-27)", cycle="keep", set_v3=False,
|
|
dod=["Mobile Navigation (Baustelle/Büro) + mobile Routes",
|
|
"Sync-on-Reconnect idempotent (lokale UUID) + Konflikt-Resolution",
|
|
"PWA-Härtung: Web-Checkout (kein Pricing-Store-UI), Account-Löschung erreichbar, Force-Update via Service-Worker-Versionierung, Deeplinks — keine App-Store-Compliance"]),
|
|
"VD-3": dict(
|
|
name="VD-3 · Screens: Mobile-PWA-Shell (Touch, Tab-Bar, Offline-Zustände)",
|
|
doks=[(RV2,"P27"),(".planning/ticket-docs/VD-P27.md","Screen-Spec"),(AD,"AD-17 PWA-only")],
|
|
bby="D-D0b", blk="VA-P27a, VA-P27b", owner="david",
|
|
win="v2-W2 (fällig 2026-07-22)", cycle="keep", set_v3=False,
|
|
dod=["Mobile-PWA-Shell: Tab-Bar, Touch-Paradigma, Offline-Zustände, Sync-Queue/Konflikt-View, Install-Hinweis (Add-to-Homescreen) — kein natives Paradigma"]),
|
|
"VD-6": dict(
|
|
name="VD-6 · Screens: v2-Politur (extern) + Visual-Reg-Baselines",
|
|
doks=[(".planning/ticket-docs/VD-6.md","Bau-Spec")],
|
|
bby="VD-2, VD-3", blk="—", owner="david",
|
|
win="v2-W3 (fällig 2026-07-31)", cycle="keep", set_v3=False,
|
|
dod=["v2-Politur extern sichtbarer Flächen + Visual-Reg-Baselines",
|
|
"App-Store-Screenshots/-Assets entfallen — PWA-only (AD-17), kein App-Store"]),
|
|
"EXT-13": dict(
|
|
name="EXT-13 · v2-Vorlauf-Externals (Gmail-Scope/Entra)",
|
|
doks=[(".planning/ticket-docs/EXT-13.md","Bau-Spec"),(AD,"AD-17 PWA-only")],
|
|
bby="—", blk="v2 (Postfach-Sync)", owner="raffael",
|
|
win="W3 (fällig 2026-06-29)", cycle="keep", set_v3=False,
|
|
dod=["Gmail-Restricted-Scope-Antrag (Wochen Vorlauf!)",
|
|
"MS-Entra-App (Outlook/Graph → v2)",
|
|
"Google Play + FCM/APNs entfallen — PWA-only, kein App-Store; Push = Web-Push (VAPID, eigene Keys)"]),
|
|
"VJ-3": dict(
|
|
name="VJ-3 · Website-Update: Portal/Mobile-PWA/KWP als Features live",
|
|
doks=[(".planning/ticket-docs/VJ-3.md","Bau-Spec"),(AD,"AD-30 Customer-Portal")],
|
|
bby="VA-P26b, VA-P26c, VA-P27b, VR-P32c", blk="—", owner="dejan",
|
|
win="nach allen Feature-Blockern (Ziel offen)", cycle="keep", set_v3=False,
|
|
dod=["Feature-Seiten Portal/Mobile-PWA/KWP live",
|
|
"Portal-Seite erklärt Preise, Standardhost-Fallback, 30-Tage-Reclaim-Cooldown und Domainwechsel als neue Einrichtung gemäß AD-30",
|
|
"Store-Badges entfallen — PWA-only (AD-17), kein App-Store; stattdessen Add-to-Homescreen-Hinweis"]),
|
|
# --- v3-Backlog: aus Cycle raus, Label v2→v3 ---
|
|
"VEXT-4": dict(
|
|
name="VEXT-4 · [v3] App-Store-Einreichung Apple + Google (zurückgestellt — PWA-only)",
|
|
doks=[(AD,"AD-17 PWA-only"),(RM,"Phase 27")],
|
|
bby="—", blk="—", owner="akeshan",
|
|
win="v3 (zurückgestellt — kein App-Store in v1/v2)", cycle=None, set_v3=True,
|
|
dod=["⏸ Zurückgestellt auf v3: kein App-Store in v1/v2 (PWA-only, AD-17).",
|
|
"Erst relevant, wenn ein nativer Client (v3) gebaut wird — dann: Build-Einreichung Apple + Google, TestFlight/interner Track, Privacy-Manifest."]),
|
|
"VJ-1": dict(
|
|
name="VJ-1 · [v3] App-Store-Metadaten (zurückgestellt — PWA-only)",
|
|
doks=[(AD,"AD-17 PWA-only")],
|
|
bby="—", blk="—", owner="dejan",
|
|
win="v3 (zurückgestellt — kein App-Store in v1/v2)", cycle=None, set_v3=True,
|
|
dod=["⏸ Zurückgestellt auf v3: kein App-Store in v1/v2 (PWA-only, AD-17).",
|
|
"Erst relevant mit nativem Client (v3): Store-Listings Apple + Google (Beschreibung/Keywords/Screenshots/Datenschutz)."]),
|
|
}
|
|
|
|
def wid_of(name): return name.split(" · ", 1)[0] if " · " in name else None
|
|
|
|
# ---------- Lauf ----------
|
|
print(f"=== scrub_plane.py — {'APPLY (scharf)' if APPLY else 'DRY-RUN (nur Anzeige)'} ===\n")
|
|
labels = {l["name"]: l["id"] for l in get_all("/labels/")}
|
|
cycles = get_all("/cycles/")
|
|
issues = get_all("/issues/")
|
|
|
|
# v3-Label sicherstellen
|
|
V3 = labels.get("v3")
|
|
if V3 is None:
|
|
if APPLY:
|
|
st, d = req("POST", "/labels/", {"name": "v3", "color": "#6b7280"})
|
|
if st < 400: V3 = d["id"]; print("Label 'v3' angelegt.")
|
|
else: print("Label v3 FAIL:", st, d)
|
|
else:
|
|
print("[würde Label 'v3' anlegen]")
|
|
V2 = labels.get("v2")
|
|
|
|
# ---------- C) Board-States/Labels sicherstellen (idempotent) ----------
|
|
# Workflow-Hygiene: "In Review" muss in Gruppe started liegen (nicht completed, sonst
|
|
# zaehlen wartende Tickets als erledigt). Neuer State "Blocked / On Hold" fuer "Code
|
|
# fertig, liegt bewusst" + Labels fuer den Blocker-Grund (typuebergreifend, damit Davids
|
|
# Screen-Board sauber bleibt). Siehe Operation C im Docstring.
|
|
print("\n--- Board-States/Labels ---")
|
|
WANT_LABELS = {"wartet-auf-screen": "#8B5CF6", "wartet-extern": "#0EA5E9"}
|
|
for lname, lcolor in WANT_LABELS.items():
|
|
if lname in labels:
|
|
print(f" ok (bereits): Label '{lname}'")
|
|
elif APPLY:
|
|
st, d = req("POST", "/labels/", {"name": lname, "color": lcolor})
|
|
if st < 400: labels[lname] = d["id"]; print(f" Label '{lname}' angelegt.")
|
|
else: print(f" Label '{lname}' FAIL:", st, d)
|
|
else:
|
|
print(f" [wuerde Label '{lname}' anlegen]")
|
|
|
|
states_by_name = {s["name"]: s for s in get_all("/states/")}
|
|
ir = states_by_name.get("In Review")
|
|
if ir and ir.get("group") != "started":
|
|
print(f" FIX: 'In Review' group {ir.get('group')} -> started")
|
|
if APPLY:
|
|
st, d = req("PATCH", f"/states/{ir['id']}/", {"group": "started", "sequence": 75000})
|
|
if st >= 400: print(" FAIL:", st, d)
|
|
elif ir:
|
|
print(" ok (bereits): 'In Review' in started")
|
|
if "Blocked / On Hold" in states_by_name:
|
|
print(" ok (bereits): State 'Blocked / On Hold'")
|
|
elif APPLY:
|
|
st, d = req("POST", "/states/", {"name": "Blocked / On Hold", "color": "#F59E0B",
|
|
"group": "started", "sequence": 80000})
|
|
if st < 400: print(" State 'Blocked / On Hold' angelegt.")
|
|
else: print(" State 'Blocked / On Hold' FAIL:", st, d)
|
|
else:
|
|
print(" [wuerde State 'Blocked / On Hold' anlegen]")
|
|
|
|
# Cycle-Namen fixen
|
|
print("\n--- Cycle-Namen ---")
|
|
cyc_by_name = {c["name"]: c for c in cycles}
|
|
for old, new in CYCLE_RENAME.items():
|
|
c = cyc_by_name.get(old)
|
|
if not c:
|
|
if new in cyc_by_name: print(f" ok (bereits): {new}")
|
|
else: print(f" ?? Cycle nicht gefunden: {old}")
|
|
continue
|
|
print(f" RENAME: '{old}' -> '{new}'")
|
|
if APPLY:
|
|
st, d = req("PATCH", f"/cycles/{c['id']}/", {"name": new})
|
|
if st >= 400: print(" FAIL:", st, d)
|
|
|
|
# Issue-Map per Working-ID
|
|
wid2issue = {}
|
|
for i in issues:
|
|
w = wid_of(i["name"])
|
|
if w: wid2issue[w] = i
|
|
|
|
# cycle-membership map (issue_id -> cycle_id) für v3-Defer (Remove)
|
|
i2cyc = {}
|
|
for c in cycles:
|
|
for it in get_all(f"/cycles/{c['id']}/cycle-issues/"):
|
|
i2cyc[it["id"]] = c["id"]
|
|
|
|
patched = uml_only = pwa_changed = 0
|
|
print("\n--- Issues ---")
|
|
for i in issues:
|
|
w = wid_of(i["name"]);
|
|
if not w: continue
|
|
old_name = i["name"]; old_html = i.get("description_html") or ""
|
|
spec = PWA.get(w)
|
|
if spec:
|
|
new_name = spec["name"]
|
|
new_html = desc(spec["doks"], spec["bby"], spec["blk"], spec["owner"], spec["win"], spec["dod"])
|
|
else:
|
|
new_name = fix_uml(old_name)
|
|
new_html = fix_uml(old_html)
|
|
name_diff = new_name != old_name
|
|
html_diff = new_html != old_html
|
|
# Labels (nur für v3-Defer)
|
|
lbl_change = None
|
|
if spec and spec.get("set_v3") and V3:
|
|
cur = list(i.get("labels", []))
|
|
new_lbls = [x for x in cur if x != V2] + ([V3] if V3 not in cur else [])
|
|
if set(new_lbls) != set(cur): lbl_change = new_lbls
|
|
# Cycle-Remove (v3-Defer)
|
|
cyc_remove = None
|
|
if spec and spec.get("cycle") is None:
|
|
cid = i2cyc.get(i["id"])
|
|
if cid: cyc_remove = cid
|
|
if not (name_diff or html_diff or lbl_change or cyc_remove):
|
|
continue
|
|
tag = "PWA" if spec else "uml"
|
|
if spec: pwa_changed += 1
|
|
else: uml_only += 1
|
|
print(f" [{tag}] HIV-{i['sequence_id']} {w}")
|
|
if name_diff: print(f" name: {old_name}\n -> {new_name}")
|
|
if html_diff and not spec: print(f" desc: Umlaut-Fix angewandt")
|
|
if html_diff and spec: print(f" desc: komplett neu (PWA-Umbau)")
|
|
if lbl_change is not None: print(f" label: v2 -> v3")
|
|
if cyc_remove: print(f" cycle: aus Cycle entfernen (→ v3-Backlog)")
|
|
if APPLY:
|
|
body = {}
|
|
if name_diff: body["name"] = new_name
|
|
if html_diff: body["description_html"] = new_html
|
|
if lbl_change is not None: body["labels"] = lbl_change
|
|
if body:
|
|
st, d = req("PATCH", f"/issues/{i['id']}/", body)
|
|
if st >= 400: print(" PATCH FAIL:", st, d); continue
|
|
if cyc_remove:
|
|
st, d = req("DELETE", f"/cycles/{cyc_remove}/cycle-issues/{i['id']}/")
|
|
if st >= 400: print(" CYCLE-REMOVE FAIL:", st, d)
|
|
patched += 1
|
|
|
|
print(f"\n=== {'GEÄNDERT' if APPLY else 'WÜRDE ÄNDERN'}: {uml_only} (Umlaut) + {pwa_changed} (PWA) Issues ===")
|
|
if not APPLY: print("Dry-Run — nichts geschrieben. Mit --apply scharf schalten.")
|