feat: remove notification.type
All checks were successful
Rust / build (push) Successful in 1m40s
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
ci/woodpecker/cron/cron-docker-builder Pipeline was successful
ci/woodpecker/cron/push-next Pipeline was successful
ci/woodpecker/cron/tag-created Pipeline was successful

This makes it easier to specify multiple types of notifications,
rather than a single type.
This commit is contained in:
Paul Campbell 2024-07-31 06:56:04 +01:00
parent 7b64e300b6
commit 8df7600053
3 changed files with 5 additions and 40 deletions

View file

@ -7,7 +7,7 @@ use tracing::Instrument;
use crate::{repo::messages::NotifyUser, server::actor::ServerActor};
use git_next_core::server::{self, Notification, NotificationType};
use git_next_core::server::{self, OutboundWebhook};
impl Handler<NotifyUser> for ServerActor {
type Result = ();
@ -19,9 +19,8 @@ impl Handler<NotifyUser> for ServerActor {
let notification_config = server_config.notification().clone();
let net = self.net.clone();
async move {
match notification_config.r#type() {
NotificationType::None => { /* do nothing */ }
NotificationType::Webhook => send_webhook(msg, notification_config, net).await,
if let Some(webhook_config) = notification_config.webhook() {
send_webhook(msg, webhook_config, net).await;
}
}
.in_current_span()
@ -32,13 +31,9 @@ impl Handler<NotifyUser> for ServerActor {
async fn send_webhook(
msg: NotifyUser,
notification_config: Notification,
webhook_config: &OutboundWebhook,
net: kxio::network::Network,
) {
let Some(webhook_config) = notification_config.webhook() else {
tracing::warn!("Invalid notification configuration (config) - can't sent notification");
return;
};
let Ok(webhook) =
Webhook::from_bytes(webhook_config.secret().expose_secret().as_bytes().into())
else {

View file

@ -6,8 +6,6 @@ port = 8080
url = "https://localhost:8080" # don't include any query path or a trailing slash
[notification] # where updates from git-next should be sent to alert the user
type = "None"
# type = "Webhook"
# webhook = { url = "https//localhost:9090", secret = "secret-password" }
[storage] # where local copies of repositories will be cloned (bare) into

View file

@ -159,25 +159,6 @@ impl ServerStorage {
}
}
/// Identifier for the type of Notification
#[derive(
Clone,
Default,
Debug,
derive_more::From,
PartialEq,
Eq,
PartialOrd,
Ord,
serde::Deserialize,
Copy,
)]
pub enum NotificationType {
#[default]
None,
Webhook,
}
/// Defines the Webhook Forges should send updates to
/// Must be an address that is accessible from the remote forge
#[derive(
@ -192,27 +173,18 @@ pub enum NotificationType {
serde::Deserialize,
)]
pub struct Notification {
r#type: NotificationType,
webhook: Option<OutboundWebhook>,
}
impl Notification {
pub const fn none() -> Self {
Self {
r#type: NotificationType::None,
webhook: None,
}
Self { webhook: None }
}
pub const fn new_webhook(webhook: OutboundWebhook) -> Self {
Self {
r#type: NotificationType::Webhook,
webhook: Some(webhook),
}
}
pub const fn r#type(&self) -> NotificationType {
self.r#type
}
pub const fn webhook(&self) -> Option<&OutboundWebhook> {
self.webhook.as_ref()
}