mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-24 22:30:03 +00:00
Support private github repository (#1690)
* Refactor: Create new crate binstalk-git-repo-api Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix CI lint warnings Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix `just check`: Rm deleted features from `cargo-hack` check Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Refactor: Extract new mod error Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Ret artifact url in `has_release_artifact` So that we can use it to download from private repositories. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Move `test_graph_ql_error_type` to mod `error` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix running `cargo test` in `binstalk-git-repo-api`` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Remove unnecessary import in mod `error::test` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Rename mod `request`` to `release_artifacts` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Impl draft version of fetching repo info Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Refactor: Move `HasReleaseArtifacts` failure variants into `GhApiError` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Refactor: Use `GhRepo` in `GhRelease` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix testing Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Refactor: Return `'static` future Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Refactor: Make sure `'static` Future is returned To make it easier to create generic function Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add logging to unit testing Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix unit testing Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Refactor: Extract new fn `GhApiClient::do_fetch` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Rm unused `percent_encode_http_url_path` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix `cargo test` run on CI `cargo test` run all tests in one process. As such, `set_global_default` would fail on the second call. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Optimize `GhApiClient::do_fetch`: Avoid unnecessary restful API call Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Refactor: Rm param `auth_token` for restful API fn which is always set to `None` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Impl new API `GhApiClient::get_repo_info` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix unit test for `GhApiClient::get_repo_info` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Refactor testing: Parameter-ize testing Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Parallelise `test_get_repo_info` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Refactor: Create parameter-ised `test_has_release_artifact` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Parallelize `test_has_release_artifact` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Refactor: `gh_api_client::test::create_client` shall not be `async` as there is no `.await` in it. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Return `Url` in `GhApiClient::has_release_artifact` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Impl new API `GhApiClient::download_artifact` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Remove unused deps added to binstalk-git-repo-api Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix clippy lints Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add new API `GhApiClient::remote_client` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add `GhApiClient::has_gh_token` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add `GhRepo::try_extract_from_url` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Rename `ReleaseArtifactUrl` to `GhReleaseArtifactUrl` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add new fn `Download::with_data_verifier` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * feature: Support private repository Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix clippy lints Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add e2e-test/private-github-repo Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix clippy lints Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix `launch_baseline_find_tasks`: Retry on rate limit Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix test failure: Retry on rate limit Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Temporarily enable debug output for e2e-test-private-github-repo Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix `get_repo_info`: Retry on rate limit Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Improve `debug!` logging Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add more debug logging Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add more debugging Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add more debug logging Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Apply suggestions from code review * Fix compilation Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix cargo fmt Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add crate binstalk-git-repo-api to release-pr.yml * Update crates/binstalk-git-repo-api/Cargo.toml * Apply suggestions from code review * Update crates/binstalk/Cargo.toml --------- Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
48ee0b0e3e
commit
1dbd2460a3
30 changed files with 1838 additions and 1127 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::{fmt, io, marker::PhantomData, path::Path};
|
||||
use std::{fmt, io, path::Path};
|
||||
|
||||
use binstalk_types::cargo_toml_binstall::PkgFmtDecomposed;
|
||||
use bytes::Bytes;
|
||||
|
@ -8,7 +8,7 @@ use tracing::{debug, error, instrument};
|
|||
|
||||
pub use binstalk_types::cargo_toml_binstall::{PkgFmt, TarBasedFmt};
|
||||
|
||||
use crate::remote::{Client, Error as RemoteError, Url};
|
||||
use crate::remote::{Client, Error as RemoteError, Response, Url};
|
||||
|
||||
mod async_extracter;
|
||||
use async_extracter::*;
|
||||
|
@ -90,38 +90,43 @@ impl DataVerifier for () {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum DownloadContent {
|
||||
ToIssue { client: Client, url: Url },
|
||||
Response(Response),
|
||||
}
|
||||
|
||||
impl DownloadContent {
|
||||
async fn into_response(self) -> Result<Response, DownloadError> {
|
||||
Ok(match self {
|
||||
DownloadContent::ToIssue { client, url } => client.get(url).send(true).await?,
|
||||
DownloadContent::Response(response) => response,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Download<'a> {
|
||||
client: Client,
|
||||
url: Url,
|
||||
content: DownloadContent,
|
||||
data_verifier: Option<&'a mut dyn DataVerifier>,
|
||||
}
|
||||
|
||||
impl fmt::Debug for Download<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
#[allow(dead_code, clippy::type_complexity)]
|
||||
#[derive(Debug)]
|
||||
struct Download<'a> {
|
||||
client: &'a Client,
|
||||
url: &'a Url,
|
||||
data_verifier: Option<PhantomData<&'a mut dyn DataVerifier>>,
|
||||
}
|
||||
|
||||
fmt::Debug::fmt(
|
||||
&Download {
|
||||
client: &self.client,
|
||||
url: &self.url,
|
||||
data_verifier: self.data_verifier.as_ref().map(|_| PhantomData),
|
||||
},
|
||||
f,
|
||||
)
|
||||
fmt::Debug::fmt(&self.content, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Download<'static> {
|
||||
pub fn new(client: Client, url: Url) -> Self {
|
||||
Self {
|
||||
client,
|
||||
url,
|
||||
content: DownloadContent::ToIssue { client, url },
|
||||
data_verifier: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_response(response: Response) -> Self {
|
||||
Self {
|
||||
content: DownloadContent::Response(response),
|
||||
data_verifier: None,
|
||||
}
|
||||
}
|
||||
|
@ -134,8 +139,24 @@ impl<'a> Download<'a> {
|
|||
data_verifier: &'a mut dyn DataVerifier,
|
||||
) -> Self {
|
||||
Self {
|
||||
client,
|
||||
url,
|
||||
content: DownloadContent::ToIssue { client, url },
|
||||
data_verifier: Some(data_verifier),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_response_with_data_verifier(
|
||||
response: Response,
|
||||
data_verifier: &'a mut dyn DataVerifier,
|
||||
) -> Self {
|
||||
Self {
|
||||
content: DownloadContent::Response(response),
|
||||
data_verifier: Some(data_verifier),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_data_verifier(self, data_verifier: &mut dyn DataVerifier) -> Download<'_> {
|
||||
Download {
|
||||
content: self.content,
|
||||
data_verifier: Some(data_verifier),
|
||||
}
|
||||
}
|
||||
|
@ -148,9 +169,10 @@ impl<'a> Download<'a> {
|
|||
> {
|
||||
let mut data_verifier = self.data_verifier;
|
||||
Ok(self
|
||||
.client
|
||||
.get_stream(self.url)
|
||||
.content
|
||||
.into_response()
|
||||
.await?
|
||||
.bytes_stream()
|
||||
.map(move |res| {
|
||||
let bytes = res?;
|
||||
|
||||
|
@ -257,7 +279,7 @@ impl Download<'_> {
|
|||
|
||||
#[instrument]
|
||||
pub async fn into_bytes(self) -> Result<Bytes, DownloadError> {
|
||||
let bytes = self.client.get(self.url).send(true).await?.bytes().await?;
|
||||
let bytes = self.content.into_response().await?.bytes().await?;
|
||||
if let Some(verifier) = self.data_verifier {
|
||||
verifier.update(&bytes);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue