Skip to content

g1t/apps/web/app/routes/repo/branch-names.ts

21 lines868 bytesCodeBlame
1/**
2 * A repository's branch names as JSON, for choosing one without loading
3 * them with the page: a pull request's base, when someone changes it.
4 */
5import { data } from "react-router";
6
7import type { Route } from "./+types/branch-names";
8import { repos } from "../../lib/services.server";
9import { getViewer } from "../../lib/session.server";
10
11export async function loader({ params, context }: Route.LoaderArgs) {
12 const found = await repos.branches({ namespace: params.owner, name: params.repo }, getViewer(context));
13 if (!found.ok) throw data({ error: found.error.message }, { status: 404 });
14 return Response.json(
15 {
16 // The merge queue's own branches are g1t's, never a base.
17 branches: found.value.map((branch) => branch.name).filter((name) => !name.startsWith("g1t-queue/")),
18 },
19 { headers: { "cache-control": "no-store" } },
20 );
21}