Project Status: Active – The project has reached a stable, usable state and is being actively developed. CI Status codecov.io MIT License

GitHub | crates.io | Documentation | Issues | Changelog

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.

When the serde feature is enabled, the GHRepo type will additionally be serializable & deserializable with serde.

Installation

ghrepo requires version 1.60 of Rust or higher. To use the ghrepo library in your Cargo project, add the following to your Cargo.toml:

toml [dependencies] ghrepo = "0.4.0"

To use ghrepo with its serde feature, add the following instead:

toml [dependencies] ghrepo = { version = "0.4.0", features = ["serde"] }

To install the ghrepo command on your system, use cargo install:

cargo install ghrepo

Example

```rust use std::error::Error; use std::str::FromStr; use ghrepo::GHRepo;

fn main() -> Result<(), Box> { let repo = GHRepo::new("octocat", "repository")?; asserteq!(repo.owner(), "octocat"); asserteq!(repo.name(), "repository"); asserteq!(repo.tostring(), "octocat/repository"); asserteq!(repo.htmlurl(), "https://github.com/octocat/repository");

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

let repo3 = GHRepo::from_str("https://github.com/octocat/repository")?;
assert_eq!(repo, repo3);
Ok(())

} ```

Command

ghrepo also provides a command of the same name for getting the GitHub repository associated with a local Git repository:

text ghrepo [<options>] [<dirpath>]

By default, the ghrepo command just outputs the repository "fullname" (a string of the form {owner}/{name}). If the -J or --json option is supplied, a JSON object is instead output, containing fields for the repository owner, name, fullname, and individual URLs, like so:

json { "owner": "jwodder", "name": "ghrepo-rust", "fullname": "jwodder/ghrepo-rust", "api_url": "https://api.github.com/repos/jwodder/ghrepo-rust", "clone_url": "https://github.com/jwodder/ghrepo-rust.git", "git_url": "git://github.com/jwodder/ghrepo-rust.git", "html_url": "https://github.com/jwodder/ghrepo-rust", "ssh_url": "git@github.com:jwodder/ghrepo-rust.git" }

Options