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

61 lines1,476 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 "docs",
18 "explore",
19 "g1t",
20 "about",
21 "pricing",
22 "terms",
23 "privacy",
24 "help",
25 "support",
26 "status",
27 "blog",
28 "verify",
29 "forgot",
30 "reset",
31 "device",
32 "workspaces",
33 "u",
34];
35
36/// Namespaces follow GitHub's rules: letters, digits and single hyphens,
37/// not starting or ending with a hyphen, at most 39 characters.
38pub fn is_valid_namespace(value: &str) -> bool {
39 let bytes = value.as_bytes();
40 !bytes.is_empty()
41 && bytes.len() <= 39
42 && bytes
43 .iter()
44 .all(|byte| byte.is_ascii_lowercase() || byte.is_ascii_digit() || *byte == b'-')
45 && !value.starts_with('-')
46 && !value.ends_with('-')
47 && !value.contains("--")
48 && !RESERVED.contains(&value)
49}
50
51pub fn is_valid_repo_name(value: &str) -> bool {
52 !value.is_empty()
53 && value.len() <= 100
54 && value.bytes().all(|byte| {
55 byte.is_ascii_lowercase() || byte.is_ascii_digit() || matches!(byte, b'.' | b'_' | b'-')
56 })
57 && !value.starts_with('.')
58 && !value.ends_with(".git")
59 // `/<workspace>/-/…` holds the workspace's own pages.
60 && value != "-"
61}