use super::TestRun;
use crate::framework::endpoint::{HerokuEndpoint, Method};
pub struct TestRunCreate<'a> {
pub params: TestRunCreateParams<'a>,
}
#[cfg(feature = "builder")]
impl<'a> TestRunCreate<'a> {
pub fn new(
commit_branch: &'a str,
commit_message: &'a str,
commit_sha: &'a str,
pipeline: &'a str,
source_blob_url: &'a str,
) -> TestRunCreate<'a> {
TestRunCreate {
params: TestRunCreateParams {
commit_branch: commit_branch,
commit_message: commit_message,
commit_sha: commit_sha,
debug: None,
organization: None,
pipeline: pipeline,
source_blob_url: source_blob_url,
},
}
}
pub fn debug(&mut self, debug: bool) -> &mut Self {
self.params.debug = Some(debug);
self
}
pub fn organization(&mut self, organization: &'a str) -> &mut Self {
self.params.organization = Some(organization);
self
}
pub fn build(&self) -> TestRunCreate<'a> {
TestRunCreate {
params: TestRunCreateParams {
commit_branch: self.params.commit_branch,
commit_message: self.params.commit_message,
commit_sha: self.params.commit_sha,
debug: self.params.debug,
organization: self.params.organization,
pipeline: self.params.pipeline,
source_blob_url: self.params.source_blob_url,
},
}
}
}
#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Debug)]
pub struct TestRunCreateParams<'a> {
pub commit_branch: &'a str,
pub commit_message: &'a str,
pub commit_sha: &'a str,
pub debug: Option<bool>,
pub organization: Option<&'a str>,
pub pipeline: &'a str,
pub source_blob_url: &'a str,
}
impl<'a> HerokuEndpoint<TestRun, (), TestRunCreateParams<'a>> for TestRunCreate<'a> {
fn method(&self) -> Method {
Method::Post
}
fn path(&self) -> String {
format!("test-runs")
}
fn body(&self) -> Option<TestRunCreateParams<'a>> {
Some(self.params.clone())
}
}