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:
Jiahao XU 2024-05-06 23:00:02 +10:00
parent d2914cca42
commit 0708f6f348
No known key found for this signature in database
GPG key ID: 76D1E687CA3C4928
4 changed files with 22 additions and 16 deletions

View file

@ -223,14 +223,10 @@ impl GhApiClient {
.await;
match res {
Ok(Some(artifacts)) => {
let has_artifact = artifacts.contains(&artifact_name);
Ok(if has_artifact {
HasReleaseArtifact::Yes
} else {
HasReleaseArtifact::No
})
}
Ok(Some(artifacts)) => Ok(artifacts
.get_artifact_url(&artifact_name)
.map(|url| HasReleaseArtifact::Yes { url })
.unwrap_or(HasReleaseArtifact::No)),
Ok(None) => Ok(HasReleaseArtifact::NoSuchRelease),
Err(Error::Unauthorized) => Ok(HasReleaseArtifact::Unauthorized),
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 {
Yes,
Yes {
/// get url for downloading the artifact using GitHub API (for private repository).
url: CompactString,
},
No,
NoSuchRelease,
/// GitHub returns 401 requiring a token.
@ -399,7 +398,7 @@ mod test {
assert!(
matches!(
ret,
HasReleaseArtifact::Yes | HasReleaseArtifact::RateLimit { .. }
HasReleaseArtifact::Yes { .. } | HasReleaseArtifact::RateLimit { .. }
),
"for '{artifact_name}': answer is {:#?}",
ret

View file

@ -20,6 +20,7 @@ use super::{percent_encode_http_url_path, remote, GhApiError, GhGraphQLErrors, G
#[derive(Eq, Deserialize, Debug)]
struct Artifact {
name: CompactString,
url: CompactString,
}
// Manually implement PartialEq and Hash to ensure it will always produce the
@ -57,8 +58,11 @@ pub(super) struct Artifacts {
}
impl Artifacts {
pub(super) fn contains(&self, artifact_name: &str) -> bool {
self.assets.contains(artifact_name)
/// get url for downloading the artifact using GitHub API (for private repository).
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}") {{
release(tagName:"{tag}") {{
releaseAssets({cond}) {{
nodes {{ name }}
nodes {{
name
url
}}
pageInfo {{ endCursor hasNextPage }}
}}
}}