flagon-io/g1t

public

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/crates/contracts/src/names.rs

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