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/settings-deployments.tsx

129 lines6,075 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.

Secrets and variables: one list, rows per environment, for workflows and deployments1import { Form, Link, data, useNavigation } from "react-router";
2
3import type { Route } from "./+types/settings-deployments";
Social cards for every page: og.g1t.sh4import { page } from "../../lib/meta";
Secrets and variables: one list, rows per environment, for workflows and deployments5import { RepoSettingsTabs } from "../../components/repo-settings-tabs";
6import { Button, ErrorText, Field, Input } from "../../components/ui";
Workspace names and icons, and a component kit for every control7import { SwitchCard } from "../../components/ui/switch";
Secrets and variables: one list, rows per environment, for workflows and deployments8import { deployments } from "../../lib/services.server";
9import { assertSameOrigin, getViewer, requireUser, roleIn, unwrap } from "../../lib/session.server";
10
Social cards for every page: og.g1t.sh11export function meta({ params, ...args }: Route.MetaArgs) {
12 return page(args, { title: `Deployment settings · ${params.owner}/${params.repo} · g1t` });
Secrets and variables: one list, rows per environment, for workflows and deployments13}
14
15export async function loader({ params, context }: Route.LoaderArgs) {
16 const viewer = getViewer(context);
17 if (!roleIn(viewer, params.owner)) throw data(null, { status: 404 });
Projects: what a workspace builds and runs, first on every page18 const settings = await deployments.settings({ workspace: params.owner, slug: params.repo }, viewer);
Secrets and variables: one list, rows per environment, for workflows and deployments19 return { settings: unwrap(settings) };
20}
21
22export async function action({ request, params, context }: Route.ActionArgs) {
23 assertSameOrigin(request);
24 const user = requireUser(context, request);
25 const form = await request.formData();
Projects: what a workspace builds and runs, first on every page26 const ref = { workspace: params.owner, slug: params.repo };
Secrets and variables: one list, rows per environment, for workflows and deployments27 const intent = form.get("intent");
28 if (intent === "enable" || intent === "disable") {
Projects: what a workspace builds and runs, first on every page29 const saved = await deployments.updateSettings(user, ref, { enabled: intent === "enable" });
Secrets and variables: one list, rows per environment, for workflows and deployments30 return saved.ok
31 ? { notice: intent === "enable" ? "Deployments are on. Production is building." : "Deployments are off, and every app is down." }
32 : { error: saved.error.message };
33 }
34 const on = (name: string) => form.get(name) === "on";
Projects: what a workspace builds and runs, first on every page35 const saved = await deployments.updateSettings(user, ref, {
Secrets and variables: one list, rows per environment, for workflows and deployments36 previews: on("previews"),
37 production: on("production"),
38 buildCommand: String(form.get("buildCommand") ?? ""),
39 outputDir: String(form.get("outputDir") ?? ""),
40 idleDays: Number(form.get("idleDays")),
41 });
42 return saved.ok ? { notice: "Saved." } : { error: saved.error.message };
43}
44
45function Check({ name, on, title, children }: { name: string; on: boolean; title: string; children: string }) {
46 return (
Workspace names and icons, and a component kit for every control47 <SwitchCard name={name} defaultChecked={on} title={title}>
48 {children}
49 </SwitchCard>
Secrets and variables: one list, rows per environment, for workflows and deployments50 );
51}
52
53export default function DeploymentSettings({ loaderData, actionData, params }: Route.ComponentProps) {
54 const { settings } = loaderData;
55 const busy = useNavigation().state === "submitting";
56 const base = `/${params.owner}/${params.repo}`;
57 return (
58 <div className="max-w-4xl">
59 <RepoSettingsTabs base={base} />
60 <div className="min-h-6">
61 {actionData && "notice" in actionData && <p className="text-sm text-accent">{actionData.notice}</p>}
62 <ErrorText>{actionData && "error" in actionData ? actionData.error : null}</ErrorText>
63 </div>
64
65 {!settings.enabled ? (
66 <section className="rounded-xl border border-line bg-surface p-5">
67 <h2 className="font-medium">Deployments are off</h2>
68 <p className="mt-1 text-sm text-muted">
69 Turn them on to build production at{" "}
70 <span className="font-mono text-fg">{settings.productionUrl.replace("https://", "")}</span> and a preview for
71 every pull request. The workspace needs the Deployments plan, under Billing.
72 </p>
73 <Form method="post" className="mt-4">
74 <Button variant="accent" type="submit" name="intent" value="enable" disabled={busy}>
75 Turn on deployments
76 </Button>
77 </Form>
78 </section>
79 ) : (
80 <>
81 <Form method="post" className="space-y-5">
82 <div className="grid gap-3 md:grid-cols-2">
83 <Check name="production" on={settings.production} title="Production">
84 Deploy the default branch on every push.
85 </Check>
86 <Check name="previews" on={settings.previews} title="Previews">
Projects: what a workspace builds and runs, first on every page87 A preview for every branch with an open pull request, linked on it.
Secrets and variables: one list, rows per environment, for workflows and deployments88 </Check>
89 </div>
90 <div className="grid gap-4 md:grid-cols-3">
91 <Field label="Build command" hint="Instead of the project's own build script.">
92 <Input name="buildCommand" defaultValue={settings.buildCommand ?? ""} placeholder="npm run build" />
93 </Field>
94 <Field label="Output directory" hint="For a static site; found by itself when empty.">
95 <Input name="outputDir" defaultValue={settings.outputDir ?? ""} placeholder="dist" />
96 </Field>
97 <Field label="Idle days" hint="A preview no one visits for this long comes down.">
98 <Input name="idleDays" type="number" min={1} max={90} defaultValue={settings.idleDays} />
99 </Field>
100 </div>
101 <p className="text-sm text-muted">
102 Builds and running apps read the{" "}
103 <Link to={`${base}/settings/secrets`} className="text-fg hover:underline">
104 secrets and variables
105 </Link>{" "}
106 available to Deployments: each row for Production or Preview, or for all environments.
107 </p>
108 <Button type="submit" disabled={busy}>
109 Save
110 </Button>
111 </Form>
112
113 <section className="mt-10 rounded-xl border border-danger/30 p-5">
114 <h2 className="text-sm font-medium">Turn off deployments</h2>
115 <p className="mt-1 text-sm text-muted">
Projects: what a workspace builds and runs, first on every page116 Takes production and every preview down now, and stops building. Nothing of this project's keeps
Secrets and variables: one list, rows per environment, for workflows and deployments117 running or costing anything. The workspace's plan stays on; turn it off under Billing.
118 </p>
119 <Form method="post" className="mt-3">
120 <Button variant="quiet" type="submit" name="intent" value="disable" disabled={busy}>
121 Turn off deployments
122 </Button>
123 </Form>
124 </section>
125 </>
126 )}
127 </div>
128 );
129}