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.

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