diff --git a/src/api/data_types/deploy.rs b/src/api/data_types/deploy.rs new file mode 100644 index 0000000000..a7fcbc191d --- /dev/null +++ b/src/api/data_types/deploy.rs @@ -0,0 +1,29 @@ +//! The `Deploy` data type. + +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; +use std::borrow::Cow; + +#[derive(Serialize, Deserialize, Debug, Default)] +pub struct Deploy<'d> { + #[serde(rename = "environment")] + pub env: Cow<'d, str>, + pub name: Option>, + pub url: Option>, + #[serde(rename = "dateStarted")] + pub started: Option>, + #[serde(rename = "dateFinished")] + pub finished: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + pub projects: Option>>, +} + +impl<'d> Deploy<'d> { + /// Returns the name of this deploy, defaulting to `"unnamed"`. + pub fn name(&self) -> &str { + match self.name.as_deref() { + Some("") | None => "unnamed", + Some(name) => name, + } + } +} diff --git a/src/api/data_types/mod.rs b/src/api/data_types/mod.rs index 3d0af372bd..0a8b5e1d3b 100644 --- a/src/api/data_types/mod.rs +++ b/src/api/data_types/mod.rs @@ -1,3 +1,7 @@ +//! Data types used in the api module + mod chunking; +mod deploy; pub use self::chunking::*; +pub use self::deploy::*; diff --git a/src/api/mod.rs b/src/api/mod.rs index c289844940..da10176046 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -2359,30 +2359,6 @@ impl fmt::Display for Repo { } } -#[derive(Serialize, Deserialize, Debug, Default)] -pub struct Deploy<'d> { - #[serde(rename = "environment")] - pub env: String, - pub name: Option, - pub url: Option, - #[serde(rename = "dateStarted")] - pub started: Option>, - #[serde(rename = "dateFinished")] - pub finished: Option>, - #[serde(skip_serializing_if = "Option::is_none")] - pub projects: Option>>, -} - -impl<'d> Deploy<'d> { - /// Returns the name of this deploy, defaulting to `"unnamed"`. - pub fn name(&self) -> &str { - match self.name.as_deref() { - Some("") | None => "unnamed", - Some(name) => name, - } - } -} - #[derive(Debug, Serialize, Clone)] pub struct PatchSet { pub path: String, diff --git a/src/commands/deploys/new.rs b/src/commands/deploys/new.rs index af4b57bd1e..3239ff83e3 100644 --- a/src/commands/deploys/new.rs +++ b/src/commands/deploys/new.rs @@ -68,9 +68,9 @@ pub fn execute(matches: &ArgMatches) -> Result<()> { let api = Api::current(); let version = config.get_release_with_legacy_fallback(matches)?; let mut deploy = Deploy { - env: matches.get_one::("env").unwrap().to_string(), - name: matches.get_one::("name").cloned(), - url: matches.get_one::("url").cloned(), + env: matches.get_one::("env").unwrap().into(), + name: matches.get_one::("name").map(|n| n.into()), + url: matches.get_one::("url").map(|u| u.into()), projects: matches.get_many::("project").map(|x| x.into_iter().map(|x| x.into()).collect()), ..Default::default() };