The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | export const GITCAFE_HOSTS = ["git.cafe", "staging.git.cafe"] as const; |
| 2 | export type GitCafeHost = (typeof GITCAFE_HOSTS)[number]; |
| 3 | |
| 4 | export function gitCafeHost(host: string): GitCafeHost | null { |
| 5 | const normalized = host.trim().toLowerCase(); |
| 6 | return GITCAFE_HOSTS.find((candidate) => candidate === normalized) ?? null; |
| 7 | } |
| 8 | |
| 9 | export function isGitCafeHost(host: string): boolean { |
| 10 | return gitCafeHost(host) !== null; |
| 11 | } |
| 12 | |
| 13 | const REPOSITORY = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u; |
| 14 | const REMOTE_PATTERNS = [ |
| 15 | /^https?:\/\/(?:[^@/]+@)?([^/:]+)(?::\d+)?\/(.+)$/iu, |
| 16 | /^ssh:\/\/(?:[^@/]+@)?([^/:]+)(?::\d+)?\/(.+)$/iu, |
| 17 | /^(?:[^@/:]+@)?([^/:]+):(.+)$/u, |
| 18 | ]; |
| 19 | |
| 20 | export function gitCafeRepositoryPath(path: string): string | null { |
| 21 | const repository = path |
| 22 | .trim() |
| 23 | .replace(/\/+$/u, "") |
| 24 | .replace(/\.git$/u, ""); |
| 25 | return REPOSITORY.test(repository) ? repository : null; |
| 26 | } |
| 27 | |
| 28 | export function parseGitCafeRemote( |
| 29 | url: string, |
| 30 | ): { readonly host: GitCafeHost; readonly repository: string } | null { |
| 31 | for (const pattern of REMOTE_PATTERNS) { |
| 32 | const match = pattern.exec(url.trim()); |
| 33 | if (!match?.[1] || !match[2]) continue; |
| 34 | const host = gitCafeHost(match[1]); |
| 35 | const repository = gitCafeRepositoryPath(match[2]); |
| 36 | return host && repository ? { host, repository } : null; |
| 37 | } |
| 38 | return null; |
| 39 | } |