From e0521e25ff20adae8ad4d6cc90b81a48063259fe Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Mon, 15 Jul 2024 00:28:26 +1000 Subject: [PATCH] Always try geting the redirected url This would help: - redirect public gh repo `.git` to its canonical form - redirect public gh repo, which has been recently renamed - cases where redirection is needed to get the real repo This commit make it fallbacks to the previou surl, if getting the redirected url fail, in case the repository is private. Signed-off-by: Jiahao XU --- crates/binstalk-fetchers/src/lib.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/crates/binstalk-fetchers/src/lib.rs b/crates/binstalk-fetchers/src/lib.rs index f504aa80..ff46f32d 100644 --- a/crates/binstalk-fetchers/src/lib.rs +++ b/crates/binstalk-fetchers/src/lib.rs @@ -205,16 +205,13 @@ impl Data { repo: &str, client: &GhApiClient, ) -> Result { - let mut repo = Url::parse(repo)?; - let mut repository_host = RepositoryHost::guess_git_hosting_services(&repo); - - if repository_host == RepositoryHost::Unknown { - repo = client - .remote_client() - .get_redirected_final_url(repo) - .await?; - repository_host = RepositoryHost::guess_git_hosting_services(&repo); - } + let repo = Url::parse(repo)?; + let mut repo = client + .remote_client() + .get_redirected_final_url(repo.clone()) + .await + .unwrap_or(repo); + let repository_host = RepositoryHost::guess_git_hosting_services(&repo); let subcrate = RepoInfo::detect_subcrate(&mut repo, repository_host);