Skip to content

Commit 80a2956

Browse files
authored
feat: add ability to ignore certain update types (#91)
1 parent efea81e commit 80a2956

File tree

4 files changed

+68
-5
lines changed

4 files changed

+68
-5
lines changed

cup.schema.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
"type": "boolean",
1515
"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."
1616
},
17+
"ignore_update_type": {
18+
"type": "string",
19+
"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.",
20+
"enum": [
21+
"none",
22+
"major",
23+
"minor",
24+
"patch"
25+
]
26+
},
1727
"images": {
1828
"type": "object",
1929
"description": "Configuration options for specific images",
@@ -59,8 +69,8 @@
5969
}
6070
},
6171
"socket": {
62-
"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.",
6372
"type": "string",
73+
"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.",
6474
"minLength": 1
6575
},
6676
"servers": {
@@ -73,8 +83,8 @@
7383
"minProperties": 1
7484
},
7585
"theme": {
76-
"description": "The theme used by the web UI",
7786
"type": "string",
87+
"description": "The theme used by the web UI",
7888
"enum": [
7989
"default",
8090
"blue"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Callout } from "nextra/components";
2+
3+
# Ignored update types
4+
5+
To ignore certain update types, you can modify your config like this:
6+
7+
```jsonc
8+
{
9+
"ignore_update_type": "minor"
10+
}
11+
```
12+
13+
Available options are:
14+
15+
- `none`: Do not ignore any update types (default).
16+
- `major`: Ignore major updates.
17+
- `minor`: Ignore major and minor updates.
18+
- `patch`: Ignore major, minor and patch updates.
19+
20+
<Callout emoji="⚠️">
21+
Ignoring an update type also implies ignoring all update types less specific than it.
22+
For example, ignoring patch updates also implies ignoring major and minor updates.
23+
</Callout>

src/config.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ use serde::Deserialize;
66
use crate::error;
77

88
#[derive(Clone, Deserialize)]
9+
#[serde(rename_all = "snake_case")]
910
pub enum Theme {
10-
#[serde(rename = "default")]
1111
Default,
12-
#[serde(rename = "blue")]
1312
Blue,
1413
}
1514

@@ -19,6 +18,21 @@ impl Default for Theme {
1918
}
2019
}
2120

21+
#[derive(Clone, Deserialize)]
22+
#[serde(rename_all = "snake_case")]
23+
pub enum UpdateType {
24+
None,
25+
Major,
26+
Minor,
27+
Patch,
28+
}
29+
30+
impl Default for UpdateType {
31+
fn default() -> Self {
32+
Self::None
33+
}
34+
}
35+
2236
#[derive(Clone, Deserialize, Default)]
2337
#[serde(deny_unknown_fields)]
2438
#[serde(default)]
@@ -40,6 +54,7 @@ pub struct ImageConfig {
4054
pub struct Config {
4155
version: u8,
4256
pub agent: bool,
57+
pub ignore_update_type: UpdateType,
4358
pub images: ImageConfig,
4459
pub refresh_interval: Option<String>,
4560
pub registries: FxHashMap<String, RegistryConfig>,
@@ -53,6 +68,7 @@ impl Config {
5368
Self {
5469
version: 3,
5570
agent: false,
71+
ignore_update_type: UpdateType::default(),
5672
images: ImageConfig::default(),
5773
refresh_interval: None,
5874
registries: FxHashMap::default(),

src/registry.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::time::SystemTime;
33
use itertools::Itertools;
44

55
use crate::{
6+
config::UpdateType,
67
error,
78
http::Client,
89
structs::{
@@ -150,6 +151,7 @@ pub async fn get_latest_tag(
150151
&headers,
151152
base,
152153
&image.version_info.as_ref().unwrap().format_str,
154+
ctx,
153155
client,
154156
)
155157
.await
@@ -214,6 +216,7 @@ pub async fn get_extra_tags(
214216
headers: &[(&str, Option<&str>)],
215217
base: &Version,
216218
format_str: &str,
219+
ctx: &Context,
217220
client: &Client,
218221
) -> Result<(Vec<Version>, Option<String>), String> {
219222
let response = client.get(url, &headers, false).await;
@@ -237,7 +240,18 @@ pub async fn get_extra_tags(
237240
}
238241
_ => false,
239242
})
240-
.map(|(tag, _)| tag)
243+
.filter_map(|(tag, _)| match ctx.config.ignore_update_type {
244+
UpdateType::None => Some(tag),
245+
UpdateType::Major => Some(tag).filter(|tag| base.major == tag.major),
246+
UpdateType::Minor => {
247+
Some(tag).filter(|tag| base.major == tag.major && base.minor == tag.minor)
248+
}
249+
UpdateType::Patch => Some(tag).filter(|tag| {
250+
base.major == tag.major
251+
&& base.minor == tag.minor
252+
&& base.patch == tag.patch
253+
}),
254+
})
241255
.dedup()
242256
.collect();
243257
Ok((result, next_url))

0 commit comments

Comments
 (0)