g1t/crates/contracts/src/names.rs
| 1 | /// Routes and reserved words that may not be registered as usernames. |
| 2 | const RESERVED: &[&str] = &[ |
| 3 | "api", |
| 4 | "mcp", |
| 5 | "login", |
| 6 | "logout", |
| 7 | "register", |
| 8 | "new", |
| 9 | "settings", |
| 10 | "search", |
| 11 | "admin", |
| 12 | "auth", |
| 13 | // g1t.sh/integrations/github/setup: where GitHub returns after an install. |
| 14 | "integrations", |
| 15 | "pulls", |
| 16 | "issues", |
| 17 | "oauth", |
| 18 | "assets", |
| 19 | "avatars", |
| 20 | "docs", |
| 21 | "explore", |
| 22 | "g1t", |
| 23 | "about", |
| 24 | "pricing", |
| 25 | "terms", |
| 26 | "privacy", |
| 27 | "policies", |
| 28 | "security", |
| 29 | "help", |
| 30 | "support", |
| 31 | "status", |
| 32 | "blog", |
| 33 | "verify", |
| 34 | "forgot", |
| 35 | "reset", |
| 36 | "device", |
| 37 | "workspaces", |
| 38 | "u", |
| 39 | // g1t.sh/invite/<code>: invite links; and the waitlist. |
| 40 | "invite", |
| 41 | "invites", |
| 42 | "waitlist", |
| 43 | ]; |
| 44 | |
| 45 | /// Namespaces follow GitHub's rules: letters, digits and single hyphens, |
| 46 | /// not starting or ending with a hyphen, at most 39 characters. |
| 47 | pub fn is_valid_namespace(value: &str) -> bool { |
| 48 | let bytes = value.as_bytes(); |
| 49 | !bytes.is_empty() |
| 50 | && bytes.len() <= 39 |
| 51 | && bytes |
| 52 | .iter() |
| 53 | .all(|byte| byte.is_ascii_lowercase() || byte.is_ascii_digit() || *byte == b'-') |
| 54 | && !value.starts_with('-') |
| 55 | && !value.ends_with('-') |
| 56 | && !value.contains("--") |
| 57 | && !RESERVED.contains(&value) |
| 58 | } |
| 59 | |
| 60 | pub fn is_valid_repo_name(value: &str) -> bool { |
| 61 | !value.is_empty() |
| 62 | && value.len() <= 100 |
| 63 | && value.bytes().all(|byte| { |
| 64 | byte.is_ascii_lowercase() || byte.is_ascii_digit() || matches!(byte, b'.' | b'_' | b'-') |
| 65 | }) |
| 66 | && !value.starts_with('.') |
| 67 | && !value.ends_with(".git") |
| 68 | // `/<workspace>/-/…` holds the workspace's own pages. |
| 69 | && value != "-" |
| 70 | } |