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.

58 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 { repoPages } from "../../lib/repo-live";
13import { useRepoLive } from "../../lib/use-repo-live";
14
15export function meta({ params, ...args }: Route.MetaArgs) {
16 return page(args, { title: `Code · ${params.owner}/${params.repo} · g1t` });
17}
18
19export async function loader({ params, context }: Route.LoaderArgs) {
20 const path = { namespace: params.owner, name: params.repo };
21 const viewer = getViewer(context);
22 const [tree, branches, environments] = await Promise.all([
23 repos.tree(path, viewer, null, ""),
24 // For the branch menu; the page still shows without it.
25 repos.branches(path, viewer).catch(() => null),
26 // For the About sidebar's Deployments panel; null without any.
27 environmentsFor(path, viewer),
28 ]);
29 // Each entry's last commit walks history: streamed in after the list.
30 const lastCommits = lastCommitsFor(path, viewer, null, "");
31 const found = unwrap(tree);
32 // The latest commit's author, as their account where there is one.
33 const value = { ...found, head: await showOneCommit(found.head) };
34 // The About beside the files, streamed in after them.
35 const about = value.head ? aboutFor(path, viewer, value.repo.id) : null;
36 // The latest commit's checks: streamed in beside it.
37 const checks = commitChecksFor(path, viewer, [value.head?.hash]);
38 return { tree: value, branches: branches?.ok ? branches.value : null, lastCommits, about, deployments: environments, checks };
39}
40
41export default function Code({ loaderData }: Route.ComponentProps) {
42 const project = useProject();
43 // The files and latest commit follow pushes to the branch; the latest
44 // commit's checks update as they report.
45 const { tree, branches } = loaderData;
46 useRepoLive({ match: repoPages.files({ branch: tree.ref, branches: branches?.map((branch) => branch.name), sha: tree.head?.hash }) });
47 return (
48 <TreeView
49 tree={loaderData.tree}
50 branches={loaderData.branches}
51 lastCommits={loaderData.lastCommits}
52 checks={loaderData.checks}
53 about={loaderData.about}
54 canPush={Boolean(project?.access.can.push)}
55 deployments={loaderData.deployments}
56 />
57 );
58}