g1t/apps/web/app/routes/repo/add-ci.ts

25 lines1,076 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 incidents1/**
2 * Adds a starter CI workflow to a repository that has no checks, as a pull
3 * request opened by whoever asked, and goes to it. Posted by the "Add CI"
4 * prompt (components/add-ci.tsx). Anyone who can push may.
5 */
6import { redirect } from "react-router";
7
8import type { Route } from "./+types/add-ci";
9import { addCi } from "../../lib/add-ci.server";
10import { refusal } from "../../lib/access.server";
11import { assertSameOrigin, requireUser } from "../../lib/session.server";
12
13export async function action({ request, params, context }: Route.ActionArgs) {
14 assertSameOrigin(request);
15 const user = requireUser(context, request);
16 const refused = await refusal(context, params, "push");
17 if (refused) return { error: refused };
18 const added = await addCi(user, { namespace: params.owner, name: params.repo });
19 if (!added.ok) return { error: added.message };
20 throw redirect(`/${params.owner}/${params.repo}/pull/${added.value.number}`);
21}
22
23export async function loader({ params }: Route.LoaderArgs) {
24 throw redirect(`/${params.owner}/${params.repo}/actions`);
25}