diff --git a/.gitea/workflows/dry-run.yml b/.gitea/workflows/dry-run.yml index ec643e6..b980641 100644 --- a/.gitea/workflows/dry-run.yml +++ b/.gitea/workflows/dry-run.yml @@ -73,22 +73,14 @@ jobs: print(f"[{env}] Reconciler call failed: {e}") continue - # Format as markdown grouped by action + # Format as markdown table ops = data.get("operations", []) summary = data.get("summary", {}) lines = [f"## Reconciliation Plan: `{env}`\n"] if not ops: lines.append("No changes detected.\n") else: - groups = {"Create": [], "Update": [], "Delete": []} - for op in ops: - t = op["type"] - if t.startswith("create"): groups["Create"].append(op) - elif t.startswith("delete"): groups["Delete"].append(op) - else: groups["Update"].append(op) - def fmt_val(v): - """Format a value for display in markdown.""" if isinstance(v, bool): return str(v).lower() if isinstance(v, list): @@ -97,14 +89,33 @@ jobs: return "(none)" return str(v) - def fmt_create_details(op): - """Summarize key fields for a create operation.""" + def get_action(op): + """Derive a human-readable action from the operation.""" + t = op["type"] + changes = op.get("changes", []) + # For updates, check if it's just an enable/disable toggle + if not t.startswith("create") and not t.startswith("delete"): + if len(changes) == 1 and changes[0]["field"] == "enabled": + return "disable" if changes[0]["to"] is False else "enable" + return "update" + return t.split("_", 1)[0] + + def fmt_details(op, action): + """Format details based on action type.""" + if action == "delete": + return "" + if action in ("enable", "disable"): + return "" + changes = op.get("changes", []) + if changes: + parts = [] + for c in changes: + parts.append(f"`{c['field']}`: {fmt_val(c['from'])} → {fmt_val(c['to'])}") + return "; ".join(parts) d = op.get("details", {}) if not d: return "" parts = [] - if "enabled" in d: - parts.append(f"enabled={fmt_val(d['enabled'])}") if "sources" in d and "destinations" in d: parts.append(f"{fmt_val(d['sources'])} → {fmt_val(d['destinations'])}") if "auto_groups" in d: @@ -115,32 +126,14 @@ jobs: parts.append(f"peers: {fmt_val(d['peers'])}") return "; ".join(parts) if parts else "" - def fmt_changes(op): - """Format field changes as 'field: old → new'.""" - changes = op.get("changes", []) - if not changes: - return "" - parts = [] - for c in changes: - parts.append(f"`{c['field']}`: {fmt_val(c['from'])} → {fmt_val(c['to'])}") - return "; ".join(parts) - - for action, items in groups.items(): - if not items: - continue - lines.append(f"### {action} ({len(items)})\n") - lines.append("| Resource | Name | Details |") - lines.append("|----------|------|---------|") - for op in items: - resource = op["type"].split("_", 1)[1] if "_" in op["type"] else op["type"] - if action == "Update": - detail = fmt_changes(op) - elif action == "Create": - detail = fmt_create_details(op) - else: - detail = "" - lines.append(f"| {resource} | {op['name']} | {detail} |") - lines.append("") + lines.append("| Action | Resource | Name | Details |") + lines.append("|--------|----------|------|---------|") + for op in ops: + resource = op["type"].split("_", 1)[1] if "_" in op["type"] else op["type"] + action = get_action(op) + detail = fmt_details(op, action) + lines.append(f"| {action} | {resource} | {op['name']} | {detail} |") + lines.append("") c, u, d = summary.get("created", 0), summary.get("updated", 0), summary.get("deleted", 0) lines.append(f"**Total: {c} create, {u} update, {d} delete**")