pub fn parse(url: &str) -> Result<GitUrl> {
        // Normalize the url so we can use Url crate to process ssh urls
        let normalized = normalize_url(url)
            .with_context(|| "Url normalization into url::Url failed".to_string())?;

        // Some pre-processing for paths
        let scheme = Scheme::from_str(normalized.scheme())
            .with_context(|| format!("Scheme unsupported: {:?}", normalized.scheme()))?;

        // Normalized ssh urls can always have their first '/' removed
        let urlpath = match &scheme {
            Scheme::Ssh => {
                // At the moment, we're relying on url::Url's parse() behavior to not duplicate
                // the leading '/' when we normalize
                normalized.path()[1..].to_string()
            }
            _ => normalized.path().to_string(),
        };

        let git_suffix_check = &urlpath.ends_with(".git");

        // Parse through path for name,owner,organization
        // Support organizations for Azure Devops
        debug!("The urlpath: {:?}", &urlpath);

        // Most git services use the path for metadata in the same way, so we're going to separate
        // the metadata
        // ex. github.com/accountname/reponame
        // owner = accountname
        // name = reponame
        //
        // organizations are going to be supported on a per-host basis
        let splitpath = &urlpath.rsplit_terminator('/').collect::<Vec<&str>>();
        debug!("rsplit results for metadata: {:?}", splitpath);

        let name = splitpath[0].trim_end_matches(".git").to_string();

        let (owner, organization, fullname) = match &scheme {
            // We're not going to assume anything about metadata from a filepath
            Scheme::File => (None::<String>, None::<String>, name.clone()),
            _ => {
                let mut fullname: Vec<&str> = Vec::new();

                // TODO: Add support for parsing out orgs from these urls
                let hosts_w_organization_in_path = vec!["dev.azure.com", "ssh.dev.azure.com"];
                //vec!["dev.azure.com", "ssh.dev.azure.com", "visualstudio.com"];

                match hosts_w_organization_in_path.contains(&normalized.host_str().unwrap()) {
                    true => {
                        debug!("Found a git provider with an org");

                        // The path differs between git:// and https:// schemes

                        match &scheme {
                            // Example: "git@ssh.dev.azure.com:v3/CompanyName/ProjectName/RepoName",
                            Scheme::Ssh => {
                                // Organization
                                fullname.push(splitpath[2]);
                                // Project/Owner name
                                fullname.push(splitpath[1]);
                                // Repo name
                                fullname.push(splitpath[0]);

                                (
                                    Some(splitpath[1].to_string()),
                                    Some(splitpath[2].to_string()),
                                    fullname.join("/"),
                                )
                            }
                            // Example: "https://CompanyName@dev.azure.com/CompanyName/ProjectName/_git/RepoName",
                            Scheme::Https => {
                                // Organization
                                fullname.push(splitpath[3]);
                                // Project/Owner name
                                fullname.push(splitpath[2]);
                                // Repo name
                                fullname.push(splitpath[0]);

                                (
                                    Some(splitpath[2].to_string()),
                                    Some(splitpath[3].to_string()),
                                    fullname.join("/"),
                                )
                            }
                            _ => return Err(eyre!("Scheme not supported for host")),
                        }
                    }
                    false => {
                        // push owner
                        fullname.push(splitpath[1]);
                        // push name
                        fullname.push(name.as_str());

                        (
                            Some(splitpath[1].to_string()),
                            None::<String>,
                            fullname.join("/"),
                        )
                    }
                }
            }
        };

        let final_host = match scheme {
            Scheme::File => None,
            _ => normalized.host_str().map(|h| h.to_string()),
        };

        let final_path = match scheme {
            Scheme::File => {
                if let Some(host) = normalized.host_str() {
                    format!("{}{}", host, urlpath)
                } else {
                    urlpath
                }
            }
            _ => urlpath,
        };

        Ok(GitUrl {
            host: final_host,
            name,
            owner,
            organization,
            fullname,
            scheme,
            user: match normalized.username().to_string().len() {
                0 => None,
                _ => Some(normalized.username().to_string()),
            },
            token: normalized.password().map(|p| p.to_string()),
            port: normalized.port(),
            path: final_path,
            git_suffix: *git_suffix_check,
            scheme_prefix: url.contains("://"),
        })
    }
/// Returns a `Result<GitUrl>` after normalizing and parsing `url` for metadata
Returns a `Result` after normalizing and parsing `url` for metadata
Returns a ` Result ` after normalizing and parsing ` url ` for metadata
pub fn parse(url: &str) -> Result<GitUrl> {
        // Normalize the url so we can use Url crate to process ssh urls
        let normalized = normalize_url(url)
            .with_context(|| "Url normalization into url::Url failed".to_string())?;
        // Some pre-processing for paths
        let scheme = Scheme::from_str(normalized.scheme())
            .with_context(|| format!("Scheme unsupported: {:?}", normalized.scheme()))?;
        // Normalized ssh urls can always have their first '/' removed
        let urlpath = match &scheme {
            Scheme::Ssh => {
                // At the moment, we're relying on url::Url's parse() behavior to not duplicate
                // the leading '/' when we normalize
                normalized.path()[1..].to_string()
            }
            _ => normalized.path().to_string(),
        };
        let git_suffix_check = &urlpath.ends_with(".git");
        // Parse through path for name,owner,organization
        // Support organizations for Azure Devops
        debug!("The urlpath: {:?}", &urlpath);
        // Most git services use the path for metadata in the same way, so we're going to separate
        // the metadata
        // ex. github.com/accountname/reponame
        // owner = accountname
        // name = reponame
        //
        // organizations are going to be supported on a per-host basis
        let splitpath = &urlpath.rsplit_terminator('/').collect::<Vec<&str>>();
        debug!("rsplit results for metadata: {:?}", splitpath);
        let name = splitpath[0].trim_end_matches(".git").to_string();
        let (owner, organization, fullname) = match &scheme {
            // We're not going to assume anything about metadata from a filepath
            Scheme::File => (None::<String>, None::<String>, name.clone()),
            _ => {
                let mut fullname: Vec<&str> = Vec::new();
                // TODO: Add support for parsing out orgs from these urls
                let hosts_w_organization_in_path = vec!["dev.azure.com", "ssh.dev.azure.com"];
                //vec!["dev.azure.com", "ssh.dev.azure.com", "visualstudio.com"];
                match hosts_w_organization_in_path.contains(&normalized.host_str().unwrap()) {
                    true => {
                        debug!("Found a git provider with an org");
                        // The path differs between git:// and https:// schemes
                        match &scheme {
                            // Example: "git@ssh.dev.azure.com:v3/CompanyName/ProjectName/RepoName",
                            Scheme::Ssh => {
                                // Organization
                                fullname.push(splitpath[2]);
                                // Project/Owner name
                                fullname.push(splitpath[1]);
                                // Repo name
                                fullname.push(splitpath[0]);
                                (
                                    Some(splitpath[1].to_string()),
                                    Some(splitpath[2].to_string()),
                                    fullname.join("/"),
                                )
                            }
                            // Example: "https://CompanyName@dev.azure.com/CompanyName/ProjectName/_git/RepoName",
                            Scheme::Https => {
                                // Organization
                                fullname.push(splitpath[3]);
                                // Project/Owner name
                                fullname.push(splitpath[2]);
                                // Repo name
                                fullname.push(splitpath[0]);
                                (
                                    Some(splitpath[2].to_string()),
                                    Some(splitpath[3].to_string()),
                                    fullname.join("/"),
                                )
                            }
                            _ => return Err(eyre!("Scheme not supported for host")),
                        }
                    }
                    false => {
                        // push owner
                        fullname.push(splitpath[1]);
                        // push name
                        fullname.push(name.as_str());
                        (
                            Some(splitpath[1].to_string()),
                            None::<String>,
                            fullname.join("/"),
                        )
                    }
                }
            }
        };
        let final_host = match scheme {
            Scheme::File => None,
            _ => normalized.host_str().map(|h| h.to_string()),
        };
        let final_path = match scheme {
            Scheme::File => {
                if let Some(host) = normalized.host_str() {
                    format!("{}{}", host, urlpath)
                } else {
                    urlpath
                }
            }
            _ => urlpath,
        };
        Ok(GitUrl {
            host: final_host,
            name,
            owner,
            organization,
            fullname,
            scheme,
            user: match normalized.username().to_string().len() {
                0 => None,
                _ => Some(normalized.username().to_string()),
            },
            token: normalized.password().map(|p| p.to_string()),
            port: normalized.port(),
            path: final_path,
            git_suffix: *git_suffix_check,
            scheme_prefix: url.contains("://"),
        })
    }
pub fn parse ( url : & str ) -> Result < GitUrl > { // Normalize the url so we can use Url crate to process ssh urls let normalized = normalize_url ( url ) . with_context ( | | " " . to_string ( ) ) ? ; // Some pre-processing for paths let scheme = Scheme :: from_str ( normalized . scheme ( ) ) . with_context ( | | format ! ( " " normalized scheme ( ) ) ) ? ; // Normalized ssh urls can always have their first '/' removed let urlpath = match & scheme { Scheme :: Ssh => { // At the moment, we're relying on url::Url's parse() behavior to not duplicate // the leading '/' when we normalize normalized . path ( ) [ 1 .. ] . to_string ( ) } _ => normalized . path ( ) . to_string ( ) , } ; let git_suffix_check = & urlpath . ends_with ( " " ) ; // Parse through path for name,owner,organization // Support organizations for Azure Devops debug ! ( " " urlpath ) ; // Most git services use the path for metadata in the same way, so we're going to separate // the metadata // ex. github.com/accountname/reponame // owner = accountname // name = reponame // // organizations are going to be supported on a per-host basis let splitpath = & urlpath . rsplit_terminator ( '/' ) . collect :: < Vec < & str > > ( ) ; debug ! ( " " splitpath ) ; let name = splitpath [ 0 ] . trim_end_matches ( " " ) . to_string ( ) ; let ( owner , organization , fullname ) = match & scheme { // We're not going to assume anything about metadata from a filepath Scheme :: File => ( None :: < String > , None :: < String > , name . clone ( ) ) , _ => { let mut fullname : Vec < & str > = Vec :: new ( ) ; // TODO: Add support for parsing out orgs from these urls let hosts_w_organization_in_path = vec ! [ " " " " ] ; //vec!["dev.azure.com", "ssh.dev.azure.com", "visualstudio.com"]; match hosts_w_organization_in_path . contains ( & normalized . host_str ( ) . unwrap ( ) ) { true => { debug ! ( " " ) ; // The path differs between git:// and https:// schemes match & scheme { // Example: "git@ssh.dev.azure.com:v3/CompanyName/ProjectName/RepoName", Scheme :: Ssh => { // Organization fullname . push ( splitpath [ 2 ] ) ; // Project/Owner name fullname . push ( splitpath [ 1 ] ) ; // Repo name fullname . push ( splitpath [ 0 ] ) ; ( Some ( splitpath [ 1 ] . to_string ( ) ) , Some ( splitpath [ 2 ] . to_string ( ) ) , fullname . join ( " " ) , ) } // Example: "https://CompanyName@dev.azure.com/CompanyName/ProjectName/_git/RepoName", Scheme :: Https => { // Organization fullname . push ( splitpath [ 3 ] ) ; // Project/Owner name fullname . push ( splitpath [ 2 ] ) ; // Repo name fullname . push ( splitpath [ 0 ] ) ; ( Some ( splitpath [ 2 ] . to_string ( ) ) , Some ( splitpath [ 3 ] . to_string ( ) ) , fullname . join ( " " ) , ) } _ => return Err ( eyre ! ( " " ) ) , } } false => { // push owner fullname . push ( splitpath [ 1 ] ) ; // push name fullname . push ( name . as_str ( ) ) ; ( Some ( splitpath [ 1 ] . to_string ( ) ) , None :: < String > , fullname . join ( " " ) , ) } } } } ; let final_host = match scheme { Scheme :: File => None , _ => normalized . host_str ( ) . map ( | h | h . to_string ( ) ) , } ; let final_path = match scheme { Scheme :: File => { if let Some ( host ) = normalized . host_str ( ) { format ! ( " " host urlpath ) } else { urlpath } } _ => urlpath , } ; Ok ( GitUrl { host : final_host , name , owner , organization , fullname , scheme , user : match normalized . username ( ) . to_string ( ) . len ( ) { 0 => None , _ => Some ( normalized . username ( ) . to_string ( ) ) , } , token : normalized . password ( ) . map ( | p | p . to_string ( ) ) , port : normalized . port ( ) , path : final_path , git_suffix : * git_suffix_check , scheme_prefix : url . contains ( " " ) , } ) }
Returns a `Result<GitUrl>` after normalizing and parsing `url` for metadata
Returns a ` Result<GitUrl > ` after normalizing and parsing ` url ` for metadata
url
&str