m/cup
1
0
mirror of https://github.com/sergi0g/cup.git synced 2025-11-17 01:23:39 -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

@@ -14,6 +14,16 @@
"type": "boolean", "type": "boolean",
"description": "Whether or not to enable agent mode. When agent mode is enabled, the server only exposes the API and the web interface is unavailable." "description": "Whether or not to enable agent mode. When agent mode is enabled, the server only exposes the API and the web interface is unavailable."
}, },
"ignore_update_type": {
"type": "string",
"description": "The types of updates to ignore. Ignoring an update type also implies ignoring all update types less specific than it. For example, ignoring patch updates also implies ignoring major and minor updates.",
"enum": [
"none",
"major",
"minor",
"patch"
]
},
"images": { "images": {
"type": "object", "type": "object",
"description": "Configuration options for specific images", "description": "Configuration options for specific images",
@@ -59,8 +69,8 @@
} }
}, },
"socket": { "socket": {
"description": "The path to the unix socket you would like Cup to use for communication with the Docker daemon. Useful if you're trying to use Cup with Podman.",
"type": "string", "type": "string",
"description": "The path to the unix socket you would like Cup to use for communication with the Docker daemon. Useful if you're trying to use Cup with Podman.",
"minLength": 1 "minLength": 1
}, },
"servers": { "servers": {
@@ -73,8 +83,8 @@
"minProperties": 1 "minProperties": 1
}, },
"theme": { "theme": {
"description": "The theme used by the web UI",
"type": "string", "type": "string",
"description": "The theme used by the web UI",
"enum": [ "enum": [
"default", "default",
"blue" "blue"

View File

@@ -0,0 +1,23 @@
import { Callout } from "nextra/components";
# Ignored update types
To ignore certain update types, you can modify your config like this:
```jsonc
{
"ignore_update_type": "minor"
}
```
Available options are:
- `none`: Do not ignore any update types (default).
- `major`: Ignore major updates.
- `minor`: Ignore major and minor updates.
- `patch`: Ignore major, minor and patch updates.
<Callout emoji="⚠️">
Ignoring an update type also implies ignoring all update types less specific than it.
For example, ignoring patch updates also implies ignoring major and minor updates.
</Callout>

View File

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

View File

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