feat(config)!: Add webhook URL field to server config
All checks were successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful

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,10 +1,13 @@
[webhook]
url = "https://localhost:8080/webhook"
[forge.default] [forge.default]
forge_type = "ForgeJo" forge_type = "ForgeJo"
hostname = "git.example.net" 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" token = "API-Token"
# path to private SSH key for user? # path to private SSH key for user?
[forge.default.repos] [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 world = { repo = "user/world", branch = "master" } # maps to the 'master' branch

View file

@ -12,6 +12,7 @@ use crate::filesystem::FileSystem;
/// Mapped from the `git-next-server.toml` file /// Mapped from the `git-next-server.toml` file
#[derive(Debug, PartialEq, Eq, Deserialize)] #[derive(Debug, PartialEq, Eq, Deserialize)]
pub struct ServerConfig { pub struct ServerConfig {
webhook: Webhook,
forge: HashMap<String, Forge>, forge: HashMap<String, Forge>,
} }
impl ServerConfig { 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 /// Mapped from `.git-next.toml` file in target repo
/// Is also derived from the optional parameters in `git-next-server.toml` at /// Is also derived from the optional parameters in `git-next-server.toml` at
/// `forge.{forge}.repos.{repo}.(main|next|dev)` /// `forge.{forge}.repos.{repo}.(main|next|dev)`
@ -336,6 +357,9 @@ mod tests {
fs.write_file( fs.write_file(
"git-next-server.toml", "git-next-server.toml",
r#" r#"
[webhook]
url = "http://localhost:9909/webhook"
[forge.default] [forge.default]
forge_type = "ForgeJo" forge_type = "ForgeJo"
hostname = "git.example.net" hostname = "git.example.net"
@ -357,6 +381,9 @@ mod tests {
.map_err(OneOf::new)?; .map_err(OneOf::new)?;
let config = ServerConfig::load(&fs)?; let config = ServerConfig::load(&fs)?;
let expected = ServerConfig { let expected = ServerConfig {
webhook: Webhook {
url: "http://localhost:9909/webhook".to_string(),
},
forge: HashMap::from([( forge: HashMap::from([(
"default".to_string(), "default".to_string(),
Forge { Forge {