summaryrefslogtreecommitdiff
path: root/cli/tools/registry/api.rs
diff options
context:
space:
mode:
authorBartek Iwańczuk <biwanczuk@gmail.com>2023-12-15 11:27:10 +0100
committerGitHub <noreply@github.com>2023-12-15 10:27:10 +0000
commit62e3f5060ef9cc6a31b3e496dd15548c0abd07e6 (patch)
treee03148c86caebe8b23a8d5f04f9df9357769f7fb /cli/tools/registry/api.rs
parenta1870c70a1adcd58798541aa965c915afa6f6c89 (diff)
refactor: check if scope and package exist before publish (#21575)
Signed-off-by: Bartek Iwańczuk <biwanczuk@gmail.com> Co-authored-by: Luca Casonato <lucacasonato@yahoo.com>
Diffstat (limited to 'cli/tools/registry/api.rs')
-rw-r--r--cli/tools/registry/api.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/cli/tools/registry/api.rs b/cli/tools/registry/api.rs
index b174ea367..2c08ef52d 100644
--- a/cli/tools/registry/api.rs
+++ b/cli/tools/registry/api.rs
@@ -1,5 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+use deno_core::error::AnyError;
use deno_core::serde_json;
use deno_runtime::deno_fetch::reqwest;
use serde::de::DeserializeOwned;
@@ -108,3 +109,32 @@ pub async fn parse_response<T: DeserializeOwned>(
x_deno_ray,
})
}
+
+pub async fn get_scope(
+ client: &reqwest::Client,
+ registry_api_url: &str,
+ scope: &str,
+) -> Result<reqwest::Response, AnyError> {
+ let scope_url = format!("{}scope/{}", registry_api_url, scope);
+ let response = client.get(&scope_url).send().await?;
+ Ok(response)
+}
+
+pub fn get_package_api_url(
+ registry_api_url: &str,
+ scope: &str,
+ package: &str,
+) -> String {
+ format!("{}scope/{}packages/{}", registry_api_url, scope, package)
+}
+
+pub async fn get_package(
+ client: &reqwest::Client,
+ registry_api_url: &str,
+ scope: &str,
+ package: &str,
+) -> Result<reqwest::Response, AnyError> {
+ let package_url = get_package_api_url(registry_api_url, scope, package);
+ let response = client.get(&package_url).send().await?;
+ Ok(response)
+}