use super::{ReviewApp, ReviewAppConfig};
use std::collections::HashMap;
use crate::framework::endpoint::{HerokuEndpoint, Method};
pub struct ReviewAppCreate<'a> {
pub params: ReviewAppCreateParams<'a>,
}
#[cfg(feature = "builder")]
impl<'a> ReviewAppCreate<'a> {
pub fn new(
branch: &'a str,
pipeline_id: &'a str,
source_blob_url: &'a str,
) -> ReviewAppCreate<'a> {
ReviewAppCreate {
params: ReviewAppCreateParams {
branch: branch,
pr_number: None,
pipeline: pipeline_id,
source_blob: SourceBlob {
url: source_blob_url,
version: None,
},
enviroment: None,
fork_repo_id: None,
},
}
}
pub fn source_blob_version(&mut self, source_blob_version: &'a str) -> &mut Self {
self.params.source_blob.version = Some(source_blob_version);
self
}
pub fn source_blob_url(&mut self, source_blob_url: &'a str) -> &mut Self {
self.params.source_blob.url = source_blob_url;
self
}
pub fn enviroment(&mut self, enviroment: HashMap<&'a str, &'a str>) -> &mut Self {
self.params.enviroment = Some(enviroment);
self
}
pub fn pr_number(&mut self, pr_number: u32) -> &mut Self {
self.params.pr_number = Some(pr_number);
self
}
pub fn fork_repo_id(&mut self, fork_repo_id: i64) -> &mut Self {
self.params.fork_repo_id = Some(fork_repo_id);
self
}
pub fn build(&self) -> ReviewAppCreate<'a> {
ReviewAppCreate {
params: ReviewAppCreateParams {
branch: self.params.branch,
pr_number: self.params.pr_number,
pipeline: self.params.pipeline,
source_blob: SourceBlob {
url: self.params.source_blob.url,
version: self.params.source_blob.version,
},
enviroment: self.params.enviroment.clone(),
fork_repo_id: self.params.fork_repo_id,
},
}
}
}
#[derive(Serialize, Clone, Debug)]
pub struct ReviewAppCreateParams<'a> {
pub branch: &'a str,
pub pr_number: Option<u32>,
pub pipeline: &'a str,
pub source_blob: SourceBlob<'a>,
pub enviroment: Option<HashMap<&'a str, &'a str>>,
pub fork_repo_id: Option<i64>,
}
#[derive(Serialize, Clone, Debug)]
pub struct SourceBlob<'a> {
pub url: &'a str,
pub version: Option<&'a str>,
}
impl<'a> HerokuEndpoint<ReviewApp, (), ReviewAppCreateParams<'a>> for ReviewAppCreate<'a> {
fn method(&self) -> Method {
Method::Post
}
fn path(&self) -> String {
format!("review-apps")
}
fn body(&self) -> Option<ReviewAppCreateParams<'a>> {
Some(self.params.clone())
}
}
pub struct ReviewAppConfigEnable<'a> {
pub pipeline_id: &'a str,
pub params: ReviewAppConfigEnableParams<'a>,
}
#[cfg(feature = "builder")]
impl<'a> ReviewAppConfigEnable<'a> {
pub fn new(pipeline_id: &'a str, repo: &'a str) -> ReviewAppConfigEnable<'a> {
ReviewAppConfigEnable {
pipeline_id,
params: ReviewAppConfigEnableParams {
repo: repo,
automatic_review_apps: None,
destroy_stale_apps: None,
stale_days: None,
deploy_target: None,
wait_for_ci: None,
base_name: None,
},
}
}
pub fn base_name(&mut self, base_name: &'a str) -> &mut Self {
self.params.base_name = Some(base_name);
self
}
pub fn wait_for_ci(&mut self, wait_for_ci: bool) -> &mut Self {
self.params.wait_for_ci = Some(wait_for_ci);
self
}
pub fn deploy_target(&mut self, id: &'a str, t_type: &'a str) -> &mut Self {
self.params.deploy_target = Some(DeployTarget {
id: id,
type_field: t_type,
});
self
}
pub fn stale_days(&mut self, stale_days: &'a str) -> &mut Self {
self.params.stale_days = Some(stale_days);
self
}
pub fn destroy_stale_apps(&mut self, destroy_stale_apps: bool) -> &mut Self {
self.params.destroy_stale_apps = Some(destroy_stale_apps);
self
}
pub fn automatic_review_apps(&mut self, automatic_review_apps: bool) -> &mut Self {
self.params.automatic_review_apps = Some(automatic_review_apps);
self
}
pub fn build(&self) -> ReviewAppConfigEnable<'a> {
ReviewAppConfigEnable {
pipeline_id: self.pipeline_id,
params: ReviewAppConfigEnableParams {
repo: self.params.repo,
automatic_review_apps: self.params.automatic_review_apps,
destroy_stale_apps: self.params.destroy_stale_apps,
stale_days: self.params.stale_days,
deploy_target: self.params.deploy_target.clone(),
wait_for_ci: self.params.wait_for_ci,
base_name: self.params.base_name,
},
}
}
}
#[derive(Serialize, Clone, Debug)]
pub struct ReviewAppConfigEnableParams<'a> {
pub repo: &'a str,
#[serde(skip_serializing_if = "Option::is_none")]
pub automatic_review_apps: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub destroy_stale_apps: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub stale_days: Option<&'a str>,
pub deploy_target: Option<DeployTarget<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub wait_for_ci: Option<bool>,
pub base_name: Option<&'a str>,
}
#[derive(Serialize, Clone, Debug)]
pub struct DeployTarget<'a> {
pub id: &'a str,
#[serde(rename = "type")]
pub type_field: &'a str,
}
impl<'a> HerokuEndpoint<ReviewAppConfig, (), ReviewAppConfigEnableParams<'a>>
for ReviewAppConfigEnable<'a>
{
fn method(&self) -> Method {
Method::Post
}
fn path(&self) -> String {
format!("pipelines/{}/review-app-config", self.pipeline_id)
}
fn body(&self) -> Option<ReviewAppConfigEnableParams<'a>> {
Some(self.params.clone())
}
}