Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

30 linesCodeBlameRaw
1/**
2 * Bringing a fork's branch up to date with its parent's, from the fork bar
3 * on its Code page (components/fork-bar.tsx). Write access on the fork.
4 */
5import { data } from "react-router";
6
7import type { SyncedFork } from "@g1t/contracts";
8
9import type { Route } from "./+types/sync-fork";
10import { repos } from "../../lib/services.server";
11import { assertSameOrigin, requireUser } from "../../lib/session.server";
12
13export type SyncOutcome = { error: string | null; synced: SyncedFork | null };
14
15export async function action({ request, params, context }: Route.ActionArgs) {
16 assertSameOrigin(request);
17 const user = requireUser(context, request);
18 const form = await request.formData();
19 const branch = String(form.get("branch") ?? "").trim() || undefined;
20 try {
21 const synced = await repos.syncFork(user, { namespace: params.owner, name: params.repo }, branch);
22 if (!synced.ok) {
23 const status = synced.error.code === "not_found" ? 404 : synced.error.code === "forbidden" ? 403 : 409;
24 return data<SyncOutcome>({ error: synced.error.message, synced: null }, { status });
25 }
26 return { error: null, synced: synced.value } satisfies SyncOutcome;
27 } catch {
28 return data<SyncOutcome>({ error: "That did not go through. Try again in a moment.", synced: null }, { status: 503 });
29 }
30}