fluentci_common/
util.rs

1pub fn extract_git_repo(url: &str) -> String {
2    let mut repo = url
3        .replace("https://", "")
4        .replace("http://", "")
5        .replace("git@", "")
6        .replace(":", "/")
7        .replace(".git", "");
8
9    if repo.ends_with('/') {
10        repo.pop();
11    }
12
13    // remove last part of the url
14    // example:
15    // github.com/owner/repo.git -> github.com/owner
16    let mut parts: Vec<&str> = repo.split('/').collect();
17    parts.pop();
18    parts.join("/")
19}
20
21pub fn validate_git_url(url: &str) -> bool {
22    regex::Regex::new(
23        r"^(?:https:\/\/([^\/]+)\/([^\/]+)\/([^\/]+)|git@([^:]+):([^\/]+)\/([^\/]+))$",
24    )
25    .unwrap()
26    .is_match(url)
27}