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
This commit is contained in:
Marshall Bowers 2024-10-30 11:16:44 -04:00 committed by GitHub
parent 662a4440cc
commit 515fd7b75f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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::<Vec<_>>();
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(