diff options
Diffstat (limited to 'src/purgatory/sync/functions.rs')
| -rw-r--r-- | src/purgatory/sync/functions.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/purgatory/sync/functions.rs b/src/purgatory/sync/functions.rs index 751dd5e..13b2e47 100644 --- a/src/purgatory/sync/functions.rs +++ b/src/purgatory/sync/functions.rs | |||
| @@ -20,16 +20,32 @@ use super::throttle::ThrottleManager; | |||
| 20 | 20 | ||
| 21 | /// Extract domain from a URL. | 21 | /// Extract domain from a URL. |
| 22 | /// | 22 | /// |
| 23 | /// Supports HTTP(S) URLs. SSH URLs (git@...) are not supported. | ||
| 24 | /// | ||
| 23 | /// # Examples | 25 | /// # Examples |
| 24 | /// | 26 | /// |
| 25 | /// ```ignore | 27 | /// ```ignore |
| 26 | /// assert_eq!(extract_domain("https://github.com/foo/bar.git"), Some("github.com".to_string())); | 28 | /// assert_eq!(extract_domain("https://github.com/foo/bar.git"), Some("github.com".to_string())); |
| 29 | /// assert_eq!(extract_domain("http://example.com:8080/repo.git"), Some("example.com".to_string())); | ||
| 27 | /// assert_eq!(extract_domain("git@github.com:foo/bar.git"), None); // SSH URLs not supported | 30 | /// assert_eq!(extract_domain("git@github.com:foo/bar.git"), None); // SSH URLs not supported |
| 28 | /// ``` | 31 | /// ``` |
| 29 | fn extract_domain(url: &str) -> Option<String> { | 32 | fn extract_domain(url: &str) -> Option<String> { |
| 30 | url::Url::parse(url) | 33 | // Simple URL parsing for HTTP(S) URLs |
| 31 | .ok() | 34 | // Format: scheme://[user@]host[:port]/path |
| 32 | .and_then(|u| u.host_str().map(|s| s.to_string())) | 35 | let url = url.strip_prefix("https://").or_else(|| url.strip_prefix("http://"))?; |
| 36 | |||
| 37 | // Remove user info if present (e.g., "user@host" -> "host") | ||
| 38 | let url = url.split('@').last()?; | ||
| 39 | |||
| 40 | // Extract host (before first '/' or ':') | ||
| 41 | let host = url.split('/').next()?; | ||
| 42 | let host = host.split(':').next()?; | ||
| 43 | |||
| 44 | if host.is_empty() { | ||
| 45 | None | ||
| 46 | } else { | ||
| 47 | Some(host.to_string()) | ||
| 48 | } | ||
| 33 | } | 49 | } |
| 34 | 50 | ||
| 35 | /// Find the next URL to try for an identifier. | 51 | /// Find the next URL to try for an identifier. |