#parse-url #url #git #git-repository #parser #normalize #github

git-url-parse

基于url crate的git仓库url解析器

11个版本

0.4.4 2022年11月5日
0.4.2 2022年5月30日
0.4.0 2021年11月14日
0.3.1 2021年1月27日
0.1.0 2020年2月6日

解析器实现 中排名第 312

Download history 1373/week @ 2024-04-24 1245/week @ 2024-05-01 1027/week @ 2024-05-08 1236/week @ 2024-05-15 1325/week @ 2024-05-22 1059/week @ 2024-05-29 1419/week @ 2024-06-05 2102/week @ 2024-06-12 1293/week @ 2024-06-19 1493/week @ 2024-06-26 654/week @ 2024-07-03 1866/week @ 2024-07-10 1226/week @ 2024-07-17 1361/week @ 2024-07-24 1485/week @ 2024-07-31 1040/week @ 2024-08-07

每月下载量 5,485
27 crate(22 个直接)中使用

MIT 许可证 MIT

22KB
292

git-url-parse

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

支持Pro Git书中指定的通用协议

查看: 4.1 服务器上的Git - 协议

支持解析Github、Bitbucket、Azure Devops的SSH/HTTPS仓库url

  • Github
  • Bitbucket
  • Azure Devops

请查看 tests/parse.rs 以获取各种输入的预期输出。


使用ssh://协议(隐式或显式)的URL将进行小规模规范化处理以便解析。

内部使用Url crate的Url::parse()在规范化后。

示例

运行带有调试输出的示例

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

简单用法和输出

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

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

示例输出

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

依赖关系

~8–11MB
~221K SLoC