Crate hosted_git_info[−][src]
Expand description
hosted-git-info is a Rust port of the original hosted-git-info project on npm.
It provides metadata and conversions from repository urls for GitHub, Bitbucket and GitLab.
It will let you identify and transform various git hosts URLs between protocols. It also can tell you what the URL is for the raw path for particular file for direct access without git.
Usage
First, URL parsing may fail for various reasons and therefore returns a Result
:
use hosted_git_info::{HostedGitInfo, ParseError};
assert!(HostedGitInfo::from_url("https://www.rustlang.org/") == Err(ParseError::UnknownUrl));
Let’s parse a valid URL and look at its components.
use hosted_git_info::{HostedGitInfo, Provider};
let url = "https://github.com/foo/bar.git#branch";
let info = HostedGitInfo::from_url(url).unwrap();
assert_eq!(info.provider(), Provider::GitHub);
assert_eq!(info.user(), Some("foo"));
assert_eq!(info.project(), "bar");
assert_eq!(info.committish(), Some("branch"));
assert_eq!(info.auth(), None);
HostedGitInfo also implements the str::FromStr trait:
use hosted_git_info::{HostedGitInfo, Provider};
let url = "git+ssh://github.com:foo/bar.git";
let info: HostedGitInfo = url.parse().unwrap();
assert_eq!(info.provider(), Provider::GitHub);
assert_eq!(info.user(), Some("foo"));
assert_eq!(info.project(), "bar");
assert_eq!(info.committish(), None);
assert_eq!(info.auth(), None);
Structs
The parsed information from a git hosting URL.
Enums
Enum of the original URL types (shortcut, https, ssh, …)
Errors that can occur during parsing.
Enum of supported git hosting providers.