File size: 4,507 Bytes
92f3410
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cd249cc
 
 
 
 
 
 
 
 
 
 
92f3410
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"""Export utilities for reports in multiple formats."""

from __future__ import annotations

import json
from datetime import datetime
from typing import Any, Dict, Optional


def export_json(data: Dict[str, Any], filename: Optional[str] = None) -> str:
    """Export data as JSON."""
    output = json.dumps(data, indent=2, default=str)
    if filename:
        with open(filename, 'w') as f:
            f.write(output)
    return output


def export_markdown(data: Dict[str, Any], filename: Optional[str] = None) -> str:
    """Export readiness report as Markdown."""
    md_lines = [
        f"# Deployment Readiness Report",
        f"**Generated**: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}",
        "",
        "## Summary",
        ""
    ]
    
    # Plan summary
    if "plan" in data:
        plan = data["plan"]
        md_lines.extend([
            f"### Deployment Plan",
            plan.get("summary", "No summary available"),
            "",
            "#### Checklist Items:",
            ""
        ])
        for item in plan.get("items", [])[:10]:
            status_icon = "βœ…" if item.get("status") == "done" else "⏳"
            md_lines.append(f"- {status_icon} **{item.get('title', 'Untitled')}**")
            md_lines.append(f"  - Category: {item.get('category', 'general')}")
            md_lines.append(f"  - {item.get('description', '')}")
            md_lines.append("")
    
    # Review decision
    if "review" in data:
        review = data["review"]
        decision = review.get("decision", "unknown")
        confidence = review.get("confidence", 0.0)
        md_lines.extend([
            "## Review Decision",
            f"**Decision**: {decision.upper()}",
            f"**Confidence**: {confidence:.1%}",
            "",
            "### Findings:",
            ""
        ])
        for finding in review.get("findings", [])[:5]:
            severity = finding.get("severity", "medium")
            severity_icon = "πŸ”΄" if severity == "high" else "🟑" if severity == "medium" else "🟒"
            md_lines.append(f"- {severity_icon} **{severity.upper()}**: {finding.get('note', '')}")
        md_lines.append("")
    
    # Documentation references
    if "docs_references" in data and data["docs_references"]:
        docs_refs = data["docs_references"]
        md_lines.extend([
            "## Documentation References",
            f"**Framework**: {docs_refs.get('framework', 'Unknown')}",
            f"**Platform**: {docs_refs.get('platform', 'Unknown')}",
            "",
            "### Lookups:",
            ""
        ])
        for lookup in docs_refs.get("lookups", [])[:5]:
            lookup_type = lookup.get("type", "unknown")
            status = lookup.get("status", "unknown")
            md_lines.append(f"- **{lookup_type}**: {status}")
        md_lines.append("")
    
    # Deployment actions
    if "deployment" in data and data["deployment"]:
        deploy = data["deployment"]
        md_lines.extend([
            "## Deployment Actions",
            f"**Repository**: {deploy.get('repo', 'Not configured')}",
            f"**Branch**: {deploy.get('branch', 'main')}",
            f"**Ready**: {'βœ…' if deploy.get('ready') else '❌'}",
            "",
            "### Actions:",
            ""
        ])
        for action in deploy.get("actions", [])[:5]:
            action_type = action.get("type", "unknown")
            message = action.get("message", action.get("title", ""))
            md_lines.append(f"- **{action_type}**: {message}")
        md_lines.append("")
    
    # Sponsor synthesis (optional)
    sponsor_data = data.get("sponsor_synthesis")
    if sponsor_data:
        md_lines.extend([
            "## Sponsor LLM Cross-Checks",
            "",
        ])
        for key, value in sponsor_data.items():
            md_lines.append(f"### {key.replace('_', ' ').title()}")
            md_lines.append(str(value))
            md_lines.append("")
    
    output = "\n".join(md_lines)
    if filename:
        with open(filename, 'w') as f:
            f.write(output)
    return output


def export_pdf(data: Dict[str, Any], filename: Optional[str] = None) -> bytes:
    """Export as PDF (requires markdown2pdf or similar)."""
    # For now, return markdown as PDF would require additional dependencies
    # In production, use libraries like weasyprint or reportlab
    md_content = export_markdown(data)
    # Convert markdown to PDF would go here
    return md_content.encode('utf-8')