diff --git a/veno-core/src/app.rs b/veno-core/src/app.rs index 4ef5800..57174cb 100644 --- a/veno-core/src/app.rs +++ b/veno-core/src/app.rs @@ -18,9 +18,10 @@ pub struct AppState { impl AppState { pub fn init(file_path: &str) -> Result { let app_config = AppConfig::load(file_path)?; - let app_state = app_config + let app_state: AppState = app_config .try_deserialize() .context("Could not deserialize app config")?; + Ok(app_state) } diff --git a/veno-core/src/notifier/mod.rs b/veno-core/src/notifier/mod.rs index 0700154..90e3216 100644 --- a/veno-core/src/notifier/mod.rs +++ b/veno-core/src/notifier/mod.rs @@ -17,7 +17,29 @@ static DEFAULT_MESSAGE_PREFIX: &str = "New version available for"; pub struct Notifier { pub name: String, pub sink: Sink, - pub artifact_ids: Vec, + pub artifact_ids: ArtifactSelection, +} + +#[derive(Deserialize, Debug, Clone)] +#[serde(untagged)] +pub enum ArtifactSelection { + All(AllMarker), + Specific(Vec), +} + +impl ArtifactSelection { + pub fn contains(&self, other: &str) -> bool { + match self { + ArtifactSelection::All(_) => true, + ArtifactSelection::Specific(ids) => ids.contains(&other.to_string()), + } + } +} + +#[derive(Deserialize, Debug, Clone)] +#[serde(rename_all = "lowercase")] +pub enum AllMarker { + All, } #[derive(Deserialize, Debug, Clone)] diff --git a/veno-web/src/api/notifiers/model.rs b/veno-web/src/api/notifiers/model.rs index ff7379a..bf652a0 100644 --- a/veno-web/src/api/notifiers/model.rs +++ b/veno-web/src/api/notifiers/model.rs @@ -1,12 +1,12 @@ use serde::Serialize; use utoipa::ToSchema; -use veno_core::notifier::{Notifier, Sink}; +use veno_core::notifier::{ArtifactSelection, Notifier, Sink}; #[derive(Serialize, Debug, Clone, ToSchema)] pub struct NotifierResponse { pub name: String, pub sink: SinkDto, - pub artifact_ids: Vec, + pub artifact_ids: ArtifactSelectionDto, } #[derive(Serialize, Debug, Clone, ToSchema)] @@ -24,6 +24,19 @@ pub enum SinkDto { Console(ConsoleSink), } +#[derive(Serialize, Debug, Clone, ToSchema)] +#[serde(untagged)] +pub enum ArtifactSelectionDto { + All(AllMarker), + Specific(Vec), +} + +#[derive(Serialize, Debug, Clone, ToSchema)] +#[serde(rename_all = "lowercase")] +pub enum AllMarker { + All, +} + #[derive(Debug, Clone, Serialize, ToSchema)] pub struct SlackSink { pub webhook: String, @@ -56,7 +69,7 @@ impl From for NotifierResponse { Self { name: value.name, sink: value.sink.into(), - artifact_ids: value.artifact_ids, + artifact_ids: value.artifact_ids.into(), } } } @@ -84,3 +97,12 @@ impl From for SinkDto { } } } + +impl From for ArtifactSelectionDto { + fn from(value: ArtifactSelection) -> Self { + match value { + ArtifactSelection::All(_) => ArtifactSelectionDto::All(AllMarker::All), + ArtifactSelection::Specific(x) => ArtifactSelectionDto::Specific(x), + } + } +}