2022-03-26 23:53:27 +01:00
|
|
|
use reqwest::Client;
|
2022-01-30 22:18:09 +01:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct Request {
|
|
|
|
pub repo: Repository,
|
2023-07-19 22:36:24 +02:00
|
|
|
pub configs: Option<Vec<WoodpeckerConfig>>,
|
2022-01-30 22:18:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct Repository {
|
2023-07-19 21:51:47 +02:00
|
|
|
pub config_path: Option<String>,
|
|
|
|
pub config_file: Option<String>,
|
|
|
|
pub config: Option<String>,
|
2022-01-30 22:18:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
pub struct Response {
|
2023-07-19 22:36:24 +02:00
|
|
|
#[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,
|
2022-01-30 22:18:09 +01:00
|
|
|
pub data: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
2022-03-26 23:53:27 +01:00
|
|
|
pub struct APIConfig(pub Client);
|
2022-01-30 22:18:09 +01:00
|
|
|
|
|
|
|
impl Request {
|
2023-07-19 21:51:47 +02:00
|
|
|
pub fn config(&self) -> Option<String> {
|
2023-07-19 22:36:24 +02:00
|
|
|
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 {
|
2023-07-19 22:51:41 +02:00
|
|
|
if !is_woodpecker {
|
2023-07-19 22:36:24 +02:00
|
|
|
Self {
|
|
|
|
data: Some(data),
|
|
|
|
configs: None,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Self {
|
|
|
|
data: None,
|
|
|
|
configs: Some(vec![WoodpeckerConfig {
|
|
|
|
name: "central-override".to_string(),
|
|
|
|
data,
|
|
|
|
}]),
|
|
|
|
}
|
|
|
|
}
|
2022-03-23 21:18:35 +01:00
|
|
|
}
|
2022-01-30 22:18:09 +01:00
|
|
|
}
|