MCPcopy Index your code
hub / github.com/OverloadBlitz/cloudcent-cli / main

Function main

scripts/render_comment.py:21–110  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19
20
21def main():
22 path = sys.argv[1]
23 project = sys.argv[2] if len(sys.argv) > 2 else "."
24
25 with open(path) as f:
26 doc = json.load(f)
27
28 totals = doc.get("totals", {})
29 monthly = totals.get("monthly_total", "0")
30 guardrail = doc.get("guardrail") or {}
31 resources = doc.get("resources", [])
32
33 passed = guardrail.get("passed", True)
34 has_thresholds = any(
35 guardrail.get(k) is not None for k in ("budget",)
36 ) or guardrail.get("breaches")
37
38 if not guardrail:
39 badge = "💰 Cost estimate"
40 elif passed:
41 badge = "✅ Cost guardrail passed"
42 else:
43 badge = "❌ Cost guardrail failed"
44
45 lines = [
46 f"## {badge}",
47 "",
48 f"**Project:** `{project}`",
49 f"**Estimated monthly cost:** **{money(monthly)}**",
50 ]
51
52 baseline = guardrail.get("baseline")
53 delta = guardrail.get("delta")
54 if baseline is not None and delta is not None:
55 pct = guardrail.get("delta_pct")
56 arrow = "🔺" if delta > 0 else ("🔻" if delta < 0 else "▪️")
57 pct_str = f" ({pct:+.1f}%)" if pct is not None else ""
58 lines.append(
59 f"**Change vs base branch:** {arrow} {money(delta)}{pct_str} "
60 f"(base {money(baseline)})"
61 )
62
63 budget = guardrail.get("budget")
64 if budget is not None:
65 lines.append(f"**Budget:** {money(budget)}")
66
67 breaches = guardrail.get("breaches") or []
68 if breaches:
69 lines += ["", "**Breaches:**"]
70 lines += [f"- ⚠️ {b}" for b in breaches]
71
72 # Per-resource cost table.
73 rows = []
74 for r in resources:
75 name = r.get("name", "")
76 sub = r.get("sub_label")
77 if sub:
78 name = f"{name} · {sub}"

Callers 1

render_comment.pyFile · 0.70

Calls 2

moneyFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected