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.

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