diff --git a/crates/tabby-common/src/config.rs b/crates/tabby-common/src/config.rs index bfdb3ee988af..0701b3393385 100644 --- a/crates/tabby-common/src/config.rs +++ b/crates/tabby-common/src/config.rs @@ -79,6 +79,7 @@ impl RepositoryConfig { } pub fn canonicalize_url(url: &str) -> String { + let url = url.strip_suffix(".git").unwrap_or(url); url::Url::parse(url) .map(|mut url| { let _ = url.set_password(None); @@ -171,7 +172,7 @@ mod tests { let repo = RepositoryConfig { git_url: "https://github.com/TabbyML/tabby.git".to_owned(), }; - assert!(repo.dir().ends_with("https_github.com_TabbyML_tabby.git")); + assert!(repo.dir().ends_with("https_github.com_TabbyML_tabby")); } #[test] @@ -200,5 +201,10 @@ mod tests { RepositoryConfig::canonicalize_url("https://github.com/TabbyML/tabby"), "https://github.com/TabbyML/tabby" ); + + assert_eq!( + RepositoryConfig::canonicalize_url("https://github.com/TabbyML/tabby.git"), + "https://github.com/TabbyML/tabby" + ); } } diff --git a/crates/tabby/src/services/code.rs b/crates/tabby/src/services/code.rs index 992fa2592c7d..66744eac62e1 100644 --- a/crates/tabby/src/services/code.rs +++ b/crates/tabby/src/services/code.rs @@ -161,7 +161,7 @@ fn closest_match<'a>( .into_iter() .filter(|elem| GitUrl::parse(&elem.git_url).is_ok_and(|x| x.name == git_search.name)) // If there're multiple matches, we pick the one with highest alphabetical order - .min_by_key(|elem| elem.git_url.as_str()) + .min_by_key(|elem| elem.canonical_git_url()) .map(|x| x.git_url.as_str()) } diff --git a/ee/tabby-webserver/src/cron/github.rs b/ee/tabby-webserver/src/cron/github.rs index 4d49a3a1e3fa..dc5ead72ec00 100644 --- a/ee/tabby-webserver/src/cron/github.rs +++ b/ee/tabby-webserver/src/cron/github.rs @@ -61,9 +61,15 @@ async fn refresh_repositories_for_provider( .strip_prefix("git://") .map(|url| format!("https://{url}")) .unwrap_or(url); + let url = url.strip_suffix(".git").unwrap_or(&url); service - .upsert_github_provided_repository(provider.id.clone(), id, repo.name, url) + .upsert_github_provided_repository( + provider.id.clone(), + id, + repo.full_name.unwrap_or(repo.name), + url.to_string(), + ) .await?; } diff --git a/ee/tabby-webserver/src/cron/gitlab.rs b/ee/tabby-webserver/src/cron/gitlab.rs index 1639c673d14b..bb0134af7a48 100644 --- a/ee/tabby-webserver/src/cron/gitlab.rs +++ b/ee/tabby-webserver/src/cron/gitlab.rs @@ -54,13 +54,15 @@ async fn refresh_repositories_for_provider( }; for repo in repos { let id = repo.id.to_string(); + let url = repo.http_url_to_repo; + let url = url.strip_suffix(".git").unwrap_or(&url); service .upsert_gitlab_provided_repository( provider.id.clone(), id, - repo.name, - repo.http_url_to_repo, + repo.name_with_namespace, + url.to_string(), ) .await?; } @@ -71,7 +73,7 @@ async fn refresh_repositories_for_provider( #[derive(Deserialize)] struct Repository { id: u128, - name: String, + name_with_namespace: String, http_url_to_repo: String, }