Crate ghrepo

source ·
Expand description

ghrepo extracts a GitHub repository’s owner & name from various GitHub URL formats (or just from a string of the form OWNER/REPONAME or REPONAME), and the resulting object provides properties for going in reverse to determine the possible URLs. Also included is a struct for performing a couple useful inspections on local Git repositories, including determining the corresponding GitHub owner & repository name.


The ghrepo crate has the following optional features:

  • cli — Adds dependencies needed by the ghrepo binary. This is enabled by default, but if you are using ghrepo as a library, it is recommended that you remove it by disabling default features.

  • serde — Enables serializing & deserializing the GHRepo type with serde


let repo = GHRepo::new("octocat", "repository")?;
assert_eq!(repo.owner(), "octocat");
assert_eq!(, "repository");
assert_eq!(repo.to_string(), "octocat/repository");
assert_eq!(repo.html_url(), "");

let repo2 = GHRepo::from_str("octocat/repository")?;
assert_eq!(repo, repo2);

let repo3 = GHRepo::from_str("")?;
assert_eq!(repo, repo3);


  • A container for a GitHub repository spec, consisting of a repository owner and a repository name (sometimes also called the “repo” component).
  • A local Git repository.



  • Test whether a string is a valid repository name.
  • Test whether a string is a valid GitHub user login or organization name.
  • Test whether a string is a valid repository specifier/full name of the form {owner}/{name}.