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 <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2024-07-15 00:28:26 +10:00
parent 01a09141be
commit e0521e25ff
No known key found for this signature in database
GPG key ID: 76D1E687CA3C4928

View file

@ -205,16 +205,13 @@ impl Data {
repo: &str,
client: &GhApiClient,
) -> Result<RepoInfo, FetchError> {
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);