Skip to main content

parse_repo_spec

Function parse_repo_spec 

Source
pub fn parse_repo_spec(input: &str) -> Result<RepoSplit>
Expand description

Parse a repository spec string in OWNER/REPO format.

The input must contain exactly one / separator. Trailing .git is stripped from the repo name. Empty owner or repo segments are rejected.

§Errors

Returns an error if the input is empty, lacks a /, contains multiple / separators, or has empty owner or repo segments.

§Examples

use gor::repository::parse_repo_spec;

let spec = parse_repo_spec("octocat/hello-world").expect("valid spec");
assert_eq!(spec.owner, "octocat");
assert_eq!(spec.repo, "hello-world");

// Trailing .git is stripped
let spec = parse_repo_spec("octocat/repo.git").expect("valid spec");
assert_eq!(spec.repo, "repo");

// Invalid inputs
assert!(parse_repo_spec("").is_err());
assert!(parse_repo_spec("no-slash").is_err());
assert!(parse_repo_spec("too/many/slashes").is_err());