Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support private github repository #1690

Merged
merged 58 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
9efe395
Refactor: Create new crate binstalk-git-repo-api
NobodyXu May 5, 2024
90670a6
Fix CI lint warnings
NobodyXu May 5, 2024
8bda7ea
Fix `just check`: Rm deleted features from `cargo-hack` check
NobodyXu May 5, 2024
d2914cc
Refactor: Extract new mod error
NobodyXu May 6, 2024
0708f6f
Ret artifact url in `has_release_artifact`
NobodyXu May 6, 2024
30a4a53
Move `test_graph_ql_error_type` to mod `error`
NobodyXu May 7, 2024
e06ea36
Fix running `cargo test` in `binstalk-git-repo-api``
NobodyXu May 7, 2024
645a2f2
Remove unnecessary import in mod `error::test`
NobodyXu May 7, 2024
6c67c7d
Rename mod `request`` to `release_artifacts`
NobodyXu May 7, 2024
5417475
Impl draft version of fetching repo info
NobodyXu May 8, 2024
7bd8468
Refactor: Move `HasReleaseArtifacts` failure variants into `GhApiError`
NobodyXu May 9, 2024
6e6d7d7
Refactor: Use `GhRepo` in `GhRelease`
NobodyXu May 9, 2024
f9008d7
Fix testing
NobodyXu May 9, 2024
f90eea4
Refactor: Return `'static` future
NobodyXu May 15, 2024
c36145f
Merge branch 'main' into feat/private-github-repo
NobodyXu May 25, 2024
cb418fd
Refactor: Make sure `'static` Future is returned
NobodyXu May 27, 2024
fd5b78c
Add logging to unit testing
NobodyXu May 27, 2024
361aca4
Fix unit testing
NobodyXu May 27, 2024
1350ac3
Refactor: Extract new fn `GhApiClient::do_fetch`
NobodyXu May 27, 2024
ffe47d3
Rm unused `percent_encode_http_url_path`
NobodyXu May 27, 2024
962a7d0
Fix `cargo test` run on CI
NobodyXu May 28, 2024
fc02228
Optimize `GhApiClient::do_fetch`: Avoid unnecessary restful API call
NobodyXu May 28, 2024
f824ebb
Refactor: Rm param `auth_token` for restful API fn
NobodyXu May 28, 2024
0bc4231
Impl new API `GhApiClient::get_repo_info`
NobodyXu May 28, 2024
7e4020f
Fix unit test for `GhApiClient::get_repo_info`
NobodyXu May 29, 2024
5f138e6
Refactor testing: Parameter-ize testing
NobodyXu May 29, 2024
345255a
Parallelise `test_get_repo_info`
NobodyXu May 29, 2024
4ffaf8c
Refactor: Create parameter-ised `test_has_release_artifact`
NobodyXu May 29, 2024
9f3156c
Parallelize `test_has_release_artifact`
NobodyXu May 29, 2024
eb77ad7
Refactor: `gh_api_client::test::create_client` shall not be `async`
NobodyXu May 29, 2024
4da2f0e
Return `Url` in `GhApiClient::has_release_artifact`
NobodyXu Jun 3, 2024
03ae2b7
Impl new API `GhApiClient::download_artifact`
NobodyXu Jun 3, 2024
54f88e0
Remove unused deps added to binstalk-git-repo-api
NobodyXu Jun 3, 2024
1ad2d0a
Fix clippy lints
NobodyXu Jun 3, 2024
6b0f460
Add new API `GhApiClient::remote_client`
NobodyXu Jun 4, 2024
7e283cc
Add `GhApiClient::has_gh_token`
NobodyXu Jun 4, 2024
81bdc3b
Add `GhRepo::try_extract_from_url`
NobodyXu Jun 4, 2024
3cee8a9
Rename `ReleaseArtifactUrl` to `GhReleaseArtifactUrl`
NobodyXu Jun 4, 2024
c19fcb6
Add new fn `Download::with_data_verifier`
NobodyXu Jun 4, 2024
0838118
feature: Support private repository
NobodyXu Jun 4, 2024
fba7e01
Fix clippy lints
NobodyXu Jun 5, 2024
be3aeca
Add e2e-test/private-github-repo
NobodyXu Jun 5, 2024
53b3c02
Fix clippy lints
NobodyXu Jun 5, 2024
6b3e384
Fix `launch_baseline_find_tasks`: Retry on rate limit
NobodyXu Jun 5, 2024
c9fb2f4
Fix test failure: Retry on rate limit
NobodyXu Jun 5, 2024
d1aa727
Temporarily enable debug output for e2e-test-private-github-repo
NobodyXu Jun 5, 2024
bc71a1b
Fix `get_repo_info`: Retry on rate limit
NobodyXu Jun 6, 2024
a295fe9
Improve `debug!` logging
NobodyXu Jun 6, 2024
e02321e
Add more debug logging
NobodyXu Jun 6, 2024
23a1bed
Add more debugging
NobodyXu Jun 6, 2024
a236f53
Add more debug logging
NobodyXu Jun 9, 2024
d118412
Apply suggestions from code review
NobodyXu Jun 9, 2024
25b216c
Fix compilation
NobodyXu Jun 9, 2024
2b19b9a
Fix cargo fmt
NobodyXu Jun 9, 2024
567381e
Add crate binstalk-git-repo-api to release-pr.yml
NobodyXu Jun 10, 2024
c4f03a8
Update crates/binstalk-git-repo-api/Cargo.toml
NobodyXu Jun 10, 2024
ffa2c2c
Apply suggestions from code review
NobodyXu Jun 10, 2024
1619656
Update crates/binstalk/Cargo.toml
NobodyXu Jun 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- binstalk
- binstalk-bins
- binstalk-fetchers
- binstalk-git-repo-api
- binstalk-registry
- binstalk-manifests
- binstalk-types
Expand Down
23 changes: 21 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ members = [
"crates/fs-lock",
"crates/normalize-path",
"crates/detect-targets",
"crates/binstalk-git-repo-api",
]

[profile.release]
Expand Down
3 changes: 0 additions & 3 deletions crates/binstalk-downloader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ reqwest = { version = "0.12.4", features = [
"brotli",
"deflate",
], default-features = false }
percent-encoding = "2.2.0"
serde = { version = "1.0.163", features = ["derive"], optional = true }
serde-tuple-vec-map = "1.0.1"
serde_json = { version = "1.0.107", optional = true }
# Use a fork here since we need PAX support, but the upstream
# does not hav the PR merged yet.
Expand Down Expand Up @@ -127,7 +125,6 @@ zstd-thin = ["zstd/thin"]

cross-lang-fat-lto = ["zstd/fat-lto"]

gh-api-client = ["json"]
json = ["serde", "serde_json"]

[target."cfg(windows)".dependencies]
Expand Down
76 changes: 49 additions & 27 deletions crates/binstalk-downloader/src/download.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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::*;
Expand Down Expand Up @@ -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,
}
}
Expand All @@ -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),
}
}
Expand All @@ -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?;

Expand Down Expand Up @@ -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);
}
Expand Down
Loading
Loading