Restore signature of build_permalink (#8609)

This PR restores the original signature of `build_permalink`, which
intentionally uses a params struct to avoid mixing up the various `&str`
params that could otherwise be accidentally provided in the wrong order
without being caught by the compiler.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-02-29 08:52:09 -05:00 committed by GitHub
parent dc7befb884
commit faa6f979be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 159 additions and 156 deletions

View file

@ -8625,6 +8625,8 @@ impl Editor {
} }
fn get_permalink_to_line(&mut self, cx: &mut ViewContext<Self>) -> Result<url::Url> { fn get_permalink_to_line(&mut self, cx: &mut ViewContext<Self>) -> Result<url::Url> {
use git::permalink::{build_permalink, BuildPermalinkParams};
let project = self.project.clone().ok_or_else(|| anyhow!("no project"))?; let project = self.project.clone().ok_or_else(|| anyhow!("no project"))?;
let project = project.read(cx); let project = project.read(cx);
@ -8649,6 +8651,7 @@ impl Editor {
.lock() .lock()
.head_sha() .head_sha()
.ok_or_else(|| anyhow!("failed to read HEAD SHA"))?; .ok_or_else(|| anyhow!("failed to read HEAD SHA"))?;
let path = maybe!({ let path = maybe!({
let buffer = self.buffer().read(cx).as_singleton()?; let buffer = self.buffer().read(cx).as_singleton()?;
let file = buffer.read(cx).file().and_then(|f| f.as_local())?; let file = buffer.read(cx).file().and_then(|f| f.as_local())?;
@ -8659,12 +8662,12 @@ impl Editor {
let selections = self.selections.all::<Point>(cx); let selections = self.selections.all::<Point>(cx);
let selection = selections.iter().peekable().next(); let selection = selections.iter().peekable().next();
git::permalink::build_permalink( build_permalink(BuildPermalinkParams {
&origin_url, remote_url: &origin_url,
&sha, sha: &sha,
&path, path: &path,
selection.map(|selection| selection.range()), selection: selection.map(|selection| selection.range()),
) })
} }
pub fn copy_permalink_to_line(&mut self, _: &CopyPermalinkToLine, cx: &mut ViewContext<Self>) { pub fn copy_permalink_to_line(&mut self, _: &CopyPermalinkToLine, cx: &mut ViewContext<Self>) {

View file

@ -8,7 +8,7 @@ enum GitHostingProvider {
Github, Github,
Gitlab, Gitlab,
Gitee, Gitee,
BitbucketCloud, Bitbucket,
} }
impl GitHostingProvider { impl GitHostingProvider {
@ -17,7 +17,7 @@ impl GitHostingProvider {
Self::Github => "https://github.com", Self::Github => "https://github.com",
Self::Gitlab => "https://gitlab.com", Self::Gitlab => "https://gitlab.com",
Self::Gitee => "https://gitee.com", Self::Gitee => "https://gitee.com",
Self::BitbucketCloud => "https://bitbucket.org", Self::Bitbucket => "https://bitbucket.org",
}; };
Url::parse(&base_url).unwrap() Url::parse(&base_url).unwrap()
@ -31,7 +31,7 @@ impl GitHostingProvider {
match self { match self {
Self::Github | Self::Gitlab | Self::Gitee => format!("L{}", line), Self::Github | Self::Gitlab | Self::Gitee => format!("L{}", line),
Self::BitbucketCloud => format!("lines-{}", line), Self::Bitbucket => format!("lines-{}", line),
} }
} else { } else {
let start_line = selection.start.row + 1; let start_line = selection.start.row + 1;
@ -40,18 +40,27 @@ impl GitHostingProvider {
match self { match self {
Self::Github => format!("L{}-L{}", start_line, end_line), Self::Github => format!("L{}-L{}", start_line, end_line),
Self::Gitlab | Self::Gitee => format!("L{}-{}", start_line, end_line), Self::Gitlab | Self::Gitee => format!("L{}-{}", start_line, end_line),
Self::BitbucketCloud => format!("lines-{}:{}", start_line, end_line), Self::Bitbucket => format!("lines-{}:{}", start_line, end_line),
} }
} }
} }
} }
pub fn build_permalink( pub struct BuildPermalinkParams<'a> {
remote_url: &str, pub remote_url: &'a str,
sha: &str, pub sha: &'a str,
path: &str, pub path: &'a str,
selection: Option<Range<Point>>, pub selection: Option<Range<Point>>,
) -> Result<Url> { }
pub fn build_permalink(params: BuildPermalinkParams) -> Result<Url> {
let BuildPermalinkParams {
remote_url,
sha,
path,
selection,
} = params;
let ParsedGitRemote { let ParsedGitRemote {
provider, provider,
owner, owner,
@ -63,7 +72,7 @@ pub fn build_permalink(
GitHostingProvider::Github => format!("{owner}/{repo}/blob/{sha}/{path}"), GitHostingProvider::Github => format!("{owner}/{repo}/blob/{sha}/{path}"),
GitHostingProvider::Gitlab => format!("{owner}/{repo}/-/blob/{sha}/{path}"), GitHostingProvider::Gitlab => format!("{owner}/{repo}/-/blob/{sha}/{path}"),
GitHostingProvider::Gitee => format!("{owner}/{repo}/blob/{sha}/{path}"), GitHostingProvider::Gitee => format!("{owner}/{repo}/blob/{sha}/{path}"),
GitHostingProvider::BitbucketCloud => format!("{owner}/{repo}/src/{sha}/{path}"), GitHostingProvider::Bitbucket => format!("{owner}/{repo}/src/{sha}/{path}"),
}; };
let line_fragment = selection.map(|selection| provider.line_fragment(&selection)); let line_fragment = selection.map(|selection| provider.line_fragment(&selection));
@ -133,7 +142,7 @@ fn parse_git_remote_url(url: &str) -> Option<ParsedGitRemote> {
.split_once("/")?; .split_once("/")?;
return Some(ParsedGitRemote { return Some(ParsedGitRemote {
provider: GitHostingProvider::BitbucketCloud, provider: GitHostingProvider::Bitbucket,
owner, owner,
repo, repo,
}); });
@ -148,12 +157,12 @@ mod tests {
#[test] #[test]
fn test_build_github_permalink_from_ssh_url() { fn test_build_github_permalink_from_ssh_url() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"git@github.com:zed-industries/zed.git", remote_url: "git@github.com:zed-industries/zed.git",
"e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7", sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
"crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
None, selection: None,
) })
.unwrap(); .unwrap();
let expected_url = "https://github.com/zed-industries/zed/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs"; let expected_url = "https://github.com/zed-industries/zed/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs";
@ -162,12 +171,12 @@ mod tests {
#[test] #[test]
fn test_build_github_permalink_from_ssh_url_single_line_selection() { fn test_build_github_permalink_from_ssh_url_single_line_selection() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"git@github.com:zed-industries/zed.git", remote_url: "git@github.com:zed-industries/zed.git",
"e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7", sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
"crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
Some(Point::new(6, 1)..Point::new(6, 10)), selection: Some(Point::new(6, 1)..Point::new(6, 10)),
) })
.unwrap(); .unwrap();
let expected_url = "https://github.com/zed-industries/zed/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs#L7"; let expected_url = "https://github.com/zed-industries/zed/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs#L7";
@ -176,12 +185,12 @@ mod tests {
#[test] #[test]
fn test_build_github_permalink_from_ssh_url_multi_line_selection() { fn test_build_github_permalink_from_ssh_url_multi_line_selection() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"git@github.com:zed-industries/zed.git", remote_url: "git@github.com:zed-industries/zed.git",
"e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7", sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
"crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
Some(Point::new(23, 1)..Point::new(47, 10)), selection: Some(Point::new(23, 1)..Point::new(47, 10)),
) })
.unwrap(); .unwrap();
let expected_url = "https://github.com/zed-industries/zed/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs#L24-L48"; let expected_url = "https://github.com/zed-industries/zed/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs#L24-L48";
@ -190,12 +199,12 @@ mod tests {
#[test] #[test]
fn test_build_github_permalink_from_https_url() { fn test_build_github_permalink_from_https_url() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"https://github.com/zed-industries/zed.git", remote_url: "https://github.com/zed-industries/zed.git",
"b2efec9824c45fcc90c9a7eb107a50d1772a60aa", sha: "b2efec9824c45fcc90c9a7eb107a50d1772a60aa",
"crates/zed/src/main.rs", path: "crates/zed/src/main.rs",
None, selection: None,
) })
.unwrap(); .unwrap();
let expected_url = "https://github.com/zed-industries/zed/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs"; let expected_url = "https://github.com/zed-industries/zed/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs";
@ -204,12 +213,12 @@ mod tests {
#[test] #[test]
fn test_build_github_permalink_from_https_url_single_line_selection() { fn test_build_github_permalink_from_https_url_single_line_selection() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"https://github.com/zed-industries/zed.git", remote_url: "https://github.com/zed-industries/zed.git",
"b2efec9824c45fcc90c9a7eb107a50d1772a60aa", sha: "b2efec9824c45fcc90c9a7eb107a50d1772a60aa",
"crates/zed/src/main.rs", path: "crates/zed/src/main.rs",
Some(Point::new(6, 1)..Point::new(6, 10)), selection: Some(Point::new(6, 1)..Point::new(6, 10)),
) })
.unwrap(); .unwrap();
let expected_url = "https://github.com/zed-industries/zed/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs#L7"; let expected_url = "https://github.com/zed-industries/zed/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs#L7";
@ -218,12 +227,12 @@ mod tests {
#[test] #[test]
fn test_build_github_permalink_from_https_url_multi_line_selection() { fn test_build_github_permalink_from_https_url_multi_line_selection() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"https://github.com/zed-industries/zed.git", remote_url: "https://github.com/zed-industries/zed.git",
"b2efec9824c45fcc90c9a7eb107a50d1772a60aa", sha: "b2efec9824c45fcc90c9a7eb107a50d1772a60aa",
"crates/zed/src/main.rs", path: "crates/zed/src/main.rs",
Some(Point::new(23, 1)..Point::new(47, 10)), selection: Some(Point::new(23, 1)..Point::new(47, 10)),
) })
.unwrap(); .unwrap();
let expected_url = "https://github.com/zed-industries/zed/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs#L24-L48"; let expected_url = "https://github.com/zed-industries/zed/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs#L24-L48";
@ -232,12 +241,12 @@ mod tests {
#[test] #[test]
fn test_build_gitlab_permalink_from_ssh_url() { fn test_build_gitlab_permalink_from_ssh_url() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"git@gitlab.com:zed-industries/zed.git", remote_url: "git@gitlab.com:zed-industries/zed.git",
"e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7", sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
"crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
None, selection: None,
) })
.unwrap(); .unwrap();
let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs"; let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs";
@ -246,12 +255,12 @@ mod tests {
#[test] #[test]
fn test_build_gitlab_permalink_from_ssh_url_single_line_selection() { fn test_build_gitlab_permalink_from_ssh_url_single_line_selection() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"git@gitlab.com:zed-industries/zed.git", remote_url: "git@gitlab.com:zed-industries/zed.git",
"e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7", sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
"crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
Some(Point::new(6, 1)..Point::new(6, 10)), selection: Some(Point::new(6, 1)..Point::new(6, 10)),
) })
.unwrap(); .unwrap();
let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs#L7"; let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs#L7";
@ -260,12 +269,12 @@ mod tests {
#[test] #[test]
fn test_build_gitlab_permalink_from_ssh_url_multi_line_selection() { fn test_build_gitlab_permalink_from_ssh_url_multi_line_selection() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"git@gitlab.com:zed-industries/zed.git", remote_url: "git@gitlab.com:zed-industries/zed.git",
"e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7", sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
"crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
Some(Point::new(23, 1)..Point::new(47, 10)), selection: Some(Point::new(23, 1)..Point::new(47, 10)),
) })
.unwrap(); .unwrap();
let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs#L24-48"; let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs#L24-48";
@ -274,12 +283,12 @@ mod tests {
#[test] #[test]
fn test_build_gitlab_permalink_from_https_url() { fn test_build_gitlab_permalink_from_https_url() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"https://gitlab.com/zed-industries/zed.git", remote_url: "https://gitlab.com/zed-industries/zed.git",
"b2efec9824c45fcc90c9a7eb107a50d1772a60aa", sha: "b2efec9824c45fcc90c9a7eb107a50d1772a60aa",
"crates/zed/src/main.rs", path: "crates/zed/src/main.rs",
None, selection: None,
) })
.unwrap(); .unwrap();
let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs"; let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs";
@ -288,12 +297,12 @@ mod tests {
#[test] #[test]
fn test_build_gitlab_permalink_from_https_url_single_line_selection() { fn test_build_gitlab_permalink_from_https_url_single_line_selection() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"https://gitlab.com/zed-industries/zed.git", remote_url: "https://gitlab.com/zed-industries/zed.git",
"b2efec9824c45fcc90c9a7eb107a50d1772a60aa", sha: "b2efec9824c45fcc90c9a7eb107a50d1772a60aa",
"crates/zed/src/main.rs", path: "crates/zed/src/main.rs",
Some(Point::new(6, 1)..Point::new(6, 10)), selection: Some(Point::new(6, 1)..Point::new(6, 10)),
) })
.unwrap(); .unwrap();
let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs#L7"; let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs#L7";
@ -302,12 +311,12 @@ mod tests {
#[test] #[test]
fn test_build_gitlab_permalink_from_https_url_multi_line_selection() { fn test_build_gitlab_permalink_from_https_url_multi_line_selection() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"https://gitlab.com/zed-industries/zed.git", remote_url: "https://gitlab.com/zed-industries/zed.git",
"b2efec9824c45fcc90c9a7eb107a50d1772a60aa", sha: "b2efec9824c45fcc90c9a7eb107a50d1772a60aa",
"crates/zed/src/main.rs", path: "crates/zed/src/main.rs",
Some(Point::new(23, 1)..Point::new(47, 10)), selection: Some(Point::new(23, 1)..Point::new(47, 10)),
) })
.unwrap(); .unwrap();
let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs#L24-48"; let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs#L24-48";
@ -316,12 +325,12 @@ mod tests {
#[test] #[test]
fn test_build_gitee_permalink_from_ssh_url() { fn test_build_gitee_permalink_from_ssh_url() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"git@gitee.com:libkitten/zed.git", remote_url: "git@gitee.com:libkitten/zed.git",
"e5fe811d7ad0fc26934edd76f891d20bdc3bb194", sha: "e5fe811d7ad0fc26934edd76f891d20bdc3bb194",
"crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
None, selection: None,
) })
.unwrap(); .unwrap();
let expected_url = "https://gitee.com/libkitten/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/editor/src/git/permalink.rs"; let expected_url = "https://gitee.com/libkitten/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/editor/src/git/permalink.rs";
@ -330,12 +339,12 @@ mod tests {
#[test] #[test]
fn test_build_gitee_permalink_from_ssh_url_single_line_selection() { fn test_build_gitee_permalink_from_ssh_url_single_line_selection() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"git@gitee.com:libkitten/zed.git", remote_url: "git@gitee.com:libkitten/zed.git",
"e5fe811d7ad0fc26934edd76f891d20bdc3bb194", sha: "e5fe811d7ad0fc26934edd76f891d20bdc3bb194",
"crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
Some(Point::new(6, 1)..Point::new(6, 10)), selection: Some(Point::new(6, 1)..Point::new(6, 10)),
) })
.unwrap(); .unwrap();
let expected_url = "https://gitee.com/libkitten/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/editor/src/git/permalink.rs#L7"; let expected_url = "https://gitee.com/libkitten/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/editor/src/git/permalink.rs#L7";
@ -344,12 +353,12 @@ mod tests {
#[test] #[test]
fn test_build_gitee_permalink_from_ssh_url_multi_line_selection() { fn test_build_gitee_permalink_from_ssh_url_multi_line_selection() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"git@gitee.com:libkitten/zed.git", remote_url: "git@gitee.com:libkitten/zed.git",
"e5fe811d7ad0fc26934edd76f891d20bdc3bb194", sha: "e5fe811d7ad0fc26934edd76f891d20bdc3bb194",
"crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
Some(Point::new(23, 1)..Point::new(47, 10)), selection: Some(Point::new(23, 1)..Point::new(47, 10)),
) })
.unwrap(); .unwrap();
let expected_url = "https://gitee.com/libkitten/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/editor/src/git/permalink.rs#L24-48"; let expected_url = "https://gitee.com/libkitten/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/editor/src/git/permalink.rs#L24-48";
@ -358,12 +367,12 @@ mod tests {
#[test] #[test]
fn test_build_gitee_permalink_from_https_url() { fn test_build_gitee_permalink_from_https_url() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"https://gitee.com/libkitten/zed.git", remote_url: "https://gitee.com/libkitten/zed.git",
"e5fe811d7ad0fc26934edd76f891d20bdc3bb194", sha: "e5fe811d7ad0fc26934edd76f891d20bdc3bb194",
"crates/zed/src/main.rs", path: "crates/zed/src/main.rs",
None, selection: None,
) })
.unwrap(); .unwrap();
let expected_url = "https://gitee.com/libkitten/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/zed/src/main.rs"; let expected_url = "https://gitee.com/libkitten/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/zed/src/main.rs";
@ -372,12 +381,12 @@ mod tests {
#[test] #[test]
fn test_build_gitee_permalink_from_https_url_single_line_selection() { fn test_build_gitee_permalink_from_https_url_single_line_selection() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"https://gitee.com/libkitten/zed.git", remote_url: "https://gitee.com/libkitten/zed.git",
"e5fe811d7ad0fc26934edd76f891d20bdc3bb194", sha: "e5fe811d7ad0fc26934edd76f891d20bdc3bb194",
"crates/zed/src/main.rs", path: "crates/zed/src/main.rs",
Some(Point::new(6, 1)..Point::new(6, 10)), selection: Some(Point::new(6, 1)..Point::new(6, 10)),
) })
.unwrap(); .unwrap();
let expected_url = "https://gitee.com/libkitten/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/zed/src/main.rs#L7"; let expected_url = "https://gitee.com/libkitten/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/zed/src/main.rs#L7";
@ -386,12 +395,12 @@ mod tests {
#[test] #[test]
fn test_build_gitee_permalink_from_https_url_multi_line_selection() { fn test_build_gitee_permalink_from_https_url_multi_line_selection() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"https://gitee.com/libkitten/zed.git", remote_url: "https://gitee.com/libkitten/zed.git",
"e5fe811d7ad0fc26934edd76f891d20bdc3bb194", sha: "e5fe811d7ad0fc26934edd76f891d20bdc3bb194",
"crates/zed/src/main.rs", path: "crates/zed/src/main.rs",
Some(Point::new(23, 1)..Point::new(47, 10)), selection: Some(Point::new(23, 1)..Point::new(47, 10)),
) })
.unwrap(); .unwrap();
let expected_url = "https://gitee.com/libkitten/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/zed/src/main.rs#L24-48"; let expected_url = "https://gitee.com/libkitten/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/zed/src/main.rs#L24-48";
assert_eq!(permalink.to_string(), expected_url.to_string()) assert_eq!(permalink.to_string(), expected_url.to_string())
@ -401,10 +410,7 @@ mod tests {
fn test_parse_git_remote_url_bitbucket_https_with_username() { fn test_parse_git_remote_url_bitbucket_https_with_username() {
let url = "https://thorstenballzed@bitbucket.org/thorstenzed/testingrepo.git"; let url = "https://thorstenballzed@bitbucket.org/thorstenzed/testingrepo.git";
let parsed = parse_git_remote_url(url).unwrap(); let parsed = parse_git_remote_url(url).unwrap();
assert!(matches!( assert!(matches!(parsed.provider, GitHostingProvider::Bitbucket));
parsed.provider,
GitHostingProvider::BitbucketCloud
));
assert_eq!(parsed.owner, "thorstenzed"); assert_eq!(parsed.owner, "thorstenzed");
assert_eq!(parsed.repo, "testingrepo"); assert_eq!(parsed.repo, "testingrepo");
} }
@ -413,10 +419,7 @@ mod tests {
fn test_parse_git_remote_url_bitbucket_https_without_username() { fn test_parse_git_remote_url_bitbucket_https_without_username() {
let url = "https://bitbucket.org/thorstenzed/testingrepo.git"; let url = "https://bitbucket.org/thorstenzed/testingrepo.git";
let parsed = parse_git_remote_url(url).unwrap(); let parsed = parse_git_remote_url(url).unwrap();
assert!(matches!( assert!(matches!(parsed.provider, GitHostingProvider::Bitbucket));
parsed.provider,
GitHostingProvider::BitbucketCloud
));
assert_eq!(parsed.owner, "thorstenzed"); assert_eq!(parsed.owner, "thorstenzed");
assert_eq!(parsed.repo, "testingrepo"); assert_eq!(parsed.repo, "testingrepo");
} }
@ -425,22 +428,19 @@ mod tests {
fn test_parse_git_remote_url_bitbucket_git() { fn test_parse_git_remote_url_bitbucket_git() {
let url = "git@bitbucket.org:thorstenzed/testingrepo.git"; let url = "git@bitbucket.org:thorstenzed/testingrepo.git";
let parsed = parse_git_remote_url(url).unwrap(); let parsed = parse_git_remote_url(url).unwrap();
assert!(matches!( assert!(matches!(parsed.provider, GitHostingProvider::Bitbucket));
parsed.provider,
GitHostingProvider::BitbucketCloud
));
assert_eq!(parsed.owner, "thorstenzed"); assert_eq!(parsed.owner, "thorstenzed");
assert_eq!(parsed.repo, "testingrepo"); assert_eq!(parsed.repo, "testingrepo");
} }
#[test] #[test]
fn test_build_bitbucket_permalink_from_ssh_url() { fn test_build_bitbucket_permalink_from_ssh_url() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"git@bitbucket.org:thorstenzed/testingrepo.git", remote_url: "git@bitbucket.org:thorstenzed/testingrepo.git",
"f00b4r", sha: "f00b4r",
"main.rs", path: "main.rs",
None, selection: None,
) })
.unwrap(); .unwrap();
let expected_url = "https://bitbucket.org/thorstenzed/testingrepo/src/f00b4r/main.rs"; let expected_url = "https://bitbucket.org/thorstenzed/testingrepo/src/f00b4r/main.rs";
@ -449,12 +449,12 @@ mod tests {
#[test] #[test]
fn test_build_bitbucket_permalink_from_ssh_url_single_line_selection() { fn test_build_bitbucket_permalink_from_ssh_url_single_line_selection() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"git@bitbucket.org:thorstenzed/testingrepo.git", remote_url: "git@bitbucket.org:thorstenzed/testingrepo.git",
"f00b4r", sha: "f00b4r",
"main.rs", path: "main.rs",
Some(Point::new(6, 1)..Point::new(6, 10)), selection: Some(Point::new(6, 1)..Point::new(6, 10)),
) })
.unwrap(); .unwrap();
let expected_url = let expected_url =
@ -464,12 +464,12 @@ mod tests {
#[test] #[test]
fn test_build_bitbucket_permalink_from_ssh_url_multi_line_selection() { fn test_build_bitbucket_permalink_from_ssh_url_multi_line_selection() {
let permalink = build_permalink( let permalink = build_permalink(BuildPermalinkParams {
"git@bitbucket.org:thorstenzed/testingrepo.git", remote_url: "git@bitbucket.org:thorstenzed/testingrepo.git",
"f00b4r", sha: "f00b4r",
"main.rs", path: "main.rs",
Some(Point::new(23, 1)..Point::new(47, 10)), selection: Some(Point::new(23, 1)..Point::new(47, 10)),
) })
.unwrap(); .unwrap();
let expected_url = let expected_url =