diff --git a/server-default.toml b/server-default.toml index d6a03ae..80a6e64 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 3e6a63d..feadd71 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 {