mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-16 07:36:38 +00:00
Refactor Data::get_repo_info
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
7eca355cc3
commit
1384623f63
1 changed files with 67 additions and 61 deletions
|
@ -185,13 +185,10 @@ impl Data {
|
||||||
|
|
||||||
#[instrument(skip(client))]
|
#[instrument(skip(client))]
|
||||||
async fn get_repo_info(&self, client: &GhApiClient) -> Result<Option<&RepoInfo>, FetchError> {
|
async fn get_repo_info(&self, client: &GhApiClient) -> Result<Option<&RepoInfo>, FetchError> {
|
||||||
self.repo_info
|
async fn get_repo_info_inner(
|
||||||
.get_or_try_init(move || {
|
repo: &str,
|
||||||
Box::pin(async move {
|
client: &GhApiClient,
|
||||||
let Some(repo) = self.repo.as_deref() else {
|
) -> Result<RepoInfo, FetchError> {
|
||||||
return Ok(None);
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut repo = Url::parse(repo)?;
|
let mut repo = Url::parse(repo)?;
|
||||||
let mut repository_host = RepositoryHost::guess_git_hosting_services(&repo);
|
let mut repository_host = RepositoryHost::guess_git_hosting_services(&repo);
|
||||||
|
|
||||||
|
@ -233,10 +230,7 @@ impl Data {
|
||||||
}
|
}
|
||||||
Ok(None) => return Err(GhApiError::NotFound.into()),
|
Ok(None) => return Err(GhApiError::NotFound.into()),
|
||||||
Err(GhApiError::RateLimit { retry_after }) => {
|
Err(GhApiError::RateLimit { retry_after }) => {
|
||||||
sleep(
|
sleep(retry_after.unwrap_or(DEFAULT_GH_API_RETRY_DURATION))
|
||||||
retry_after
|
|
||||||
.unwrap_or(DEFAULT_GH_API_RETRY_DURATION),
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
Err(err) => return Err(err.into()),
|
Err(err) => return Err(err.into()),
|
||||||
|
@ -246,16 +240,28 @@ impl Data {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let repo_info = RepoInfo {
|
Ok(RepoInfo {
|
||||||
subcrate,
|
subcrate,
|
||||||
repo,
|
repo,
|
||||||
repository_host,
|
repository_host,
|
||||||
is_private,
|
is_private,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
self.repo_info
|
||||||
|
.get_or_try_init(move || {
|
||||||
|
Box::pin(async move {
|
||||||
|
let Some(repo) = self.repo.as_deref() else {
|
||||||
|
return Ok(None);
|
||||||
};
|
};
|
||||||
|
|
||||||
debug!("Resolved repo_info = {repo_info:#?}");
|
let ret = get_repo_info_inner(repo, client).await;
|
||||||
|
|
||||||
Ok(Some(repo_info))
|
if let Ok(repo_info) = &ret {
|
||||||
|
debug!("Resolved repo_info = {repo_info:#?}");
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.map(Some)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue