feat(config)!: Add webhook URL field to server config

This commit is contained in:
Paul Campbell 2024-04-13 11:59:59 +01:00
parent b21b80881e
commit 069b313fc3
2 changed files with 32 additions and 2 deletions

View file

@ -1,3 +1,6 @@
[webhook]
url = "https://localhost:8080/webhook"
[forge.default]
forge_type = "ForgeJo"
hostname = "git.example.net"

View file

@ -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<String, Forge>,
}
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<str> 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 {