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.

62 linesCodeBlameRaw
1import type { Route } from "./+types/tree";
2import { page } from "../../lib/meta";
3import { TreeView } from "../../components/repo-view";
4import { redirectIfBranchRenamed } from "../../lib/branch-redirect.server";
5import { commitChecksFor } from "../../lib/commit-checks.server";
6import { aboutFor } from "../../lib/about.server";
7import { environmentsFor } from "../../lib/deployments.server";
8import { lastCommitsFor } from "../../lib/last-commits.server";
9import { showOneCommit } from "../../lib/commit-people.server";
10import { repos } from "../../lib/services.server";
11import { getViewer, unwrap } from "../../lib/session.server";
12import { projectHomepage } from "../../lib/about";
13import { useProject } from "./layout";
14import { repoPages } from "../../lib/repo-live";
15import { useRepoLive } from "../../lib/use-repo-live";
16
17export function meta({ params, ...args }: Route.MetaArgs) {
18 const path = params["*"] ? `${params["*"]} · ` : "";
19 return page(args, { title: `${path}${params.owner}/${params.repo} · g1t` });
20}
21
22export async function loader({ params, context, request }: Route.LoaderArgs) {
23 const path = { namespace: params.owner, name: params.repo };
24 const viewer = getViewer(context);
25 const [tree, branches, environments] = await Promise.all([
26 repos.tree(path, viewer, params.ref, params["*"] ?? ""),
27 // For the branch menu; the page still shows without it.
28 repos.branches(path, viewer).catch(() => null),
29 // For the About sidebar's Deployments panel, shown at the root only.
30 params["*"] ? null : environmentsFor(path, viewer),
31 ]);
32 // A branch that was renamed: the same folder on its new name.
33 if (!tree.ok && tree.error.code === "not_found") await redirectIfBranchRenamed(request, path, viewer, params.ref);
34 // Each entry's last commit walks history: streamed in after the list.
35 const lastCommits = lastCommitsFor(path, viewer, params.ref, params["*"] ?? "");
36 const found = unwrap(tree);
37 // The latest commit's author, as their account where there is one.
38 const value = { ...found, head: await showOneCommit(found.head) };
39 // The About beside the files, streamed in after them.
40 const about = value.head && !value.path ? aboutFor(path, viewer, value.repo.id) : null;
41 // The latest commit's checks: streamed in beside it.
42 const checks = commitChecksFor(path, viewer, [value.head?.hash]);
43 return { tree: value, branches: branches?.ok ? branches.value : null, lastCommits, about, deployments: environments, checks };
44}
45
46export default function Tree({ loaderData }: Route.ComponentProps) {
47 const project = useProject();
48 // The files and latest commit follow pushes; checks update as they report.
49 useRepoLive({ match: repoPages.files() });
50 return (
51 <TreeView
52 tree={loaderData.tree}
53 branches={loaderData.branches}
54 lastCommits={loaderData.lastCommits}
55 checks={loaderData.checks}
56 about={loaderData.about}
57 canPush={Boolean(project?.access.can.push)}
58 homepage={projectHomepage(project?.project ?? null)}
59 deployments={loaderData.deployments}
60 />
61 );
62}