forked from kemitix/git-next
feat(config)!: Add webhook URL field to server config
This commit is contained in:
parent
b21b80881e
commit
069b313fc3
2 changed files with 32 additions and 2 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
[webhook]
|
||||||
|
url = "https://localhost:8080/webhook"
|
||||||
|
|
||||||
[forge.default]
|
[forge.default]
|
||||||
forge_type = "ForgeJo"
|
forge_type = "ForgeJo"
|
||||||
hostname = "git.example.net"
|
hostname = "git.example.net"
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue