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.
| Fast pages, required checks on the branch, self-hosted runners, honest incidents | 1 | import type { Route } from "./+types/runners"; |
| 2 | import { page } from "../../lib/meta"; | |
| 3 | import { RunnersPanel } from "../../components/runners"; | |
| 4 | import { actOnRunners, loadRunners } from "../../lib/runners.server"; | |
| 5 | import { repos } from "../../lib/services.server"; | |
| 6 | import { assertSameOrigin, getViewer, requireUser, roleIn } from "../../lib/session.server"; | |
| 7 | ||
| 8 | export function meta({ params, ...args }: Route.MetaArgs) { | |
| 9 | return page(args, { title: `Runners · ${params.owner} · g1t` }); | |
| 10 | } | |
| 11 | ||
| 12 | export async function loader({ params, context, request }: Route.LoaderArgs) { | |
| 13 | const role = roleIn(getViewer(context), params.owner); | |
| 14 | if (!role) throw new Response(null, { status: 404 }); | |
| 15 | const user = requireUser(context, request); | |
| 16 | const workspace = params.owner.toLowerCase(); | |
| 17 | // Members see the runners; owners add, remove and group them. | |
| 18 | const names = role === "owner" ? (await repos.list(user, { namespace: workspace })).map((repo) => repo.name) : []; | |
| 19 | return { role, ...(await loadRunners({ workspace }, user, names)) }; | |
| 20 | } | |
| 21 | ||
| 22 | export async function action({ request, params, context }: Route.ActionArgs) { | |
| 23 | assertSameOrigin(request); | |
| 24 | const user = requireUser(context, request); | |
| 25 | return actOnRunners({ workspace: params.owner.toLowerCase() }, user, await request.formData()); | |
| 26 | } | |
| 27 | ||
| 28 | export default function WorkspaceRunners({ loaderData, actionData }: Route.ComponentProps) { | |
| 29 | const { role, ...data } = loaderData; | |
| 30 | return <RunnersPanel data={data} action={actionData} scope="workspace" manage={role === "owner"} />; | |
| 31 | } |