Refactor: Use GhRepo in GhRelease

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2024-05-09 23:30:53 +10:00
parent 7bd8468c35
commit 6e6d7d778f
No known key found for this signature in database
GPG key ID: 76D1E687CA3C4928
2 changed files with 35 additions and 16 deletions

View file

@ -38,8 +38,7 @@ impl GhRepo {
/// The keys required to identify a github release.
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
pub struct GhRelease {
pub owner: CompactString,
pub repo: CompactString,
pub repo: GhRepo,
pub tag: CompactString,
}
@ -72,8 +71,10 @@ impl GhReleaseArtifact {
(path_segments.next().is_none() && url.fragment().is_none() && url.query().is_none()).then(
|| Self {
release: GhRelease {
repo: GhRepo {
owner: percent_decode_http_url_path(owner),
repo: percent_decode_http_url_path(repo),
},
tag: percent_decode_http_url_path(tag),
},
artifact_name: percent_decode_http_url_path(artifact_name),
@ -211,11 +212,13 @@ mod test {
use std::{env, num::NonZeroU16};
mod cargo_binstall_v0_20_1 {
use super::{CompactString, GhRelease};
use super::{CompactString, GhRelease, GhRepo};
pub(super) const RELEASE: GhRelease = GhRelease {
repo: GhRepo {
owner: CompactString::new_inline("cargo-bins"),
repo: CompactString::new_inline("cargo-binstall"),
},
tag: CompactString::new_inline("v0.20.1"),
};
@ -259,7 +262,10 @@ mod test {
fn extract_gh_release_artifacts_failure() {
use cargo_binstall_v0_20_1::*;
let GhRelease { owner, repo, tag } = RELEASE;
let GhRelease {
repo: GhRepo { owner, repo },
tag,
} = RELEASE;
assert_extract_gh_release_artifacts_failures(&[
"https://examle.com",
@ -280,7 +286,10 @@ mod test {
fn extract_gh_release_artifacts_success() {
use cargo_binstall_v0_20_1::*;
let GhRelease { owner, repo, tag } = RELEASE;
let GhRelease {
repo: GhRepo { owner, repo },
tag,
} = RELEASE;
for artifact in ARTIFACTS {
let GhReleaseArtifact {
@ -364,8 +373,10 @@ mod test {
async fn test_gh_api_client_cargo_binstall_no_such_release() {
for client in create_client().await {
let release = GhRelease {
repo: GhRepo {
owner: "cargo-bins".to_compact_string(),
repo: "cargo-binstall".to_compact_string(),
},
// We are currently at v0.20.1 and we would never release
// anything older than v0.20.1
tag: "v0.18.2".to_compact_string(),
@ -391,8 +402,10 @@ mod test {
use super::*;
const RELEASE: GhRelease = GhRelease {
repo: GhRepo {
owner: CompactString::new_inline("rustsec"),
repo: CompactString::new_inline("rustsec"),
},
tag: CompactString::new_inline("cargo-audit/v0.17.6"),
};

View file

@ -11,7 +11,7 @@ use serde::Deserialize;
use super::{
common::{issue_graphql_query, issue_restful_api, percent_encode_http_url_path},
GhApiError, GhRelease,
GhApiError, GhRelease, GhRepo,
};
// Only include fields we do care about
@ -67,7 +67,10 @@ impl Artifacts {
async fn fetch_release_artifacts_restful_api(
client: &remote::Client,
GhRelease { owner, repo, tag }: &GhRelease,
GhRelease {
repo: GhRepo { owner, repo },
tag,
}: &GhRelease,
auth_token: Option<&str>,
) -> Result<Artifacts, GhApiError> {
issue_restful_api(
@ -131,7 +134,10 @@ impl fmt::Display for FilterCondition {
async fn fetch_release_artifacts_graphql_api(
client: &remote::Client,
GhRelease { owner, repo, tag }: &GhRelease,
GhRelease {
repo: GhRepo { owner, repo },
tag,
}: &GhRelease,
auth_token: &str,
) -> Result<Artifacts, GhApiError> {
let mut artifacts = Artifacts::default();