flagon-io/g1t

public

Git for AI scale: a forge for thousands of agents working on the same code at once.

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

297 lines12,757 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 { ExternalLink, Globe, Rocket, RotateCw, Trash2 } from "lucide-react";
2import type { ReactNode } from "react";
3import { Form, Link, data, useNavigation } from "react-router";
4
Projects: what a workspace builds and runs, first on every page5import type { Deployment, FeatureState } from "@g1t/contracts";
Deployments: a preview for every pull request, production on g1t.page6
Projects: what a workspace builds and runs, first on every page7import { host, StatusDot } from "../../components/deploy";
8
Deployments: a preview for every pull request, production on g1t.page9import type { Route } from "./+types/deployments";
Social cards for every page: og.g1t.sh10import { page } from "../../lib/meta";
Secrets and variables: one list, rows per environment, for workflows and deployments11import { Button, ButtonLink, EmptyState, ErrorText, TimeAgo } from "../../components/ui";
Deployments: a preview for every pull request, production on g1t.page12import { billing, deployments } from "../../lib/services.server";
13import { assertSameOrigin, getViewer, requireUser, roleIn, unwrap } from "../../lib/session.server";
14
Social cards for every page: og.g1t.sh15export function meta({ params, ...args }: Route.MetaArgs) {
16 return page(args, { title: `Deployments · ${params.owner}/${params.repo} · g1t` });
Deployments: a preview for every pull request, production on g1t.page17}
18
19export async function loader({ params, context }: Route.LoaderArgs) {
20 const viewer = getViewer(context);
21 const role = roleIn(viewer, params.owner);
22 // Members only; to anyone else the page does not exist.
23 if (!role) throw data(null, { status: 404 });
Projects: what a workspace builds and runs, first on every page24 const ref = { workspace: params.owner, slug: params.repo };
Deployments: a preview for every pull request, production on g1t.page25 const [settings, list, features] = await Promise.all([
Projects: what a workspace builds and runs, first on every page26 deployments.settings(ref, viewer),
27 deployments.list(ref, viewer),
Deployments: a preview for every pull request, production on g1t.page28 billing.features(params.owner, viewer),
29 ]);
30 const plan = unwrap(features).find((state) => state.plan.feature === "deployments") ?? null;
31 return { role, settings: unwrap(settings), ...unwrap(list), plan };
32}
33
34export async function action({ request, params, context }: Route.ActionArgs) {
35 assertSameOrigin(request);
36 const user = requireUser(context, request);
37 const form = await request.formData();
Projects: what a workspace builds and runs, first on every page38 const ref = { workspace: params.owner, slug: params.repo };
Deployments: a preview for every pull request, production on g1t.page39 const intent = form.get("intent");
Projects: what a workspace builds and runs, first on every page40 const branch = form.get("branch") ? String(form.get("branch")) : null;
Deployments: a preview for every pull request, production on g1t.page41 if (intent === "redeploy") {
Projects: what a workspace builds and runs, first on every page42 const started = await deployments.redeploy(user, ref, branch);
Deployments: a preview for every pull request, production on g1t.page43 return started.ok ? { notice: "Build started." } : { error: started.error.message };
44 }
45 if (intent === "take-down") {
Projects: what a workspace builds and runs, first on every page46 const done = await deployments.takeDown(user, ref, branch);
Deployments: a preview for every pull request, production on g1t.page47 return done.ok ? { notice: "Taken down." } : { error: done.error.message };
48 }
49 if (intent === "enable" || intent === "disable") {
Projects: what a workspace builds and runs, first on every page50 const saved = await deployments.updateSettings(user, ref, { enabled: intent === "enable" });
Deployments: a preview for every pull request, production on g1t.page51 return saved.ok
52 ? { notice: intent === "enable" ? "Deployments are on. Production is building." : "Deployments are off, and every app is down." }
53 : { error: saved.error.message };
54 }
Secrets and variables: one list, rows per environment, for workflows and deployments55 return { error: "Unknown request." };
Deployments: a preview for every pull request, production on g1t.page56}
57
58export default function RepoDeployments({ loaderData, actionData, params }: Route.ComponentProps) {
59 const { settings, deployments: builds, live, plan } = loaderData;
60 const busy = useNavigation().state === "submitting";
61 const base = `/${params.owner}/${params.repo}`;
62 const production = live.find((app) => app.kind === "production");
63 const previews = live.filter((app) => app.kind === "preview");
64
65 return (
66 <div className="mx-auto max-w-5xl">
67 <header className="flex flex-wrap items-start justify-between gap-4">
68 <div>
69 <h1 className="flex items-center gap-2 text-xl font-semibold tracking-tight">
70 <Rocket size={18} className="text-accent" />
71 Deployments
72 </h1>
73 <p className="mt-1 max-w-2xl text-sm text-muted">
74 Every pull request gets a live preview on g1t.page, and the default branch goes to production on each push.
75 Apps run on Cloudflare only while someone visits them.{" "}
76 <a href="https://docs.g1t.sh/guides/deployments/" className="text-fg hover:underline">
77 How it works
78 </a>
79 </p>
80 </div>
81 {settings.enabled && (
82 <a
Agents and memory, checks and conflicts, profiles, slug renames, custom domains83 href={settings.primaryDomain ? `https://${settings.primaryDomain}` : settings.productionUrl}
Deployments: a preview for every pull request, production on g1t.page84 className="inline-flex items-center gap-1.5 rounded-md border border-line px-3 py-1.5 font-mono text-xs text-muted hover:border-line-strong hover:text-fg"
85 >
86 <Globe size={13} />
Agents and memory, checks and conflicts, profiles, slug renames, custom domains87 {settings.primaryDomain ?? host(settings.productionUrl)}
Deployments: a preview for every pull request, production on g1t.page88 </a>
89 )}
90 </header>
91
92 <div className="mt-4 min-h-6">
93 {actionData && "notice" in actionData && <p className="text-sm text-accent">{actionData.notice}</p>}
94 <ErrorText>{actionData && "error" in actionData ? actionData.error : null}</ErrorText>
95 </div>
96
97 {!plan?.on ? (
98 <PlanNeeded plan={plan} owner={params.owner} />
99 ) : !settings.enabled ? (
100 <section className="mt-2 rounded-xl border border-accent/30 bg-accent/5 p-6">
101 <h2 className="font-medium">Deploy {params.repo}</h2>
102 <p className="mt-1 max-w-2xl text-sm text-muted">
Projects: what a workspace builds and runs, first on every page103 Production goes up from <span className="font-mono text-fg">{host(settings.productionUrl)}</span>{" "}
Deployments: a preview for every pull request, production on g1t.page104 as soon as you turn this on, and every open pull request gets its own preview. Workers projects (a{" "}
105 <code className="font-mono text-fg">wrangler.jsonc</code>) and static sites deploy without configuration.
106 </p>
107 <Form method="post" className="mt-4">
108 <Button variant="accent" type="submit" name="intent" value="enable" disabled={busy}>
109 <Rocket size={14} />
110 Turn on deployments
111 </Button>
112 </Form>
113 </section>
114 ) : (
115 <>
116 <section className="mt-2 grid gap-4 md:grid-cols-2">
117 <LiveCard
118 title="Production"
119 hint="The default branch, on every push."
120 app={production}
121 off={!settings.production}
122 actions={
Projects: what a workspace builds and runs, first on every page123 <AppActions branch={null} up={!!production} busy={busy} />
Deployments: a preview for every pull request, production on g1t.page124 }
125 />
126 <div className="rounded-xl border border-line bg-surface p-5">
127 <h2 className="text-sm font-medium">Previews</h2>
128 <p className="mt-0.5 text-xs text-faint">
129 {settings.previews
Projects: what a workspace builds and runs, first on every page130 ? `One per branch with an open pull request; down when it closes or after ${settings.idleDays} days without a visit.`
Deployments: a preview for every pull request, production on g1t.page131 : "Off for this repository."}
132 </p>
133 {previews.length === 0 ? (
134 <p className="mt-4 text-sm text-muted">No previews are up.</p>
135 ) : (
136 <ul className="mt-3 divide-y divide-line">
137 {previews.map((app) => (
138 <li key={app.url} className="flex items-center gap-3 py-2 text-sm">
Projects: what a workspace builds and runs, first on every page139 <span className="shrink-0">
140 <span className="font-medium">{app.branch}</span>
141 {app.number != null && (
142 <Link to={`${base}/pull/${app.number}`} className="ml-1.5 text-xs text-muted hover:underline">
143 #{app.number}
144 </Link>
145 )}
146 </span>
Deployments: a preview for every pull request, production on g1t.page147 <a href={app.url} className="min-w-0 truncate font-mono text-xs text-muted hover:text-fg">
Projects: what a workspace builds and runs, first on every page148 {host(app.url)}
Deployments: a preview for every pull request, production on g1t.page149 </a>
150 <span className="ml-auto shrink-0">
Projects: what a workspace builds and runs, first on every page151 <AppActions branch={app.branch} up busy={busy} compact />
Deployments: a preview for every pull request, production on g1t.page152 </span>
153 </li>
154 ))}
155 </ul>
156 )}
157 </div>
158 </section>
159
160 <h2 className="mt-10 text-sm font-medium text-muted">Recent builds</h2>
161 <div className="mt-3">
162 {builds.length === 0 ? (
163 <EmptyState title="No builds yet">Push to the default branch or open a pull request.</EmptyState>
164 ) : (
165 <ul className="divide-y divide-line overflow-hidden rounded-xl border border-line">
166 {builds.map((build) => (
167 <BuildRow key={build.id} build={build} base={base} />
168 ))}
169 </ul>
170 )}
171 </div>
172
Secrets and variables: one list, rows per environment, for workflows and deployments173 <p className="mt-10 text-sm text-muted">
174 Build command, output directory, idle days, and turning deployments off are under{" "}
175 <Link to={`${base}/settings/deployments`} className="text-fg hover:underline">
176 Settings → Deployments
177 </Link>
178 . Secrets and config for builds and running apps are under{" "}
179 <Link to={`${base}/settings/secrets`} className="text-fg hover:underline">
180 Settings → Secrets and variables
181 </Link>
Agents and memory, checks and conflicts, profiles, slug renames, custom domains182 , and production's own domains under{" "}
183 <Link to={`${base}/settings/domains`} className="text-fg hover:underline">
184 Settings → Domains
185 </Link>
Secrets and variables: one list, rows per environment, for workflows and deployments186 .
187 </p>
Deployments: a preview for every pull request, production on g1t.page188 </>
189 )}
190 </div>
191 );
192}
193
194function PlanNeeded({ plan, owner }: { plan: FeatureState | null; owner: string }) {
195 return (
196 <section className="mt-2 rounded-xl border border-accent/30 bg-accent/5 p-6">
197 <h2 className="font-medium">Deployments are part of a paid plan</h2>
198 <p className="mt-1 max-w-2xl text-sm text-muted">
Projects: what a workspace builds and runs, first on every page199 Turn on Deployments for the {owner} workspace and every project in it can have a preview for each pull
Deployments: a preview for every pull request, production on g1t.page200 request and production on g1t.page.
201 {plan && ` $${(plan.plan.monthlyCents / 100).toFixed(0)} a month, including:`}
202 </p>
203 {plan && (
204 <ul className="mt-3 grid gap-1.5 text-sm text-muted sm:grid-cols-2">
205 {plan.plan.includes.map((line) => (
206 <li key={line} className="flex gap-2">
207 <span className="text-accent">✓</span>
208 {line}
209 </li>
210 ))}
211 </ul>
212 )}
213 {plan && <p className="mt-3 text-xs text-faint">{plan.plan.overage}</p>}
214 <div className="mt-4">
215 <ButtonLink variant="accent" to={`/${owner}/-/billing`}>
216 See the plan under Billing
217 </ButtonLink>
218 </div>
219 </section>
220 );
221}
222
223function LiveCard({
224 title,
225 hint,
226 app,
227 off,
228 actions,
229}: {
230 title: string;
231 hint: string;
232 app: { url: string; commit: string; deployedAt: string } | undefined;
233 off: boolean;
234 actions: ReactNode;
235}) {
236 return (
237 <div className="rounded-xl border border-line bg-surface p-5">
238 <h2 className="text-sm font-medium">{title}</h2>
239 <p className="mt-0.5 text-xs text-faint">{off ? "Off for this repository." : hint}</p>
240 {app ? (
241 <>
242 <a href={app.url} className="mt-3 flex items-center gap-1.5 font-mono text-sm text-accent hover:underline">
Projects: what a workspace builds and runs, first on every page243 {host(app.url)}
Deployments: a preview for every pull request, production on g1t.page244 <ExternalLink size={12} />
245 </a>
246 <p className="mt-1 text-xs text-faint">
247 <span className="font-mono">{app.commit.slice(0, 8)}</span> · deployed <TimeAgo at={app.deployedAt} />
248 </p>
249 </>
250 ) : (
251 <p className="mt-4 text-sm text-muted">Not up.</p>
252 )}
253 {!off && <div className="mt-4">{actions}</div>}
254 </div>
255 );
256}
257
Projects: what a workspace builds and runs, first on every page258function AppActions({ branch, up, busy, compact }: { branch: string | null; up: boolean; busy: boolean; compact?: boolean }) {
Deployments: a preview for every pull request, production on g1t.page259 return (
260 <Form method="post" className="flex items-center gap-2">
Projects: what a workspace builds and runs, first on every page261 {branch != null && <input type="hidden" name="branch" value={branch} />}
Deployments: a preview for every pull request, production on g1t.page262 <Button variant="quiet" type="submit" name="intent" value="redeploy" disabled={busy} title="Build again from the current head">
263 <RotateCw size={13} />
264 {!compact && "Redeploy"}
265 </Button>
266 {up && (
267 <Button variant="quiet" type="submit" name="intent" value="take-down" disabled={busy} title="Take it down now">
268 <Trash2 size={13} />
269 {!compact && "Take down"}
270 </Button>
271 )}
272 </Form>
273 );
274}
275
276function BuildRow({ build, base }: { build: Deployment; base: string }) {
277 return (
278 <li>
279 <Link to={`${base}/deployments/${build.id}`} className="flex items-center gap-4 px-4 py-3 text-sm hover:bg-surface">
280 <span className="w-20 shrink-0">
281 <StatusDot status={build.status} />
282 </span>
283 <span className="min-w-0 grow">
284 <span className="block truncate font-medium">
Projects: what a workspace builds and runs, first on every page285 {build.kind === "production" ? "Production" : `Preview of ${build.branch}`}
Deployments: a preview for every pull request, production on g1t.page286 <span className="ml-2 font-mono text-xs font-normal text-faint">{build.commit.slice(0, 8)}</span>
287 </span>
288 {build.error && <span className="mt-0.5 block truncate text-xs text-muted">{build.error}</span>}
289 </span>
290 <span className="shrink-0 text-xs text-faint">
291 {build.buildSeconds != null && `${build.buildSeconds} s · `}
292 <TimeAgo at={build.createdAt} />
293 </span>
294 </Link>
295 </li>
296 );
297}