mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-17 08:06:38 +00:00
Refactor: Rm param auth_token
for restful API fn
which is always set to `None` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
fc0222881c
commit
f824ebbd9c
4 changed files with 6 additions and 15 deletions
|
@ -166,7 +166,7 @@ impl GhApiClient {
|
||||||
) -> Result<U, GhApiError>
|
) -> Result<U, GhApiError>
|
||||||
where
|
where
|
||||||
GraphQLFn: Fn(&remote::Client, &T, &str) -> GraphQLFut,
|
GraphQLFn: Fn(&remote::Client, &T, &str) -> GraphQLFut,
|
||||||
RestfulFn: Fn(&remote::Client, &T, Option<&str>) -> RestfulFut,
|
RestfulFn: Fn(&remote::Client, &T) -> RestfulFut,
|
||||||
GraphQLFut: Future<Output = Result<U, GhApiError>> + Send + Sync + 'static,
|
GraphQLFut: Future<Output = Result<U, GhApiError>> + Send + Sync + 'static,
|
||||||
RestfulFut: Future<Output = Result<U, GhApiError>> + Send + Sync + 'static,
|
RestfulFut: Future<Output = Result<U, GhApiError>> + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
|
@ -181,7 +181,7 @@ impl GhApiClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
restful_func(&self.0.client, data, None)
|
restful_func(&self.0.client, data)
|
||||||
.await
|
.await
|
||||||
.map_err(|err| err.context("Restful API"))
|
.map_err(|err| err.context("Restful API"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,6 @@ fn get_api_endpoint() -> &'static Url {
|
||||||
pub(super) fn issue_restful_api<T>(
|
pub(super) fn issue_restful_api<T>(
|
||||||
client: &remote::Client,
|
client: &remote::Client,
|
||||||
path: &[&str],
|
path: &[&str],
|
||||||
auth_token: Option<&str>,
|
|
||||||
) -> impl Future<Output = Result<T, GhApiError>> + Send + Sync + 'static
|
) -> impl Future<Output = Result<T, GhApiError>> + Send + Sync + 'static
|
||||||
where
|
where
|
||||||
T: DeserializeOwned,
|
T: DeserializeOwned,
|
||||||
|
@ -65,16 +64,11 @@ where
|
||||||
|
|
||||||
debug!("Getting restful API: {url}");
|
debug!("Getting restful API: {url}");
|
||||||
|
|
||||||
let mut request_builder = client
|
let future = client
|
||||||
.get(url)
|
.get(url)
|
||||||
.header("Accept", "application/vnd.github+json")
|
.header("Accept", "application/vnd.github+json")
|
||||||
.header("X-GitHub-Api-Version", "2022-11-28");
|
.header("X-GitHub-Api-Version", "2022-11-28")
|
||||||
|
.send(false);
|
||||||
if let Some(auth_token) = auth_token {
|
|
||||||
request_builder = request_builder.bearer_auth(&auth_token);
|
|
||||||
}
|
|
||||||
|
|
||||||
let future = request_builder.send(false);
|
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let response = future.await?;
|
let response = future.await?;
|
||||||
|
|
|
@ -72,7 +72,6 @@ pub(super) fn fetch_release_artifacts_restful_api(
|
||||||
repo: GhRepo { owner, repo },
|
repo: GhRepo { owner, repo },
|
||||||
tag,
|
tag,
|
||||||
}: &GhRelease,
|
}: &GhRelease,
|
||||||
auth_token: Option<&str>,
|
|
||||||
) -> impl Future<Output = Result<Artifacts, GhApiError>> + Send + Sync + 'static {
|
) -> impl Future<Output = Result<Artifacts, GhApiError>> + Send + Sync + 'static {
|
||||||
issue_restful_api(
|
issue_restful_api(
|
||||||
client,
|
client,
|
||||||
|
@ -80,7 +79,6 @@ pub(super) fn fetch_release_artifacts_restful_api(
|
||||||
"repos", owner, repo, "releases", "tags",
|
"repos", owner, repo, "releases", "tags",
|
||||||
tag, //&percent_encode_http_url_path(tag).to_compact_string(),
|
tag, //&percent_encode_http_url_path(tag).to_compact_string(),
|
||||||
],
|
],
|
||||||
auth_token,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,9 +34,8 @@ impl RepoInfo {
|
||||||
pub(super) async fn fetch_repo_info_restful_api(
|
pub(super) async fn fetch_repo_info_restful_api(
|
||||||
client: &remote::Client,
|
client: &remote::Client,
|
||||||
GhRepo { owner, repo }: &GhRepo,
|
GhRepo { owner, repo }: &GhRepo,
|
||||||
auth_token: Option<&str>,
|
|
||||||
) -> Result<RepoInfo, GhApiError> {
|
) -> Result<RepoInfo, GhApiError> {
|
||||||
issue_restful_api(client, &["repos", owner, repo], auth_token).await
|
issue_restful_api(client, &["repos", owner, repo]).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue