#git #url #parsing #normalize

git-url-parse

A parser for git repo urls based on url crate

11 releases

0.4.4 Nov 5, 2022
0.4.2 May 30, 2022
0.4.0 Nov 14, 2021
0.3.1 Jan 27, 2021
0.1.0 Feb 6, 2020

#185 in Parser implementations

Download history 969/week @ 2023-02-07 1200/week @ 2023-02-14 1091/week @ 2023-02-21 1207/week @ 2023-02-28 1174/week @ 2023-03-07 980/week @ 2023-03-14 677/week @ 2023-03-21 1132/week @ 2023-03-28 585/week @ 2023-04-04 856/week @ 2023-04-11 841/week @ 2023-04-18 1062/week @ 2023-04-25 1006/week @ 2023-05-02 667/week @ 2023-05-09 834/week @ 2023-05-16 740/week @ 2023-05-23

3,448 downloads per month
Used in 16 crates (15 directly)

MIT license

22KB
292 lines

git-url-parse

Minimum Supported Rust Version Crates.io Crates.io Github actions build status docs.rs licence Maintenance

Supports common protocols as specified by the Pro Git book

See: 4.1 Git on the Server - The Protocols

Supports parsing SSH/HTTPS repo urls for:

  • Github
  • Bitbucket
  • Azure Devops

See tests/parse.rs for expected output for a variety of inputs.


URLs that use the ssh:// protocol (implicitly or explicitly) undergo a small normalization process in order to be parsed.

Internally uses Url::parse() from the Url crate after normalization.

Examples

Run example with debug output

$ RUST_LOG=git_url_parse cargo run --example multi
$ RUST_LOG=git_url_parse cargo run --example trim_auth 

Simple usage and output

$ cargo run --example readme
use git_url_parse::GitUrl;

fn main() {
    println!("SSH: {:#?}", GitUrl::parse("git@github.com:tjtelan/git-url-parse-rs.git"));
    println!("HTTPS: {:#?}", GitUrl::parse("https://github.com/tjtelan/git-url-parse-rs"));
}

Example Output

SSH: Ok(
    GitUrl {
        host: Some(
            "github.com",
        ),
        name: "git-url-parse-rs",
        owner: Some(
            "tjtelan",
        ),
        organization: None,
        fullname: "tjtelan/git-url-parse-rs",
        scheme: Ssh,
        user: Some(
            "git",
        ),
        token: None,
        port: None,
        path: "tjtelan/git-url-parse-rs.git",
        git_suffix: true,
        scheme_prefix: false,
    },
)
HTTPS: Ok(
    GitUrl {
        host: Some(
            "github.com",
        ),
        name: "git-url-parse-rs",
        owner: Some(
            "tjtelan",
        ),
        organization: None,
        fullname: "tjtelan/git-url-parse-rs",
        scheme: Https,
        user: None,
        token: None,
        port: None,
        path: "/tjtelan/git-url-parse-rs",
        git_suffix: false,
        scheme_prefix: true,
    },
)

Dependencies

~9.5MB
~222K SLoC