From f824ebbd9c7b4f4752def0822cb452dd79864b5f Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Tue, 28 May 2024 23:12:02 +1000 Subject: [PATCH] Refactor: Rm param `auth_token` for restful API fn which is always set to `None` Signed-off-by: Jiahao XU --- crates/binstalk-git-repo-api/src/gh_api_client.rs | 4 ++-- .../src/gh_api_client/common.rs | 12 +++--------- .../src/gh_api_client/release_artifacts.rs | 2 -- .../src/gh_api_client/repo_info.rs | 3 +-- 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/crates/binstalk-git-repo-api/src/gh_api_client.rs b/crates/binstalk-git-repo-api/src/gh_api_client.rs index a9cb8ecf..e265ae81 100644 --- a/crates/binstalk-git-repo-api/src/gh_api_client.rs +++ b/crates/binstalk-git-repo-api/src/gh_api_client.rs @@ -166,7 +166,7 @@ impl GhApiClient { ) -> Result where GraphQLFn: Fn(&remote::Client, &T, &str) -> GraphQLFut, - RestfulFn: Fn(&remote::Client, &T, Option<&str>) -> RestfulFut, + RestfulFn: Fn(&remote::Client, &T) -> RestfulFut, GraphQLFut: Future> + Send + Sync + 'static, RestfulFut: Future> + Send + Sync + 'static, { @@ -181,7 +181,7 @@ impl GhApiClient { } } - restful_func(&self.0.client, data, None) + restful_func(&self.0.client, data) .await .map_err(|err| err.context("Restful API")) } diff --git a/crates/binstalk-git-repo-api/src/gh_api_client/common.rs b/crates/binstalk-git-repo-api/src/gh_api_client/common.rs index 091be43d..4e2a5e63 100644 --- a/crates/binstalk-git-repo-api/src/gh_api_client/common.rs +++ b/crates/binstalk-git-repo-api/src/gh_api_client/common.rs @@ -52,7 +52,6 @@ fn get_api_endpoint() -> &'static Url { pub(super) fn issue_restful_api( client: &remote::Client, path: &[&str], - auth_token: Option<&str>, ) -> impl Future> + Send + Sync + 'static where T: DeserializeOwned, @@ -65,16 +64,11 @@ where debug!("Getting restful API: {url}"); - let mut request_builder = client + let future = client .get(url) .header("Accept", "application/vnd.github+json") - .header("X-GitHub-Api-Version", "2022-11-28"); - - if let Some(auth_token) = auth_token { - request_builder = request_builder.bearer_auth(&auth_token); - } - - let future = request_builder.send(false); + .header("X-GitHub-Api-Version", "2022-11-28") + .send(false); async move { let response = future.await?; diff --git a/crates/binstalk-git-repo-api/src/gh_api_client/release_artifacts.rs b/crates/binstalk-git-repo-api/src/gh_api_client/release_artifacts.rs index 5855f57c..4ff33684 100644 --- a/crates/binstalk-git-repo-api/src/gh_api_client/release_artifacts.rs +++ b/crates/binstalk-git-repo-api/src/gh_api_client/release_artifacts.rs @@ -72,7 +72,6 @@ pub(super) fn fetch_release_artifacts_restful_api( repo: GhRepo { owner, repo }, tag, }: &GhRelease, - auth_token: Option<&str>, ) -> impl Future> + Send + Sync + 'static { issue_restful_api( client, @@ -80,7 +79,6 @@ pub(super) fn fetch_release_artifacts_restful_api( "repos", owner, repo, "releases", "tags", tag, //&percent_encode_http_url_path(tag).to_compact_string(), ], - auth_token, ) } diff --git a/crates/binstalk-git-repo-api/src/gh_api_client/repo_info.rs b/crates/binstalk-git-repo-api/src/gh_api_client/repo_info.rs index 51c00bc7..4aa6bbe7 100644 --- a/crates/binstalk-git-repo-api/src/gh_api_client/repo_info.rs +++ b/crates/binstalk-git-repo-api/src/gh_api_client/repo_info.rs @@ -34,9 +34,8 @@ impl RepoInfo { pub(super) async fn fetch_repo_info_restful_api( client: &remote::Client, GhRepo { owner, repo }: &GhRepo, - auth_token: Option<&str>, ) -> Result { - issue_restful_api(client, &["repos", owner, repo], auth_token).await + issue_restful_api(client, &["repos", owner, repo]).await } #[derive(Deserialize)]