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 3 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
6 changes: 6 additions & 0 deletions 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 @@ -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"
);
}
}
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 @@ async fn refresh_repositories_for_provider(
.strip_prefix("git://")
.map(|url| format!("https://{url}"))
.unwrap_or(url);
let url = url.strip_suffix(".git").unwrap_or(&url);

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(),
)
.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 @@ async fn refresh_repositories_for_provider(
};
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);

service
.upsert_gitlab_provided_repository(
provider.id.clone(),
id,
repo.name,
repo.http_url_to_repo,
repo.name_with_namespace,
url.to_string(),
)
.await?;
}
Expand All @@ -71,7 +73,7 @@ async fn refresh_repositories_for_provider(
#[derive(Deserialize)]
struct Repository {
id: u128,
name: String,
name_with_namespace: String,
http_url_to_repo: String,
}

Expand Down
Loading