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.

89 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";
16import { isFailed, part } from "../../lib/partial";
17import { Unavailable } from "../../components/boundary";
18
19export function meta({ params, ...args }: Route.MetaArgs) {
20 return page(args, { title: `Code · ${params.owner}/${params.repo} · g1t` });
21}
22
23export async function loader({ params, context }: Route.LoaderArgs) {
24 const path = { namespace: params.owner, name: params.repo };
25 const viewer = getViewer(context);
26 const [tree, branches, environments, fork] = await Promise.all([
27 repos.tree(path, viewer, null, ""),
28 // For the branch menu; the page still shows without it, and the menu
29 // says when it could not be loaded.
30 part(repos.branches(path, viewer), "Branches"),
31 // For the About sidebar's Deployments panel; null without any.
32 part(environmentsFor(path, viewer), "Deployments"),
33 // A fork's parent, for the bar above its files.
34 part(forkSourceFor(context, params, viewer), "Where this fork came from"),
35 ]);
36 // Each entry's last commit walks history: streamed in after the list.
37 const lastCommits = lastCommitsFor(path, viewer, null, "");
38 const found = unwrap(tree);
39 // The latest commit's author, as their account where there is one.
40 const value = { ...found, head: await showOneCommit(found.head) };
41 // The About beside the files, streamed in after them.
42 const about = value.head ? aboutFor(path, viewer, value.repo.id) : null;
43 // The latest commit's checks: streamed in beside it.
44 const checks = commitChecksFor(path, viewer, [value.head?.hash]);
45 return {
46 tree: value,
47 branches: isFailed(branches) ? branches : branches.ok ? branches.value : null,
48 lastCommits,
49 about,
50 deployments: environments,
51 checks,
52 fork,
53 };
54}
55
56export default function Code({ loaderData }: Route.ComponentProps) {
57 const project = useProject();
58 // The files and latest commit follow pushes to the branch; the latest
59 // commit's checks update as they report.
60 const { tree, fork } = loaderData;
61 // Without the branch list, the page follows its branch as if it were one.
62 const branches = isFailed(loaderData.branches) ? null : loaderData.branches;
63 useRepoLive({ match: repoPages.files({ branch: tree.ref, branches: branches?.map((branch) => branch.name), sha: tree.head?.hash }) });
64 return (
65 <TreeView
66 tree={loaderData.tree}
67 branches={loaderData.branches}
68 lastCommits={loaderData.lastCommits}
69 checks={loaderData.checks}
70 about={loaderData.about}
71 canPush={Boolean(project?.access.can.push)}
72 deployments={loaderData.deployments}
73 fork={
74 isFailed(fork) ? (
75 <div className="mb-4">
76 <Unavailable compact what={fork.what} />
77 </div>
78 ) : fork && project && branches?.some((branch) => branch.name === tree.ref) ? (
79 <ForkBar
80 base={`/${tree.repo.namespace}/${tree.repo.name}`}
81 branch={tree.ref}
82 parent={fork}
83 canPush={Boolean(project.access.can.push)}
84 />
85 ) : null
86 }
87 />
88 );
89}