Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(webserver): use full name for repositories and strip .git from urls #1978

Merged
merged 5 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/tabby-common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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"
);
}
}
2 changes: 1 addition & 1 deletion crates/tabby/src/services/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
8 changes: 7 additions & 1 deletion ee/tabby-webserver/src/cron/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@
.strip_prefix("git://")
.map(|url| format!("https://{url}"))
.unwrap_or(url);
let url = url.strip_suffix(".git").unwrap_or(&url);

Check warning on line 64 in ee/tabby-webserver/src/cron/github.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/github.rs#L64

Added line #L64 was not covered by tests

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(),
)

Check warning on line 72 in ee/tabby-webserver/src/cron/github.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/github.rs#L67-L72

Added lines #L67 - L72 were not covered by tests
.await?;
}

Expand Down
8 changes: 5 additions & 3 deletions ee/tabby-webserver/src/cron/gitlab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@
};
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);

Check warning on line 58 in ee/tabby-webserver/src/cron/gitlab.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/gitlab.rs#L57-L58

Added lines #L57 - L58 were not covered by tests

service
.upsert_gitlab_provided_repository(
provider.id.clone(),
id,
repo.name,
repo.http_url_to_repo,
repo.name_with_namespace,
url.to_string(),

Check warning on line 65 in ee/tabby-webserver/src/cron/gitlab.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/gitlab.rs#L64-L65

Added lines #L64 - L65 were not covered by tests
)
.await?;
}
Expand All @@ -71,7 +73,7 @@
#[derive(Deserialize)]
struct Repository {
id: u128,
name: String,
name_with_namespace: String,
http_url_to_repo: String,
}

Expand Down
Loading