mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-17 16:16:37 +00:00
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>
This commit is contained in:
parent
d2914cca42
commit
0708f6f348
4 changed files with 22 additions and 16 deletions
|
@ -35,7 +35,7 @@ pub(super) async fn does_url_exist(
|
||||||
|
|
||||||
// The future returned has the same size as a pointer
|
// The future returned has the same size as a pointer
|
||||||
match gh_api_client.has_release_artifact(artifact).await? {
|
match gh_api_client.has_release_artifact(artifact).await? {
|
||||||
HasReleaseArtifact::Yes => return Ok(true),
|
HasReleaseArtifact::Yes { .. } => return Ok(true),
|
||||||
HasReleaseArtifact::No | HasReleaseArtifact::NoSuchRelease => return Ok(false),
|
HasReleaseArtifact::No | HasReleaseArtifact::NoSuchRelease => return Ok(false),
|
||||||
|
|
||||||
HasReleaseArtifact::RateLimit { retry_after } => {
|
HasReleaseArtifact::RateLimit { retry_after } => {
|
||||||
|
|
|
@ -223,14 +223,10 @@ impl GhApiClient {
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
Ok(Some(artifacts)) => {
|
Ok(Some(artifacts)) => Ok(artifacts
|
||||||
let has_artifact = artifacts.contains(&artifact_name);
|
.get_artifact_url(&artifact_name)
|
||||||
Ok(if has_artifact {
|
.map(|url| HasReleaseArtifact::Yes { url })
|
||||||
HasReleaseArtifact::Yes
|
.unwrap_or(HasReleaseArtifact::No)),
|
||||||
} else {
|
|
||||||
HasReleaseArtifact::No
|
|
||||||
})
|
|
||||||
}
|
|
||||||
Ok(None) => Ok(HasReleaseArtifact::NoSuchRelease),
|
Ok(None) => Ok(HasReleaseArtifact::NoSuchRelease),
|
||||||
Err(Error::Unauthorized) => Ok(HasReleaseArtifact::Unauthorized),
|
Err(Error::Unauthorized) => Ok(HasReleaseArtifact::Unauthorized),
|
||||||
Err(Error::RateLimit { retry_after }) => {
|
Err(Error::RateLimit { retry_after }) => {
|
||||||
|
@ -243,9 +239,12 @@ impl GhApiClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
|
#[derive(Eq, PartialEq, Clone, Debug)]
|
||||||
pub enum HasReleaseArtifact {
|
pub enum HasReleaseArtifact {
|
||||||
Yes,
|
Yes {
|
||||||
|
/// get url for downloading the artifact using GitHub API (for private repository).
|
||||||
|
url: CompactString,
|
||||||
|
},
|
||||||
No,
|
No,
|
||||||
NoSuchRelease,
|
NoSuchRelease,
|
||||||
/// GitHub returns 401 requiring a token.
|
/// GitHub returns 401 requiring a token.
|
||||||
|
@ -399,7 +398,7 @@ mod test {
|
||||||
assert!(
|
assert!(
|
||||||
matches!(
|
matches!(
|
||||||
ret,
|
ret,
|
||||||
HasReleaseArtifact::Yes | HasReleaseArtifact::RateLimit { .. }
|
HasReleaseArtifact::Yes { .. } | HasReleaseArtifact::RateLimit { .. }
|
||||||
),
|
),
|
||||||
"for '{artifact_name}': answer is {:#?}",
|
"for '{artifact_name}': answer is {:#?}",
|
||||||
ret
|
ret
|
||||||
|
|
|
@ -20,6 +20,7 @@ use super::{percent_encode_http_url_path, remote, GhApiError, GhGraphQLErrors, G
|
||||||
#[derive(Eq, Deserialize, Debug)]
|
#[derive(Eq, Deserialize, Debug)]
|
||||||
struct Artifact {
|
struct Artifact {
|
||||||
name: CompactString,
|
name: CompactString,
|
||||||
|
url: CompactString,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manually implement PartialEq and Hash to ensure it will always produce the
|
// Manually implement PartialEq and Hash to ensure it will always produce the
|
||||||
|
@ -57,8 +58,11 @@ pub(super) struct Artifacts {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Artifacts {
|
impl Artifacts {
|
||||||
pub(super) fn contains(&self, artifact_name: &str) -> bool {
|
/// get url for downloading the artifact using GitHub API (for private repository).
|
||||||
self.assets.contains(artifact_name)
|
pub(super) fn get_artifact_url(&self, artifact_name: &str) -> Option<CompactString> {
|
||||||
|
self.assets
|
||||||
|
.get(artifact_name)
|
||||||
|
.map(|artifact| artifact.url.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +205,10 @@ query {{
|
||||||
repository(owner:"{owner}",name:"{repo}") {{
|
repository(owner:"{owner}",name:"{repo}") {{
|
||||||
release(tagName:"{tag}") {{
|
release(tagName:"{tag}") {{
|
||||||
releaseAssets({cond}) {{
|
releaseAssets({cond}) {{
|
||||||
nodes {{ name }}
|
nodes {{
|
||||||
|
name
|
||||||
|
url
|
||||||
|
}}
|
||||||
pageInfo {{ endCursor hasNextPage }}
|
pageInfo {{ endCursor hasNextPage }}
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub async fn does_url_exist(
|
||||||
|
|
||||||
// The future returned has the same size as a pointer
|
// The future returned has the same size as a pointer
|
||||||
match gh_api_client.has_release_artifact(artifact).await? {
|
match gh_api_client.has_release_artifact(artifact).await? {
|
||||||
HasReleaseArtifact::Yes => return Ok(true),
|
HasReleaseArtifact::Yes { .. } => return Ok(true),
|
||||||
HasReleaseArtifact::No | HasReleaseArtifact::NoSuchRelease => return Ok(false),
|
HasReleaseArtifact::No | HasReleaseArtifact::NoSuchRelease => return Ok(false),
|
||||||
|
|
||||||
HasReleaseArtifact::RateLimit { retry_after } => {
|
HasReleaseArtifact::RateLimit { retry_after } => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue