mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-17 08:06:38 +00:00
Refactor: Use GhRepo
in GhRelease
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
7bd8468c35
commit
6e6d7d778f
2 changed files with 35 additions and 16 deletions
|
@ -38,8 +38,7 @@ impl GhRepo {
|
||||||
/// The keys required to identify a github release.
|
/// The keys required to identify a github release.
|
||||||
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
|
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
|
||||||
pub struct GhRelease {
|
pub struct GhRelease {
|
||||||
pub owner: CompactString,
|
pub repo: GhRepo,
|
||||||
pub repo: CompactString,
|
|
||||||
pub tag: CompactString,
|
pub tag: CompactString,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,8 +71,10 @@ impl GhReleaseArtifact {
|
||||||
(path_segments.next().is_none() && url.fragment().is_none() && url.query().is_none()).then(
|
(path_segments.next().is_none() && url.fragment().is_none() && url.query().is_none()).then(
|
||||||
|| Self {
|
|| Self {
|
||||||
release: GhRelease {
|
release: GhRelease {
|
||||||
|
repo: GhRepo {
|
||||||
owner: percent_decode_http_url_path(owner),
|
owner: percent_decode_http_url_path(owner),
|
||||||
repo: percent_decode_http_url_path(repo),
|
repo: percent_decode_http_url_path(repo),
|
||||||
|
},
|
||||||
tag: percent_decode_http_url_path(tag),
|
tag: percent_decode_http_url_path(tag),
|
||||||
},
|
},
|
||||||
artifact_name: percent_decode_http_url_path(artifact_name),
|
artifact_name: percent_decode_http_url_path(artifact_name),
|
||||||
|
@ -211,11 +212,13 @@ mod test {
|
||||||
use std::{env, num::NonZeroU16};
|
use std::{env, num::NonZeroU16};
|
||||||
|
|
||||||
mod cargo_binstall_v0_20_1 {
|
mod cargo_binstall_v0_20_1 {
|
||||||
use super::{CompactString, GhRelease};
|
use super::{CompactString, GhRelease, GhRepo};
|
||||||
|
|
||||||
pub(super) const RELEASE: GhRelease = GhRelease {
|
pub(super) const RELEASE: GhRelease = GhRelease {
|
||||||
|
repo: GhRepo {
|
||||||
owner: CompactString::new_inline("cargo-bins"),
|
owner: CompactString::new_inline("cargo-bins"),
|
||||||
repo: CompactString::new_inline("cargo-binstall"),
|
repo: CompactString::new_inline("cargo-binstall"),
|
||||||
|
},
|
||||||
tag: CompactString::new_inline("v0.20.1"),
|
tag: CompactString::new_inline("v0.20.1"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -259,7 +262,10 @@ mod test {
|
||||||
fn extract_gh_release_artifacts_failure() {
|
fn extract_gh_release_artifacts_failure() {
|
||||||
use cargo_binstall_v0_20_1::*;
|
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(&[
|
assert_extract_gh_release_artifacts_failures(&[
|
||||||
"https://examle.com",
|
"https://examle.com",
|
||||||
|
@ -280,7 +286,10 @@ mod test {
|
||||||
fn extract_gh_release_artifacts_success() {
|
fn extract_gh_release_artifacts_success() {
|
||||||
use cargo_binstall_v0_20_1::*;
|
use cargo_binstall_v0_20_1::*;
|
||||||
|
|
||||||
let GhRelease { owner, repo, tag } = RELEASE;
|
let GhRelease {
|
||||||
|
repo: GhRepo { owner, repo },
|
||||||
|
tag,
|
||||||
|
} = RELEASE;
|
||||||
|
|
||||||
for artifact in ARTIFACTS {
|
for artifact in ARTIFACTS {
|
||||||
let GhReleaseArtifact {
|
let GhReleaseArtifact {
|
||||||
|
@ -364,8 +373,10 @@ mod test {
|
||||||
async fn test_gh_api_client_cargo_binstall_no_such_release() {
|
async fn test_gh_api_client_cargo_binstall_no_such_release() {
|
||||||
for client in create_client().await {
|
for client in create_client().await {
|
||||||
let release = GhRelease {
|
let release = GhRelease {
|
||||||
|
repo: GhRepo {
|
||||||
owner: "cargo-bins".to_compact_string(),
|
owner: "cargo-bins".to_compact_string(),
|
||||||
repo: "cargo-binstall".to_compact_string(),
|
repo: "cargo-binstall".to_compact_string(),
|
||||||
|
},
|
||||||
// We are currently at v0.20.1 and we would never release
|
// We are currently at v0.20.1 and we would never release
|
||||||
// anything older than v0.20.1
|
// anything older than v0.20.1
|
||||||
tag: "v0.18.2".to_compact_string(),
|
tag: "v0.18.2".to_compact_string(),
|
||||||
|
@ -391,8 +402,10 @@ mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
const RELEASE: GhRelease = GhRelease {
|
const RELEASE: GhRelease = GhRelease {
|
||||||
|
repo: GhRepo {
|
||||||
owner: CompactString::new_inline("rustsec"),
|
owner: CompactString::new_inline("rustsec"),
|
||||||
repo: CompactString::new_inline("rustsec"),
|
repo: CompactString::new_inline("rustsec"),
|
||||||
|
},
|
||||||
tag: CompactString::new_inline("cargo-audit/v0.17.6"),
|
tag: CompactString::new_inline("cargo-audit/v0.17.6"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ use serde::Deserialize;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
common::{issue_graphql_query, issue_restful_api, percent_encode_http_url_path},
|
common::{issue_graphql_query, issue_restful_api, percent_encode_http_url_path},
|
||||||
GhApiError, GhRelease,
|
GhApiError, GhRelease, GhRepo,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Only include fields we do care about
|
// Only include fields we do care about
|
||||||
|
@ -67,7 +67,10 @@ impl Artifacts {
|
||||||
|
|
||||||
async fn fetch_release_artifacts_restful_api(
|
async fn fetch_release_artifacts_restful_api(
|
||||||
client: &remote::Client,
|
client: &remote::Client,
|
||||||
GhRelease { owner, repo, tag }: &GhRelease,
|
GhRelease {
|
||||||
|
repo: GhRepo { owner, repo },
|
||||||
|
tag,
|
||||||
|
}: &GhRelease,
|
||||||
auth_token: Option<&str>,
|
auth_token: Option<&str>,
|
||||||
) -> Result<Artifacts, GhApiError> {
|
) -> Result<Artifacts, GhApiError> {
|
||||||
issue_restful_api(
|
issue_restful_api(
|
||||||
|
@ -131,7 +134,10 @@ impl fmt::Display for FilterCondition {
|
||||||
|
|
||||||
async fn fetch_release_artifacts_graphql_api(
|
async fn fetch_release_artifacts_graphql_api(
|
||||||
client: &remote::Client,
|
client: &remote::Client,
|
||||||
GhRelease { owner, repo, tag }: &GhRelease,
|
GhRelease {
|
||||||
|
repo: GhRepo { owner, repo },
|
||||||
|
tag,
|
||||||
|
}: &GhRelease,
|
||||||
auth_token: &str,
|
auth_token: &str,
|
||||||
) -> Result<Artifacts, GhApiError> {
|
) -> Result<Artifacts, GhApiError> {
|
||||||
let mut artifacts = Artifacts::default();
|
let mut artifacts = Artifacts::default();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue