pr_01m47d24b0e6n91zwymwxg0vpx/apps/web/app/routes/repo/deployment.tsx

75 lines3,101 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

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