From 515fd7b75f532d530809f3749cdc975482a8c610 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 30 Oct 2024 11:16:44 -0400 Subject: [PATCH] git_hosting_providers: Fix support for GitLab remotes containing subgroups (#19962) This PR fixes the support for GitLab remote URLs containing subgroups. Reported in https://github.com/zed-industries/zed/issues/18012#issuecomment-2446206256. Release Notes: - N/A --- .../src/providers/gitlab.rs | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/crates/git_hosting_providers/src/providers/gitlab.rs b/crates/git_hosting_providers/src/providers/gitlab.rs index 1e7bdbb88b..7910379ef0 100644 --- a/crates/git_hosting_providers/src/providers/gitlab.rs +++ b/crates/git_hosting_providers/src/providers/gitlab.rs @@ -77,9 +77,9 @@ impl GitHostingProvider for Gitlab { return None; } - let mut path_segments = url.path_segments()?; - let owner = path_segments.next()?; - let repo = path_segments.next()?.trim_end_matches(".git"); + let mut path_segments = url.path_segments()?.collect::>(); + let repo = path_segments.pop()?.trim_end_matches(".git"); + let owner = path_segments.join("/"); Some(ParsedGitRemote { owner: owner.into(), @@ -178,6 +178,23 @@ mod tests { ); } + #[test] + fn test_parse_remote_url_given_self_hosted_https_url_with_subgroup() { + let remote_url = "https://gitlab.my-enterprise.com/group/subgroup/zed.git"; + let parsed_remote = Gitlab::from_remote_url(remote_url) + .unwrap() + .parse_remote_url(remote_url) + .unwrap(); + + assert_eq!( + parsed_remote, + ParsedGitRemote { + owner: "group/subgroup".into(), + repo: "zed".into(), + } + ); + } + #[test] fn test_build_gitlab_permalink() { let permalink = Gitlab::new().build_permalink(