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.

34 linesCodeBlameRaw
1/**
2 * `/<workspace>/-/work/ref/<number>`: `#12` read in the workspace alone
3 * (lib/refs.ts): its work item, else its pull request. Asked for JSON, it
4 * is the card over a `#12` on a work item's timeline
5 * (components/commit-message.tsx), for anyone who may see it; followed as
6 * a link, it sends the browser on. Kept a minute by the browser, and out
7 * of indexes.
8 */
9import { data, redirect } from "react-router";
10
11import type { Route } from "./+types/ref";
12import { refCard, refPath } from "../../../lib/refs.server";
13import { getViewer } from "../../../lib/session.server";
14
15const HEADERS = {
16 "cache-control": "private, max-age=60",
17 vary: "Cookie, Accept",
18 "x-robots-tag": "noindex, nofollow",
19};
20
21export async function loader({ params, context, request }: Route.LoaderArgs) {
22 const viewer = getViewer(context);
23 const scope = { workspace: params.owner.toLowerCase() };
24 const number = Number(params.number);
25 const card = (request.headers.get("accept") ?? "").startsWith("application/json");
26 if (card) {
27 const found = await refCard(viewer, scope, number);
28 if (!found) return Response.json({ error: "not_found" }, { status: 404, headers: HEADERS });
29 return Response.json(found, { headers: HEADERS });
30 }
31 const to = await refPath(viewer, scope, number);
32 if (!to) throw data(null, { status: 404 });
33 return redirect(to);
34}