| 280 | } |
| 281 | |
| 282 | fn match_git_http_url(original: &str) -> Option<GitRepo> { |
| 283 | let uri = translate_shortcut(original); |
| 284 | let uri = uri.as_deref().unwrap_or(original); |
| 285 | |
| 286 | let repo_regex = regex::Regex::new( |
| 287 | r"https://(?P<host>[a-zA-Z0-9.-]+)/(?P<repo>[a-zA-Z0-9][a-zA-Z0-9_-]+/[a-zA-Z0-9][a-zA-Z0-9_-]+)/?((branch|tag|tree)/(?P<ref>.+))?$", |
| 288 | ) |
| 289 | .into_diagnostic() |
| 290 | .expect("invalid HTTP regex"); |
| 291 | |
| 292 | let caps = repo_regex.captures(uri)?; |
| 293 | |
| 294 | let host = caps.name("host")?; |
| 295 | let repo = caps.name("repo")?; |
| 296 | let reference = caps |
| 297 | .name("ref") |
| 298 | .map(|m| m.as_str().trim_end_matches('/').replace('/', "-")); |
| 299 | |
| 300 | Some(GitRepo { |
| 301 | host: host.as_str().into(), |
| 302 | repo: repo.as_str().into(), |
| 303 | reference, |
| 304 | auth_user: None, |
| 305 | protocol: GitProtocol::Http, |
| 306 | }) |
| 307 | } |
| 308 | |
| 309 | fn match_git_ssh_url(value: &str) -> Option<GitRepo> { |
| 310 | let ssh_regex = regex::Regex::new( |