import { MAX_DESCRIPTION_LENGTH, type CiEnvironment } from "@refs/backend/contract"; import { Banner, Button, Checkbox, Dialog, Empty, Input, InputArea, LayerCard, Tabs } from "@refs/design-system"; import { ShieldCheckIcon, TrashIcon } from "@refs/design-system/icons"; import { useState } from "react"; import { Form, data, redirect, useNavigation } from "react-router"; import type { Route } from "./+types/repo-settings"; import { VisibilityField } from "../components/repo-form"; import { SecretTable } from "../components/secret-table"; import { failed, formText, found, refs, fullName } from "../lib/session"; async function settingsFor(context: Route.LoaderArgs["context"], name: string) { const repo = await found(refs(context).repo(name)); return { name: repo.summary.name, settings: await found(repo.settings()) }; } export const meta: Route.MetaFunction = ({ params }) => [{ title: `Settings · ${fullName(params)} · refs` }]; export async function loader({ params, context }: Route.LoaderArgs) { const { name, settings } = await settingsFor(context, fullName(params)); const [secrets, environments, protectedBranches] = await Promise.all([settings.ci.secrets(), settings.ci.environments(), settings.ci.protectedBranches()]); return { name, description: settings.description, visibility: settings.visibility, secrets, environments, protectedBranches }; } function lines(text: string): string[] { return text.split(/[\n,]/).map((line) => line.trim()).filter(Boolean); } export async function action({ request, params, context }: Route.ActionArgs) { const { settings } = await settingsFor(context, fullName(params)); const { ci } = settings; const form = await request.formData(); const intent = formText(form, "intent"); if (intent === "delete") { const outcome = await settings.delete(formText(form, "confirm")); if (!outcome.ok) return failed(outcome.problem, { intent, saved: false }); throw redirect("/"); } const environment = formText(form, "environment") || null; const outcome = intent === "update" ? await settings.update({ description: formText(form, "description"), visibility: formText(form, "visibility") === "public" ? "public" : "private" }) : intent === "secret-set" ? await ci.setSecret({ name: formText(form, "name"), value: String(form.get("value") ?? ""), environment }) : intent === "secret-delete" ? await ci.deleteSecret(formText(form, "name"), environment) : intent === "environment-save" ? await ci.saveEnvironment({ name: formText(form, "name"), requiresApproval: form.get("approval") === "on", waitSeconds: Math.round(Number(formText(form, "wait") || 0) * 60), branches: lines(formText(form, "branches")) }) : intent === "environment-delete" ? await ci.deleteEnvironment(formText(form, "name")) : intent === "protected-save" ? await ci.setProtectedBranches(lines(formText(form, "patterns"))) : null; if (!outcome) return data({ intent, error: "Unknown action.", saved: false }, { status: 400 }); return outcome.ok ? { intent, error: undefined, saved: true } : failed(outcome.problem, { intent, saved: false }); } function EnvironmentForm({ environment }: { environment: CiEnvironment | null }) { const navigation = useNavigation(); const saving = navigation.state === "submitting" && navigation.formData?.get("intent") === "environment-save" && (environment === null || navigation.formData.get("name") === environment.name); const [name, setName] = useState(environment?.name ?? ""); return (
); } function DeleteRepository({ name, error }: { name: string; error?: string }) { const [open, setOpen] = useState(Boolean(error)); const [confirm, setConfirm] = useState(""); const submitting = useNavigation().state === "submitting"; return (A push by a person to one of these branches gets every secret, environment secrets too. Use * for one path segment and ** for many.
A job gets a secret only when it names it under secrets in .refs/ci.yml. An environment secret wins over a repository secret, and a repository secret wins over an organization secret.
A job that names an environment runs only when its rules allow it. Its environment secrets need a person's approval or a push by a person to a protected branch.
{environments.map((environment) => (