fix: implement review comment regarding non standard ssh port scenario
This commit is contained in:
		
							parent
							
								
									5fc28346e6
								
							
						
					
					
						commit
						a786cd85ad
					
				
					 1 changed files with 15 additions and 6 deletions
				
			
		
							
								
								
									
										21
									
								
								src/lib.rs
									
										
									
									
									
								
							
							
						
						
									
										21
									
								
								src/lib.rs
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -262,8 +262,7 @@ where
 | 
			
		|||
    DE: serde::de::Error,
 | 
			
		||||
{
 | 
			
		||||
    let raw_url: String = String::deserialize(deserializer).map_err(DE::custom)?;
 | 
			
		||||
    let url = format!("ssh://{url}", url = raw_url.replace(":", "/"));
 | 
			
		||||
    Url::parse(url.as_str()).map_err(DE::custom)
 | 
			
		||||
    parse_ssh_url(&raw_url).map_err(DE::custom)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn deserialize_optional_ssh_url<'de, D, DE>(deserializer: D) -> Result<Option<Url>, DE>
 | 
			
		||||
| 
						 | 
				
			
			@ -273,13 +272,23 @@ where
 | 
			
		|||
{
 | 
			
		||||
    let raw_url: Option<String> = Option::deserialize(deserializer).map_err(DE::custom)?;
 | 
			
		||||
    raw_url
 | 
			
		||||
        .map(|raw_url| {
 | 
			
		||||
            let url = format!("ssh://{url}", url = raw_url.replace(":", "/"));
 | 
			
		||||
            Url::parse(url.as_str()).map_err(DE::custom).map(Some)
 | 
			
		||||
        })
 | 
			
		||||
        .as_ref()
 | 
			
		||||
        .map(parse_ssh_url)
 | 
			
		||||
        .map(|res| res.map_err(DE::custom).map(Some))
 | 
			
		||||
        .unwrap_or(Ok(None))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn parse_ssh_url(raw_url: &String) -> Result<Url, url::ParseError> {
 | 
			
		||||
    // in case of a non-standard ssh-port (not 22), the ssh url coming from the forgejo API
 | 
			
		||||
    // is actually parseable by the url crate, so try to do that first
 | 
			
		||||
    Url::parse(raw_url).or_else(|_| {
 | 
			
		||||
        // otherwise the ssh url is not parseable by the url crate and we try again after some
 | 
			
		||||
        // pre-processing
 | 
			
		||||
        let url = format!("ssh://{url}", url = raw_url.replace(":", "/"));
 | 
			
		||||
        Url::parse(url.as_str())
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl From<structs::DefaultMergeStyle> for structs::MergePullRequestOptionDo {
 | 
			
		||||
    fn from(value: structs::DefaultMergeStyle) -> Self {
 | 
			
		||||
        match value {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue