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
230 linesCodeBlameRaw
1import type { User, Viewer } from "./identity";
2import type { RepoPath } from "./repos";
3import type { Result } from "./result";
4
5/**
6 * Projects: the thing a workspace builds and runs. A project has exactly
7 * one source, where its code lives; everything about running it
8 * (deployments, environments, domains, secrets and variables) belongs to
9 * the project, while branches, pull requests and review stay with the
10 * repository. One repository may carry several projects, each from its own
11 * root directory. Every repository on g1t gets a project of its own name.
12 */
13
14/** Where a project's code lives: a repository hosted on g1t. */
15export type ProjectSource = { kind: "hosted"; repoId: string; repo: RepoPath; rootDir: string; defaultBranch: string };
16
17export type Project = {
18 id: string;
19 /** The workspace's slug. */
20 workspace: string;
21 /** Unique in its workspace; the project's address is `g1t.sh/<workspace>/<slug>`. */
22 slug: string;
23 name: string;
24 /** The project's own description, or its repository's while it has none. */
25 description: string | null;
26 /** Whether `description` is its repository's, following it as it changes. */
27 descriptionInherited: boolean;
28 source: ProjectSource;
29 /** Whether its repository is private: only people with a role on it can see it. */
30 private: boolean;
31 /** Whether its repository is archived: read-only, kept for reference. */
32 archived: boolean;
33 /** Whether it is the project its repository's workflows read secrets from. */
34 primary: boolean;
35 /** What a person set it to be; each part null while it is left to detection. */
36 setting: ProjectSetting;
37 /** What it is: from `setting`, or for what is left out, from its deployments, packages and files. */
38 kind: ProjectKind;
39 /** Why it is that kind. */
40 kindReason: KindReason;
41 /**
42 * Where it runs: `g1t` when it is hosted on g1t.page (Deployments),
43 * `elsewhere` when it deploys itself (a workflow on g1t Actions, or
44 * another pipeline) to hosting of its own, at `productionUrl`. Null for
45 * what is not deployed (a library, a tool) and for an app nobody has
46 * placed that has neither Deployments on nor deployed production itself.
47 */
48 runs: ProjectRuns | null;
49 /** Where production is when it deploys itself; null when nobody has given one. */
50 productionUrl: string | null;
51 /**
52 * An image of production someone uploaded, shown on its overview when
53 * there is no screenshot, or instead of one when `preferred`. Null when
54 * none was uploaded.
55 */
56 productionImage: ProductionImage | null;
57 /** What detection decides, whatever the setting is, to show beside it. */
58 detected: { kind: ProjectKind; reason: KindReason };
59 /** The ecosystem its files say it publishes to, for how to publish; null when none says. */
60 ecosystem: ProjectEcosystem | null;
61 /** Its homepage, docs and other links, shown wherever the project is. */
62 links: ProjectLinks;
63 createdBy: string;
64 /** RFC 3339. */
65 createdAt: string;
66 updatedAt: string;
67 /** RFC 3339: when its repository was last pushed to; null until it is, after projects began keeping it. */
68 pushedAt: string | null;
69 /**
70 * How active it is lately: each push, issue or pull request opened or
71 * closed, review, comment and deployment counts one, halving every week.
72 * 0 for none.
73 */
74 activity: number;
75};
76
77/**
78 * What a project is. An app (or a site) runs somewhere and gets a
79 * production card; a library is published and installed; a tool, such as
80 * a CLI, ships as releases people install; docs are documentation or site
81 * content; other is anything else, such as configuration or research.
82 */
83export type ProjectKind = "app" | "library" | "tool" | "docs" | "other";
84
85/** Every kind, in the order pages offer them. */
86export const PROJECT_KINDS: readonly ProjectKind[] = ["app", "library", "tool", "docs", "other"];
87
88/** Where an app or a site runs: hosted on g1t.page, or deploying itself to hosting of its own. */
89export type ProjectRuns = "g1t" | "elsewhere";
90
91/** What a person set; null for each part left to detection. */
92export type ProjectSetting = { kind: ProjectKind | null; runs: ProjectRuns | null };
93
94/** One of a project's own links: a label and an http(s) address. */
95export type ProjectLink = { label: string; url: string };
96
97export type ProjectLinks = {
98 /** Its homepage: its own, or its repository's website while it has none. */
99 homepage: string | null;
100 /** Whether `homepage` is its repository's website, following it as it changes. */
101 homepageInherited: boolean;
102 /** Where its documentation is read. */
103 docs: string | null;
104 /** Any others, in the order given, at most `MAX_PROJECT_LINKS`. */
105 custom: ProjectLink[];
106};
107
108/**
109 * An uploaded image of a project's production. `file` is the SHA-256 of
110 * its bytes: it is served from the usercontent origin at
111 * `/production-images/<file>`.
112 */
113export type ProductionImage = { file: string; contentType: string; preferred: boolean };
114
115/** The largest production image taken, in bytes. */
116export const MAX_PRODUCTION_IMAGE_BYTES = 5 * 1024 * 1024;
117
118/** The types a production image may be, read from its bytes. */
119export const PRODUCTION_IMAGE_TYPES: readonly string[] = ["image/png", "image/jpeg", "image/webp"];
120
121/**
122 * A change to a project's production image. `image` is the new one's bytes
123 * in base64, or null to remove it (and with it the preference); left out,
124 * it stays. `preferred` shows it instead of a screenshot.
125 */
126export type ProductionImageChange = { image?: string | null; preferred?: boolean };
127
128/** How many links of its own a project keeps besides its homepage and docs. */
129export const MAX_PROJECT_LINKS = 10;
130/** The longest link label. */
131export const MAX_LINK_LABEL = 40;
132/** The longest link address. */
133export const MAX_LINK_URL = 255;
134
135/** A change to a project; only what is given changes. */
136export type ProjectChanges = {
137 name?: string;
138 /** Null or blank goes back to the repository's. */
139 description?: string | null;
140 rootDir?: string;
141 /** What it is; `auto` leaves it to detection. Anything but an app or docs stops it running anywhere. */
142 kind?: ProjectKind | "auto";
143 /** Where it runs; `auto` leaves it to Deployments. Setting it makes it an app unless it is docs. */
144 runs?: ProjectRuns | "auto";
145 /** Production's address when it deploys itself; null or blank clears it. */
146 productionUrl?: string | null;
147 /** Null or blank goes back to the repository's website. */
148 homepage?: string | null;
149 /** Null or blank clears it. */
150 docsUrl?: string | null;
151 /** Replaces its other links. */
152 links?: ProjectLink[];
153};
154
155/**
156 * What decided the kind: the setting, Deployments being on, a package its
157 * repository publishes, its files, or nothing (an app, by default).
158 * `detail` says it in a sentence.
159 */
160export type KindReason = { by: "set" | "deployments" | "packages" | "files" | "default"; detail: string };
161
162/** Where a library's files say it is published. */
163export type ProjectEcosystem = "composer" | "npm" | "cargo" | "go" | "python";
164
165export type NewProject = {
166 name: string;
167 description?: string | null;
168 /** The hosted repository it builds from. */
169 repo: RepoPath;
170 /** Where in the repository it lives; empty for the whole repository. */
171 rootDir?: string;
172};
173
174/**
175 * What a person keeps at hand in a workspace: the projects they pinned, in
176 * their order, then the ones they opened last that they have not pinned.
177 * Only projects they can still see.
178 */
179export type ProjectShortcuts = { pinned: Project[]; recent: Project[] };
180
181export interface ProjectsApi {
182 /** A workspace's projects, by name. Members, or anyone for public repositories. */
183 list(workspace: string, viewer: Viewer): Promise<Result<Project[]>>;
184 get(workspace: string, slug: string, viewer: Viewer): Promise<Result<Project>>;
185 /** The projects built from a repository, its primary one first. For services. */
186 byRepo(repoId: string): Promise<Project[]>;
187 /** Members only. */
188 create(actor: User, workspace: string, input: NewProject): Promise<Result<Project>>;
189 /**
190 * Members with a role that may change its settings. Making it something
191 * that does not run (a library, a tool, other) while Deployments are on
192 * is refused: they are turned off first.
193 */
194 update(actor: User, workspace: string, slug: string, changes: ProjectChanges): Promise<Result<Project>>;
195 /**
196 * Uploads, replaces or removes its production image, or says whether it
197 * is shown instead of a screenshot. Whoever may change the project's
198 * settings, as for its production address.
199 */
200 setProductionImage(actor: User, workspace: string, slug: string, change: ProductionImageChange): Promise<Result<Project>>;
201 /**
202 * For the screenshot service's daily refresh: every production address
203 * of a project deployed elsewhere that shows a screenshot (not an
204 * uploaded image instead), once each.
205 */
206 externalProductions(): Promise<string[]>;
207 /** For deployments: Deployments were turned on or off for the project. */
208 deploymentsChanged(projectId: string, enabled: boolean): Promise<void>;
209 /** A person's pinned and recent projects in a workspace. Empty for anyone else. */
210 shortcuts(workspace: string, viewer: Viewer): Promise<ProjectShortcuts>;
211 /**
212 * Pins a project the person can see, at `position` (0 first) or at the
213 * end; pinning one already pinned moves it. A person's own, at most 8 a
214 * workspace. Returns their pins, in order.
215 */
216 pin(actor: User, workspace: string, slug: string, position?: number | null): Promise<Result<Project[]>>;
217 /** Unpins it. Returns their pins, in order. */
218 unpin(actor: User, workspace: string, slug: string): Promise<Result<Project[]>>;
219 /** Puts their pins in this order: every pinned project's slug, once. */
220 reorderPins(actor: User, workspace: string, slugs: string[]): Promise<Result<Project[]>>;
221 /** The person opened the project: it leads their recent ones. */
222 visited(actor: User, projectId: string): Promise<void>;
223 /**
224 * For lists of public repositories, such as Explore: each one's own
225 * project's address to show, by `namespace/name` in lower case:
226 * production when it is deployed elsewhere, else its homepage, else its
227 * docs. Repositories without one are left out. At most 100 asked at once.
228 */
229 publicLinks(repos: RepoPath[]): Promise<Record<string, string>>;
230}