g1t/apps/web/app/routes/repo/deployment.tsx
| 1 | import { ArrowLeft, ExternalLink } from "lucide-react"; |
| 2 | import { Link, data } from "react-router"; |
| 3 | |
| 4 | import type { Route } from "./+types/deployment"; |
| 5 | import { page } from "../../lib/meta"; |
| 6 | import { TimeAgo } from "../../components/ui"; |
| 7 | import { deployments } from "../../lib/services.server"; |
| 8 | import { getViewer, roleIn } from "../../lib/session.server"; |
| 9 | |
| 10 | export function meta({ params, ...args }: Route.MetaArgs) { |
| 11 | return page(args, { title: `Deployment · ${params.owner}/${params.repo} · g1t` }); |
| 12 | } |
| 13 | |
| 14 | export async function loader({ params, context }: Route.LoaderArgs) { |
| 15 | const viewer = getViewer(context); |
| 16 | if (!roleIn(viewer, params.owner)) throw data(null, { status: 404 }); |
| 17 | const found = await deployments.get({ workspace: params.owner, slug: params.repo }, params.id, viewer); |
| 18 | if (!found.ok) throw data(null, { status: 404 }); |
| 19 | return { build: found.value }; |
| 20 | } |
| 21 | |
| 22 | const WORDS = { |
| 23 | queued: "Waiting for a sandbox", |
| 24 | building: "Building", |
| 25 | ready: "Live", |
| 26 | failed: "Failed", |
| 27 | skipped: "Skipped", |
| 28 | } as const; |
| 29 | |
| 30 | export default function DeploymentPage({ loaderData, params }: Route.ComponentProps) { |
| 31 | const { build } = loaderData; |
| 32 | const base = `/${params.owner}/${params.repo}`; |
| 33 | return ( |
| 34 | <div className="mx-auto max-w-5xl"> |
| 35 | <Link to={`${base}/deployments`} className="inline-flex items-center gap-1 text-sm text-muted hover:text-fg"> |
| 36 | <ArrowLeft size={14} /> |
| 37 | Deployments |
| 38 | </Link> |
| 39 | <h1 className="mt-3 text-xl font-semibold tracking-tight"> |
| 40 | {build.kind === "production" ? "Production" : ( |
| 41 | <> |
| 42 | Preview of <span className="font-mono">{build.branch}</span> |
| 43 | {build.number != null && ( |
| 44 | <Link to={`${base}/pull/${build.number}`} className="ml-2 text-base font-normal text-muted hover:underline"> |
| 45 | #{build.number} |
| 46 | </Link> |
| 47 | )} |
| 48 | </> |
| 49 | )} |
| 50 | <span className="ml-3 font-mono text-sm font-normal text-faint">{build.commit.slice(0, 12)}</span> |
| 51 | </h1> |
| 52 | <p className="mt-1 text-sm text-muted"> |
| 53 | {WORDS[build.status]} · started <TimeAgo at={build.createdAt} /> by {build.createdBy} |
| 54 | {build.buildSeconds != null && ` · built in ${build.buildSeconds} s`} |
| 55 | </p> |
| 56 | {build.status === "ready" && ( |
| 57 | <a href={build.url} className="mt-3 inline-flex items-center gap-1.5 font-mono text-sm text-accent hover:underline"> |
| 58 | {build.url.replace("https://", "")} |
| 59 | <ExternalLink size={12} /> |
| 60 | </a> |
| 61 | )} |
| 62 | {build.error && ( |
| 63 | <p className="mt-4 rounded-lg border border-danger/30 bg-danger/5 px-4 py-3 text-sm">{build.error}</p> |
| 64 | )} |
| 65 | {build.warnings.length > 0 && ( |
| 66 | <ul className="mt-4 space-y-1 rounded-lg border border-warn/30 bg-warn/5 px-4 py-3 text-sm"> |
| 67 | {build.warnings.map((warning) => ( |
| 68 | <li key={warning}>{warning}</li> |
| 69 | ))} |
| 70 | </ul> |
| 71 | )} |
| 72 | <h2 className="mt-8 text-sm font-medium text-muted">Build log</h2> |
| 73 | <pre className="mt-3 max-h-[70vh] overflow-auto rounded-xl border border-line bg-bg p-4 font-mono text-xs leading-relaxed text-muted"> |
| 74 | {build.log || (build.status === "queued" || build.status === "building" ? "The log appears when the build finishes." : "No log.")} |
| 75 | </pre> |
| 76 | </div> |
| 77 | ); |
| 78 | } |