git_hosting_providers: Refactor constructors (#26919)
This PR refactors the constructors for the various Git hosting providers to facilitate adding support for more self-hosted variants. Release Notes: - N/A
This commit is contained in:
@@ -17,13 +17,17 @@ pub struct Gitlab {
|
||||
}
|
||||
|
||||
impl Gitlab {
|
||||
pub fn new() -> Self {
|
||||
pub fn new(name: impl Into<String>, base_url: Url) -> Self {
|
||||
Self {
|
||||
name: "GitLab".to_string(),
|
||||
base_url: Url::parse("https://gitlab.com").unwrap(),
|
||||
name: name.into(),
|
||||
base_url,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn public_instance() -> Self {
|
||||
Self::new("GitLab", Url::parse("https://gitlab.com").unwrap())
|
||||
}
|
||||
|
||||
pub fn from_remote_url(remote_url: &str) -> Result<Self> {
|
||||
let host = get_host_from_git_remote_url(remote_url)?;
|
||||
if host == "gitlab.com" {
|
||||
@@ -37,10 +41,10 @@ impl Gitlab {
|
||||
bail!("not a GitLab URL");
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
name: "GitLab Self-Hosted".to_string(),
|
||||
base_url: Url::parse(&format!("https://{}", host))?,
|
||||
})
|
||||
Ok(Self::new(
|
||||
"GitLab Self-Hosted",
|
||||
Url::parse(&format!("https://{}", host))?,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +139,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_parse_remote_url_given_ssh_url() {
|
||||
let parsed_remote = Gitlab::new()
|
||||
let parsed_remote = Gitlab::public_instance()
|
||||
.parse_remote_url("git@gitlab.com:zed-industries/zed.git")
|
||||
.unwrap();
|
||||
|
||||
@@ -150,7 +154,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_parse_remote_url_given_https_url() {
|
||||
let parsed_remote = Gitlab::new()
|
||||
let parsed_remote = Gitlab::public_instance()
|
||||
.parse_remote_url("https://gitlab.com/zed-industries/zed.git")
|
||||
.unwrap();
|
||||
|
||||
@@ -200,7 +204,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_build_gitlab_permalink() {
|
||||
let permalink = Gitlab::new().build_permalink(
|
||||
let permalink = Gitlab::public_instance().build_permalink(
|
||||
ParsedGitRemote {
|
||||
owner: "zed-industries".into(),
|
||||
repo: "zed".into(),
|
||||
@@ -218,7 +222,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_build_gitlab_permalink_with_single_line_selection() {
|
||||
let permalink = Gitlab::new().build_permalink(
|
||||
let permalink = Gitlab::public_instance().build_permalink(
|
||||
ParsedGitRemote {
|
||||
owner: "zed-industries".into(),
|
||||
repo: "zed".into(),
|
||||
@@ -236,7 +240,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_build_gitlab_permalink_with_multi_line_selection() {
|
||||
let permalink = Gitlab::new().build_permalink(
|
||||
let permalink = Gitlab::public_instance().build_permalink(
|
||||
ParsedGitRemote {
|
||||
owner: "zed-industries".into(),
|
||||
repo: "zed".into(),
|
||||
|
||||
Reference in New Issue
Block a user