Skip to content

Commit

Permalink
Fixes parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdappollonio committed Aug 25, 2024
1 parent e3cc11c commit 3b983c4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ pub fn repository(repo_url: String) -> Result<(String, String, String), ParseRep
return parse_http_url(&repo_url).map_err(ParseRepoError::from);
}

match repo_url.split('/').collect::<Vec<&str>>().as_slice() {
[_, _] => parse_user_repo(&repo_url).map_err(ParseRepoError::from),
_ => parse_ssh_url(&repo_url).map_err(ParseRepoError::from),
if repo_url.contains('@') && repo_url.contains(':') {
return parse_ssh_url(&repo_url).map_err(ParseRepoError::from);
}

parse_user_repo(&repo_url).map_err(ParseRepoError::from)
}

#[derive(Debug)]
Expand All @@ -94,6 +95,7 @@ enum CantConvertSSHError {
}

fn parse_user_repo(location: &str) -> Result<(String, String, String), CantConvertError> {
dbg!("parsing using user/repo");
let re = Regex::new(r"^(?<user>[a-zA-Z0-9-]+)/(?<repo>[\w\.-]+)$")
.map_err(CantConvertError::InvalidRegexp)?;

Expand All @@ -113,6 +115,7 @@ fn parse_user_repo(location: &str) -> Result<(String, String, String), CantConve
}

fn parse_ssh_url(url: &str) -> Result<(String, String, String), CantConvertSSHError> {
dbg!("parsing using SSH");
let parts: Vec<&str> = url.splitn(2, '@').collect();

if parts.len() != 2 {
Expand All @@ -138,6 +141,7 @@ fn parse_ssh_url(url: &str) -> Result<(String, String, String), CantConvertSSHEr
}

fn parse_http_url(url: &str) -> Result<(String, String, String), CantConvertError> {
dbg!("parsing using HTTP");
let re = Regex::new(r"^(https?://)?github\.com/(?<org>[^/]+)/(?<project>[^/]+).*$")
.map_err(CantConvertError::InvalidRegexp)?;

Expand Down

0 comments on commit 3b983c4

Please sign in to comment.