m/cup
1
0
mirror of https://github.com/sergi0g/cup.git synced 2025-11-17 17:43:37 -05:00

feat: add ability to ignore certain update types (#91)

This commit is contained in:
Seow Alex
2025-04-12 14:37:28 +08:00
committed by GitHub
parent efea81ef39
commit 80a295680d
4 changed files with 68 additions and 5 deletions

View File

@@ -6,10 +6,9 @@ use serde::Deserialize;
use crate::error;
#[derive(Clone, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Theme {
#[serde(rename = "default")]
Default,
#[serde(rename = "blue")]
Blue,
}
@@ -19,6 +18,21 @@ impl Default for Theme {
}
}
#[derive(Clone, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum UpdateType {
None,
Major,
Minor,
Patch,
}
impl Default for UpdateType {
fn default() -> Self {
Self::None
}
}
#[derive(Clone, Deserialize, Default)]
#[serde(deny_unknown_fields)]
#[serde(default)]
@@ -40,6 +54,7 @@ pub struct ImageConfig {
pub struct Config {
version: u8,
pub agent: bool,
pub ignore_update_type: UpdateType,
pub images: ImageConfig,
pub refresh_interval: Option<String>,
pub registries: FxHashMap<String, RegistryConfig>,
@@ -53,6 +68,7 @@ impl Config {
Self {
version: 3,
agent: false,
ignore_update_type: UpdateType::default(),
images: ImageConfig::default(),
refresh_interval: None,
registries: FxHashMap::default(),

View File

@@ -3,6 +3,7 @@ use std::time::SystemTime;
use itertools::Itertools;
use crate::{
config::UpdateType,
error,
http::Client,
structs::{
@@ -150,6 +151,7 @@ pub async fn get_latest_tag(
&headers,
base,
&image.version_info.as_ref().unwrap().format_str,
ctx,
client,
)
.await
@@ -214,6 +216,7 @@ pub async fn get_extra_tags(
headers: &[(&str, Option<&str>)],
base: &Version,
format_str: &str,
ctx: &Context,
client: &Client,
) -> Result<(Vec<Version>, Option<String>), String> {
let response = client.get(url, &headers, false).await;
@@ -237,7 +240,18 @@ pub async fn get_extra_tags(
}
_ => false,
})
.map(|(tag, _)| tag)
.filter_map(|(tag, _)| match ctx.config.ignore_update_type {
UpdateType::None => Some(tag),
UpdateType::Major => Some(tag).filter(|tag| base.major == tag.major),
UpdateType::Minor => {
Some(tag).filter(|tag| base.major == tag.major && base.minor == tag.minor)
}
UpdateType::Patch => Some(tag).filter(|tag| {
base.major == tag.major
&& base.minor == tag.minor
&& base.patch == tag.patch
}),
})
.dedup()
.collect();
Ok((result, next_url))