pub fn to_ssh_url(url: &str) -> Option<String> {
if url.starts_with("git@") || url.starts_with("ssh://") {
return Some(url.to_string());
}
let trimmed = url.trim_end_matches(".git");
let prefix = "https://";
if trimmed.starts_with(prefix) {
let rest = &trimmed[prefix.len()..];
let parts: Vec<&str> = rest.split('/').collect();
if parts.len() >= 2 {
let host = parts[0];
let path = parts[1..].join("/");
return Some(format!("git@{}:{}.git", host, path));
}
}
None
}
pub fn to_github_pr_url(remote_url: &str, pr: &str) -> Option<String> {
if remote_url.starts_with("git@github.com:") {
let repo = remote_url.trim_start_matches("git@github.com:").trim_end_matches(".git");
return Some(format!("https://github.com/{}/pull/{}", repo, pr));
}
if remote_url.starts_with("https://github.com/") {
let repo = remote_url.trim_start_matches("https://github.com/").trim_end_matches(".git");
return Some(format!("https://github.com/{}/pull/{}", repo, pr));
}
None
}