From 069b313fc33f17b1744f7c22a2c7df902fe58860 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 13 Apr 2024 11:59:59 +0100 Subject: [PATCH] feat(config)!: Add webhook URL field to server config --- server-default.toml | 7 +++++-- src/server/config.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/server-default.toml b/server-default.toml index d6a03ae6..80a6e644 100644 --- a/server-default.toml +++ b/server-default.toml @@ -1,10 +1,13 @@ +[webhook] +url = "https://localhost:8080/webhook" + [forge.default] forge_type = "ForgeJo" hostname = "git.example.net" -user = "git-next" # the user to perform actions as +user = "git-next" # the user to perform actions as token = "API-Token" # path to private SSH key for user? [forge.default.repos] -hello = { repo = "user/hello", branch = "main" } # maps to https://git.example.net/user/hello on the branch 'main' +hello = { repo = "user/hello", branch = "main" } # maps to https://git.example.net/user/hello on the branch 'main' world = { repo = "user/world", branch = "master" } # maps to the 'master' branch diff --git a/src/server/config.rs b/src/server/config.rs index 3e6a63d9..feadd714 100644 --- a/src/server/config.rs +++ b/src/server/config.rs @@ -12,6 +12,7 @@ use crate::filesystem::FileSystem; /// Mapped from the `git-next-server.toml` file #[derive(Debug, PartialEq, Eq, Deserialize)] pub struct ServerConfig { + webhook: Webhook, forge: HashMap, } impl ServerConfig { @@ -27,6 +28,26 @@ impl ServerConfig { } } +/// Defines the Webhook Forges should send updates to +#[derive(Debug, PartialEq, Eq, Deserialize)] +pub struct Webhook { + url: String, +} +impl Webhook { + #[allow(dead_code)] // TODO: (#15) register webhook + pub fn url(&self) -> WebhookUrl { + WebhookUrl(self.url.clone()) + } +} + +/// The URL for the webhook where forges should send their updates +pub struct WebhookUrl(String); +impl AsRef for WebhookUrl { + fn as_ref(&self) -> &str { + &self.0 + } +} + /// Mapped from `.git-next.toml` file in target repo /// Is also derived from the optional parameters in `git-next-server.toml` at /// `forge.{forge}.repos.{repo}.(main|next|dev)` @@ -336,6 +357,9 @@ mod tests { fs.write_file( "git-next-server.toml", r#" + [webhook] + url = "http://localhost:9909/webhook" + [forge.default] forge_type = "ForgeJo" hostname = "git.example.net" @@ -357,6 +381,9 @@ mod tests { .map_err(OneOf::new)?; let config = ServerConfig::load(&fs)?; let expected = ServerConfig { + webhook: Webhook { + url: "http://localhost:9909/webhook".to_string(), + }, forge: HashMap::from([( "default".to_string(), Forge {