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.

65 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 to the branch (none for a
49 // tag or a commit); the latest commit's checks update as they report.
50 const { tree, branches } = loaderData;
51 const names = branches?.map((branch) => branch.name);
52 useRepoLive({ match: repoPages.files({ branch: !names || names.includes(tree.ref) ? tree.ref : null, branches: names, sha: tree.head?.hash }) });
53 return (
54 <TreeView
55 tree={loaderData.tree}
56 branches={loaderData.branches}
57 lastCommits={loaderData.lastCommits}
58 checks={loaderData.checks}
59 about={loaderData.about}
60 canPush={Boolean(project?.access.can.push)}
61 homepage={projectHomepage(project?.project ?? null)}
62 deployments={loaderData.deployments}
63 />
64 );
65}