diff --git a/src/main.rs b/src/main.rs index 38b5ff5..3d275ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,7 +62,7 @@ async fn on_request( let conf = body.config().ok_or(Error::NoContent)?; if conf.starts_with("http://") || conf.starts_with("https://") { let drone_config = client.get(conf).send().await?.text().await?; - let response = Response { data: drone_config }; + let response = Response::new(drone_config, body.is_woodpecker()); return Ok(Json(response)); } Err(Error::NoContent) diff --git a/src/model.rs b/src/model.rs index c0e760e..5e2194f 100644 --- a/src/model.rs +++ b/src/model.rs @@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize}; #[derive(Deserialize)] pub struct Request { pub repo: Repository, + pub configs: Option>, } #[derive(Deserialize)] @@ -15,6 +16,15 @@ pub struct Repository { #[derive(Serialize)] pub struct Response { + #[serde(skip_serializing_if = "Option::is_none")] + pub data: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub configs: Option>, +} + +#[derive(Serialize, Deserialize)] +pub struct WoodpeckerConfig { + pub name: String, pub data: String, } @@ -23,6 +33,33 @@ pub struct APIConfig(pub Client); impl Request { pub fn config(&self) -> Option { - self.repo.config_path.clone().or(self.repo.config_file.clone()).or(self.repo.config.clone()) + self.repo + .config_path + .clone() + .or(self.repo.config_file.clone()) + .or(self.repo.config.clone()) + } + + pub fn is_woodpecker(&self) -> bool { + self.configs.is_some() + } +} + +impl Response { + pub fn new(data: String, is_woodpecker: bool) -> Self { + if is_woodpecker { + Self { + data: Some(data), + configs: None, + } + } else { + Self { + data: None, + configs: Some(vec![WoodpeckerConfig { + name: "central-override".to_string(), + data, + }]), + } + } } }