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.

28 linesCodeBlameRaw
1import { LIST_PAGE } from "@g1t/contracts";
2
3import type { Route } from "./+types/plan-later";
4import { originPath } from "../../../lib/plan";
5import { work } from "../../../lib/services.server";
6import { getViewer } from "../../../lib/session.server";
7import { repoFilter } from "../../../lib/work-items";
8
9/**
10 * One of the Plan's Later groups, read when it is opened: the open work
11 * items on Later filed in a repository (`?repo=acme/web`), or in the
12 * workspace itself (`?repo=`), in the plan's order, at most 100.
13 */
14export async function loader({ params, context, request }: Route.LoaderArgs) {
15 const viewer = getViewer(context);
16 const workspace = params.owner.toLowerCase();
17 const repoName = new URL(request.url).searchParams.get("repo")?.trim() ?? "";
18 const repo = repoName ? repoFilter(workspace, repoName) : null;
19 if (repoName && !repo) return { error: "That is not a repository of the workspace." };
20 const found = await work
21 .listWorkItems(workspace, viewer, { horizon: "later", limit: LIST_PAGE, ...(repo ? { repo, role: "origin" as const } : {}) })
22 .catch(() => null);
23 if (!found) return { error: "Later could not be loaded just now." };
24 if (!found.ok) return { error: found.error.message };
25 // Those filed in the workspace have no origin repository.
26 const items = repo ? found.value : found.value.filter((item) => originPath(item) == null);
27 return { items, more: found.value.length >= LIST_PAGE };
28}