9 releases (breaking)

0.7.0 Jan 2, 2025
0.6.0 Feb 16, 2024
0.5.0 Apr 27, 2023
0.4.0 Feb 15, 2023
0.1.0 Jul 8, 2022

#1317 in Web programming

Download history 37/week @ 2024-10-27 18/week @ 2024-11-03 19/week @ 2024-11-10 24/week @ 2024-11-17 37/week @ 2024-11-24 21/week @ 2024-12-01 44/week @ 2024-12-08 41/week @ 2024-12-15 31/week @ 2024-12-22 190/week @ 2024-12-29 177/week @ 2025-01-05 77/week @ 2025-01-12 63/week @ 2025-01-19 87/week @ 2025-01-26 148/week @ 2025-02-02 71/week @ 2025-02-09

375 downloads per month
Used in 2 crates

MIT license

51KB
675 lines

Project Status: Active – The project has reached a stable, usable state and is being actively developed. CI Status codecov.io Minimum Supported Rust Version 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.

Example

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(())
}

Command

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!

Dependencies

~160KB