spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / telemetry / hooks / context / remote-hash-of / normalized-remote-of / normalized-remote-of.ts
24 lines · 804 BRaw
1/**
2 * A git remote URL as the CLI normalizes it before hashing: `host/path`
3 * lowercased, the user and a trailing `.git` dropped.
4 *
5 * The scp form (`git@host:owner/repo`) and the URL form (`https://` or
6 * `ssh://`) alike; undefined for anything else.
7 *
8 * @param remote the remote URL as `$.session.repo()` answers it
9 * @returns the normalized remote, or undefined
10 */
11export function normalizedRemoteOf(remote: string): string | undefined {
12 const trimmed = remote.trim()
13
14 const [, host, path] =
15 /^git@([^:/@]+):(.+?)(?:\.git)?$/.exec(trimmed) ??
16 /^(?:https?|ssh):\/\/(?:[^@/?#]*@)?([^/?#@]+)\/(.+?)(?:\.git)?$/.exec(
17 trimmed,
18 ) ??
19 []
20
21 const isRecognized = host !== undefined && path !== undefined
22
23 return isRecognized ? `${host}/${path}`.toLowerCase() : undefined
24}