Crates.io | ghrepo |
lib.rs | ghrepo |
version | |
source | src |
created_at | 2022-07-08 13:44:41.474487 |
updated_at | 2025-01-02 16:42:09.811508 |
description | Parse & construct GitHub repository URLs & specifiers |
homepage | |
repository | https://github.com/jwodder/ghrepo-rust |
max_upload_size | |
id | 621813 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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.
use std::error::Error;
use std::str::FromStr;
use ghrepo::GHRepo;
fn main() -> Result<(), Box<dyn Error>> {
let repo = GHRepo::new("octocat", "repository")?;
assert_eq!(repo.owner(), "octocat");
assert_eq!(repo.name(), "repository");
assert_eq!(repo.to_string(), "octocat/repository");
assert_eq!(repo.html_url(), "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(())
}
There is also an accompanying binary package
ghrepo-cli
that provides a CLI command
named ghrepo
for showing the GitHub repository for a directory, optionally
along with derived URLs. Feel free to install it if you're interested!