Skip to content
51 linesCodeBlameRaw
1// Namespaces follow GitHub's rules (no leading, trailing or doubled hyphens),
2// so "--" can never appear inside one.
3const NAMESPACE = /^[a-z0-9](?:[a-z0-9]|-(?=[a-z0-9])){0,38}$/;
4const REPO_NAME = /^[a-z0-9._-]{1,100}$/;
5
6/** Routes and reserved words that may not be registered as usernames. */
7const RESERVED = new Set([
8 "api", "mcp", "login", "logout", "register", "new", "settings", "search",
9 "admin", "auth", "integrations", "pulls", "issues", "verify", "confirm-email", "forgot", "reset", "device", "workspaces", "u", "oauth", "assets", "avatars", "docs", "explore", "about", "pricing",
10 // g1t itself, and the name its agent once went by: everything g1t does is
11 // shown as `g1t`, so nobody else may be called either. `ghost` wrote what
12 // a deleted account wrote (`GHOST_USERNAME`).
13 "g1t", "g1t-agent", "ghost",
14 // Trust pages on g1t.sh, and names kept for them.
15 "policies", "security", "support", "status", "terms", "privacy", "help", "blog",
16 // Invite links, and the waitlist.
17 "invite", "invites", "waitlist",
18 // g1t.sh/invitations: the workspace invitations waiting for an answer.
19 "invitations",
20 // The container registry, at g1t.sh/v2/.
21 "v2",
22 // g1t.sh/inbox, and the name it might also go by.
23 "inbox", "notifications",
24]);
25
26/** Whether `value`, whatever its case, is a name nobody can register: a route, or g1t's own. */
27export function isReservedName(value: string): boolean {
28 return RESERVED.has(value.trim().toLowerCase());
29}
30
31export function isValidNamespace(value: string): boolean {
32 return isNamespaceShaped(value) && !isReservedName(value);
33}
34
35/**
36 * Whether `value` has a namespace's shape, reserved or not: what a
37 * workspace's old name or an alias staff set (such as `g1t`) can be.
38 */
39export function isNamespaceShaped(value: string): boolean {
40 return NAMESPACE.test(value);
41}
42
43export function isValidRepoName(value: string): boolean {
44 return (
45 REPO_NAME.test(value) &&
46 !value.startsWith(".") &&
47 !value.endsWith(".git") &&
48 // `/<workspace>/-/…` holds the workspace's own pages.
49 value !== "-"
50 );
51}