flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

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

77 lines3,244 bytesCodeBlame
1import { 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({ workspace: params.owner, slug: 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 <span className="font-mono">{build.branch}</span>
42 {build.number != null && (
43 <Link to={`${base}/pull/${build.number}`} className="ml-2 text-base font-normal text-muted hover:underline">
44 #{build.number}
45 </Link>
46 )}
47 </>
48 )}
49 <span className="ml-3 font-mono text-sm font-normal text-faint">{build.commit.slice(0, 12)}</span>
50 </h1>
51 <p className="mt-1 text-sm text-muted">
52 {WORDS[build.status]} · started <TimeAgo at={build.createdAt} /> by {build.createdBy}
53 {build.buildSeconds != null && ` · built in ${build.buildSeconds} s`}
54 </p>
55 {build.status === "ready" && (
56 <a href={build.url} className="mt-3 inline-flex items-center gap-1.5 font-mono text-sm text-accent hover:underline">
57 {build.url.replace("https://", "")}
58 <ExternalLink size={12} />
59 </a>
60 )}
61 {build.error && (
62 <p className="mt-4 rounded-lg border border-danger/30 bg-danger/5 px-4 py-3 text-sm">{build.error}</p>
63 )}
64 {build.warnings.length > 0 && (
65 <ul className="mt-4 space-y-1 rounded-lg border border-warn/30 bg-warn/5 px-4 py-3 text-sm">
66 {build.warnings.map((warning) => (
67 <li key={warning}>{warning}</li>
68 ))}
69 </ul>
70 )}
71 <h2 className="mt-8 text-sm font-medium text-muted">Build log</h2>
72 <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">
73 {build.log || (build.status === "queued" || build.status === "building" ? "The log appears when the build finishes." : "No log.")}
74 </pre>
75 </div>
76 );
77}