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
139 linesCodeBlameRaw
1/**
2 * A project's pages and the tabs within them, in one place: the sidebar
3 * lists the pages, and a page with more than one view shows them as tabs
4 * across its top, the way GitHub and Vercel do. Soon tabs come from the
5 * roadmap and open its page for them, under the same tabs.
6 */
7import type { Abilities, Capability } from "@g1t/contracts";
8
9import { type RoadmapItem, roadmapIn } from "./roadmap.ts";
10
11export type Tab = {
12 label: string;
13 /** Under the project, without a leading slash; "" is its overview. */
14 path: string;
15 /** Other paths under which this tab is the current one. */
16 also?: string[];
17 soon?: boolean;
18 about?: string;
19 /** Members only. */
20 members?: boolean;
21 /** Current on its own path only, not on the paths under it. */
22 exact?: boolean;
23 /** Only for viewers whose role has this capability, once it is known. */
24 needs?: Capability;
25};
26
27export type Section = {
28 key: RoadmapItem["section"] | "Workflows" | "Settings";
29 tabs: Tab[];
30};
31
32function soon(section: RoadmapItem["section"]): Tab[] {
33 return roadmapIn(section).map((item) => ({ label: item.title, path: `soon/${item.key}`, soon: true, about: item.summary }));
34}
35
36export const SECTIONS: Section[] = [
37 {
38 key: "Code",
39 tabs: [
40 { label: "Files", path: "code", also: ["tree", "blob"] },
41 { label: "Commits", path: "commits", also: ["commit"] },
42 { label: "Branches", path: "branches" },
43 { label: "Tags", path: "tags" },
44 { label: "Releases", path: "releases" },
45 { label: "Compare", path: "compare" },
46 // No Docs tab: code is not docs. Docs is a workspace mode, filtered by project there.
47 ],
48 },
49 {
50 key: "Issues",
51 tabs: [
52 { label: "Issues", path: "issues" },
53 { label: "Outcomes", path: "plans" },
54 { label: "Milestones", path: "milestones" },
55 ...soon("Issues"),
56 ],
57 },
58 {
59 key: "Agents",
60 tabs: [
61 { label: "At work", path: "agents" },
62 { label: "Sessions", path: "sessions" },
63 { label: "Memory", path: "memory" },
64 ...soon("Agents"),
65 ],
66 },
67 {
68 key: "Deployments",
69 tabs: [{ label: "Deployments", path: "deployments" }, ...soon("Deployments")],
70 },
71 {
72 key: "Observability",
73 tabs: [
74 { label: "Overview", path: "observability", exact: true, members: true },
75 { label: "Requests", path: "observability/requests", members: true },
76 { label: "Logs", path: "observability/logs", members: true },
77 { label: "Traces", path: "observability/traces", members: true },
78 { label: "Errors", path: "observability/errors", members: true },
79 { label: "Metrics", path: "observability/metrics", members: true },
80 { label: "Settings", path: "observability/settings", members: true, needs: "manage_integrations" },
81 ...soon("Observability"),
82 ],
83 },
84 {
85 key: "Security",
86 tabs: [
87 { label: "Overview", path: "security", members: true, needs: "security_alerts", exact: true },
88 { label: "Secret scanning", path: "security/secret-scanning", members: true, needs: "security_alerts" },
89 { label: "Code scanning", path: "security/code-scanning", members: true, needs: "security_alerts", also: ["security/pulls"] },
90 { label: "Vulnerabilities", path: "security/vulnerabilities", members: true, needs: "security_alerts" },
91 { label: "Dependency graph", path: "security/dependency-graph", members: true, needs: "security_alerts" },
92 { label: "Dependency updates", path: "security/dependency-updates", members: true, needs: "security_alerts" },
93 { label: "Advisories", path: "security/advisories", members: true, needs: "security_alerts", also: ["security/reports"] },
94 { label: "Settings", path: "security/settings", members: true, needs: "security_alerts" },
95 ...soon("Security"),
96 ],
97 },
98 {
99 key: "Insights",
100 tabs: [
101 { label: "Contributors", path: "contributors" },
102 { label: "Activity", path: "activity" },
103 { label: "Stargazers", path: "stargazers" },
104 ...soon("Insights"),
105 ],
106 },
107];
108
109/** Pull requests and the merge queue share a page's tabs too. */
110export const PULLS: Section = {
111 key: "Code",
112 tabs: [
113 { label: "Pull requests", path: "pulls", also: ["pull"] },
114 { label: "Merge queue", path: "queue" },
115 ],
116};
117
118function matches(rest: string, tab: Tab): boolean {
119 return [tab.path, ...(tab.also ?? [])].some((path) => path !== "" && (rest === path || rest.startsWith(`${path}/`)));
120}
121
122/**
123 * The tabs for the page at `rest` (the path under the project), if it
124 * belongs to a page with more than one view.
125 */
126export function tabsFor(rest: string, member: boolean, can?: Partial<Abilities>): Tab[] | null {
127 for (const section of [...SECTIONS, PULLS]) {
128 const visible = section.tabs.filter(
129 (tab) => (member || !tab.members) && (!tab.needs || !can || Boolean(can[tab.needs])),
130 );
131 if (visible.length > 1 && visible.some((tab) => matches(rest, tab))) return visible;
132 }
133 return null;
134}
135
136/** The first page of a section, for its sidebar link: a built one if any. */
137export function entryOf(key: Section["key"]): Tab | undefined {
138 return SECTIONS.find((section) => section.key === key)?.tabs[0];
139}