import { Layout } from "../components/Layout"; import type { Deployment, Command } from "../index"; interface DeploymentDetailProps { deployment: Deployment; commands: Command[]; } function getStatusBadge(status: string): string { const statusClass = status === "success" ? "badge-success" : status === "failed" ? "badge-failed" : status === "pending" ? "badge-pending" : "badge-in_progress"; return `${status}`; } function formatDate(dateString: string | undefined): string { if (!dateString) return "N/A"; const date = new Date(dateString); return date.toLocaleString(); } function escapeHtml(text: string | undefined): string { if (!text) return ""; return text .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); } export function DeploymentDetail({ deployment, commands }: DeploymentDetailProps): string { const content = `

Deployment #${deployment.id}

← Back to List
Repository:

${escapeHtml(deployment.repository)}

Branch:

${escapeHtml(deployment.branch) || "N/A"}

Commit:

${deployment.commit_hash ? `${escapeHtml(deployment.commit_hash)}` : "N/A"}

Status:

${getStatusBadge(deployment.status)}

Created At:

${formatDate(deployment.created_at)}

Commands (${commands.length})

${commands.length === 0 ? "

No commands executed.

" : commands.map((command) => `
${escapeHtml(command.command)}
${command.success ? 'Success' : 'Failed'} ${command.exit_code !== null ? `Exit: ${command.exit_code}` : ""}
${command.stdout ? `
Output:
${escapeHtml(command.stdout)}
` : ""} ${command.stderr ? `
Error:
${escapeHtml(command.stderr)}
` : ""}
`).join("")}
`; return Layout({ title: `Deployment #${deployment.id}`, children: content }); }