Impl GhApiClient and use it in cargo-binstall to speedup resolution process (#832)

Fixed #776

 - Add new feature gh-api-client to binstalk-downloader
 - Impl new type `binstalk_downloader::remote::{RequestBuilder, Response}`
 - Impl `binstalk_downloader::gh_api_client::GhApiClient`, exposed if `cfg(feature = "gh-api-client")` and add e2e and unit tests for it
 - Use `binstalk_downloader::gh_api_client::GhApiClient` to speedup `cargo-binstall`
 - Add new option `--github-token` to supply the token for GitHub restful API, or read from env variable `GITHUB_TOKEN` if not present.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2023-03-02 12:04:22 +11:00 committed by GitHub
parent 263c836757
commit 599bcaf333
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 960 additions and 192 deletions

View file

@ -6,6 +6,7 @@ use std::{
use binstalk_downloader::{
download::{DownloadError, ZipError},
gh_api_client::GhApiError,
remote::{Error as RemoteError, HttpError, ReqwestError},
};
use cargo_toml::Error as CargoTomlError;
@ -309,6 +310,14 @@ pub enum BinstallError {
#[diagnostic(severity(error), code(binstall::invalid_pkg_fmt))]
InvalidPkgFmt(Box<InvalidPkgFmtError>),
/// Request to GitHub Restful API failed
///
/// - Code: `binstall::gh_restful_api_failure`
/// - Exit: 96
#[error("Request to GitHub Restful API failed: {0}")]
#[diagnostic(severity(error), code(binstall::gh_restful_api_failure))]
GhApiErr(#[source] Box<GhApiError>),
/// A wrapped error providing the context of which crate the error is about.
#[error(transparent)]
#[diagnostic(transparent)]
@ -343,6 +352,7 @@ impl BinstallError {
EmptySourceFilePath => 92,
NoFallbackToCargoInstall => 94,
InvalidPkgFmt(..) => 95,
GhApiErr(..) => 96,
CrateContext(context) => context.err.exit_number(),
};
@ -453,3 +463,9 @@ impl From<InvalidPkgFmtError> for BinstallError {
BinstallError::InvalidPkgFmt(Box::new(e))
}
}
impl From<GhApiError> for BinstallError {
fn from(e: GhApiError) -> Self {
BinstallError::GhApiErr(Box::new(e))
}
}