fix: return correct response
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Timo Ley 2023-07-19 22:36:24 +02:00
parent 15dc36f337
commit 242b950c13
2 changed files with 39 additions and 2 deletions

View file

@ -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)

View file

@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
#[derive(Deserialize)]
pub struct Request {
pub repo: Repository,
pub configs: Option<Vec<WoodpeckerConfig>>,
}
#[derive(Deserialize)]
@ -15,6 +16,15 @@ pub struct Repository {
#[derive(Serialize)]
pub struct Response {
#[serde(skip_serializing_if = "Option::is_none")]
pub data: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub configs: Option<Vec<WoodpeckerConfig>>,
}
#[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<String> {
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,
}]),
}
}
}
}