Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion veno-core/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ pub struct AppState {
impl AppState {
pub fn init(file_path: &str) -> Result<Self> {
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)
}

Expand Down
24 changes: 23 additions & 1 deletion veno-core/src/notifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
pub artifact_ids: ArtifactSelection,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(untagged)]
pub enum ArtifactSelection {
All(AllMarker),
Specific(Vec<String>),
}

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)]
Expand Down
28 changes: 25 additions & 3 deletions veno-web/src/api/notifiers/model.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
pub artifact_ids: ArtifactSelectionDto,
}

#[derive(Serialize, Debug, Clone, ToSchema)]
Expand All @@ -24,6 +24,19 @@ pub enum SinkDto {
Console(ConsoleSink),
}

#[derive(Serialize, Debug, Clone, ToSchema)]
#[serde(untagged)]
pub enum ArtifactSelectionDto {
All(AllMarker),
Specific(Vec<String>),
}

#[derive(Serialize, Debug, Clone, ToSchema)]
#[serde(rename_all = "lowercase")]
pub enum AllMarker {
All,
}

#[derive(Debug, Clone, Serialize, ToSchema)]
pub struct SlackSink {
pub webhook: String,
Expand Down Expand Up @@ -56,7 +69,7 @@ impl From<Notifier> for NotifierResponse {
Self {
name: value.name,
sink: value.sink.into(),
artifact_ids: value.artifact_ids,
artifact_ids: value.artifact_ids.into(),
}
}
}
Expand Down Expand Up @@ -84,3 +97,12 @@ impl From<Sink> for SinkDto {
}
}
}

impl From<ArtifactSelection> for ArtifactSelectionDto {
fn from(value: ArtifactSelection) -> Self {
match value {
ArtifactSelection::All(_) => ArtifactSelectionDto::All(AllMarker::All),
ArtifactSelection::Specific(x) => ArtifactSelectionDto::Specific(x),
}
}
}
Loading