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.
| GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs | 1 | import type { Route } from "./+types/secrets"; |
| 2 | import { SecretsPanel } from "../../components/secrets"; | |
| 3 | import { actOnSecrets, loadSecrets } from "../../lib/secrets.server"; | |
| 4 | import { assertSameOrigin, getViewer, requireUser, roleIn } from "../../lib/session.server"; | |
| 5 | ||
| 6 | export function meta({ params }: Route.MetaArgs) { | |
| 7 | return [{ title: `Secrets and variables · ${params.owner} · g1t` }]; | |
| 8 | } | |
| 9 | ||
| 10 | export async function loader({ params, context, request }: Route.LoaderArgs) { | |
| 11 | const role = roleIn(getViewer(context), params.owner); | |
| 12 | if (!role) throw new Response(null, { status: 404 }); | |
| 13 | return { role, ...(await loadSecrets({ workspace: params.owner.toLowerCase() }, requireUser(context, request))) }; | |
| 14 | } | |
| 15 | ||
| 16 | export async function action({ request, params, context }: Route.ActionArgs) { | |
| 17 | assertSameOrigin(request); | |
| 18 | const user = requireUser(context, request); | |
| 19 | return actOnSecrets({ workspace: params.owner.toLowerCase() }, user, await request.formData()); | |
| 20 | } | |
| 21 | ||
| 22 | export default function WorkspaceSecrets({ loaderData, actionData }: Route.ComponentProps) { | |
| 23 | const { role, ...data } = loaderData; | |
| 24 | // Every repository reads a workspace's, so only its owners change them. | |
| 25 | return <SecretsPanel data={data} action={actionData} scope="workspace" manage={role === "owner"} />; | |
| 26 | } |