g1t/apps/web/app/routes/workspace/runners.tsx

30 lines1,520 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.

Fast pages, required checks on the branch, self-hosted runners, honest incidents1import type { Route } from "./+types/runners";
2import { page } from "../../lib/meta";
3import { RunnersPanel } from "../../components/runners";
4import { actOnRunners, loadRunners } from "../../lib/runners.server";
5import { repos } from "../../lib/services.server";
6import { assertSameOrigin, getViewer, requireUser, roleIn } from "../../lib/session.server";
7
8export function meta({ params, ...args }: Route.MetaArgs) {
9 return page(args, { title: `Runners · ${params.owner} · g1t` });
10}
11
12export async function loader({ params, context, request }: Route.LoaderArgs) {
Runners are owner-only: the page, its actions, the Settings entry and the links to it13 // The workspace's own machines and their tokens: owners only.
14 if (roleIn(getViewer(context), params.owner) !== "owner") throw new Response(null, { status: 404 });
Fast pages, required checks on the branch, self-hosted runners, honest incidents15 const user = requireUser(context, request);
16 const workspace = params.owner.toLowerCase();
Runners are owner-only: the page, its actions, the Settings entry and the links to it17 const names = (await repos.list(user, { namespace: workspace })).map((repo) => repo.name);
18 return loadRunners({ workspace }, user, names);
Fast pages, required checks on the branch, self-hosted runners, honest incidents19}
20
21export async function action({ request, params, context }: Route.ActionArgs) {
22 assertSameOrigin(request);
Runners are owner-only: the page, its actions, the Settings entry and the links to it23 if (roleIn(getViewer(context), params.owner) !== "owner") throw new Response(null, { status: 404 });
Fast pages, required checks on the branch, self-hosted runners, honest incidents24 const user = requireUser(context, request);
25 return actOnRunners({ workspace: params.owner.toLowerCase() }, user, await request.formData());
26}
27
28export default function WorkspaceRunners({ loaderData, actionData }: Route.ComponentProps) {
Runners are owner-only: the page, its actions, the Settings entry and the links to it29 return <RunnersPanel data={loaderData} action={actionData} scope="workspace" manage />;
Fast pages, required checks on the branch, self-hosted runners, honest incidents30}