Skip to main content

parse_github_path

Function parse_github_path 

Source
pub fn parse_github_path(url: &str) -> Option<GithubPath>
Expand description

Parse a git remote URL into a GithubPath ({ owner, repo }).

Why: the canonical identity of a hosted project is the owner/repo path in its remote URL, not the local directory name. Parsing it purely (no I/O) makes every URL-shape branch deterministically unit-testable. What: handles the three canonical shapes — SSH (git@github.com:owner/repo.git), HTTPS (https://github.com/owner/repo(.git)), and scp-less host paths — by stripping the scheme + host, trimming a trailing .git/slashes, splitting on /, and taking the final two segments as (owner, repo). Each segment is slugified. When only one trailing segment is parseable (no owner) the repo is kept and owner falls back to UNKNOWN_OWNER so the result is always a two-segment path. Returns None only when no non-empty repo slug can be produced (empty input, host-only URL). Test: parse_ssh_github, parse_https_github_with_and_without_dot_git, parse_non_github_host, parse_trailing_slash, parse_nested_group_takes_last_two, parse_repo_only_uses_unknown_owner, parse_empty_returns_none.