Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
🐛 💩 allow default values if Jenkins replies with null when it shouldn't
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed May 15, 2018
1 parent f523f2a commit f3c4e54
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/action/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ pub struct Revision {
/// Branch information
pub branch: Vec<Branch>,
}
impl Default for Revision {
fn default() -> Self {
Revision {
sha1: "".to_string(),
branch: vec![],
}
}
}

tagged_enum_or_default!(
/// Information about a build related to a branch
Expand All @@ -48,3 +56,11 @@ pub struct BuildsByBranch {
#[serde(flatten)]
pub branches: HashMap<String, BranchBuild>,
}

impl Default for BuildsByBranch {
fn default() -> Self {
BuildsByBranch {
branches: HashMap::new(),
}
}
}
11 changes: 11 additions & 0 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ pub enum BuildStatus {
/// Aborted build
Aborted,
}
impl Default for BuildStatus {
fn default() -> Self {
BuildStatus::NotBuilt
}
}

tagged_enum_or_default!(
/// A `Build` of a `Job`
Expand Down Expand Up @@ -279,6 +284,12 @@ pub mod changeset {
}
);

impl Default for ChangeSetList {
fn default() -> Self {
ChangeSetList::EmptyChangeSet {}
}
}

tagged_enum_or_default!(
/// Changes found
pub enum ChangeSet {
Expand Down
8 changes: 6 additions & 2 deletions src/helpers/tagged_enum_or_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ macro_rules! tagged_enum_or_default {
match ::helpers::to_snake_case(&key).as_ref() {
$(stringify!($field) => {
$field = Some(
::serde::de::MapAccess::next_value::<$type>(
::serde::de::MapAccess::next_value::<Option<$type>>(
&mut map,
).map_err(|err| ::serde::de::Error::custom(
).map(|v| if let Some(v) = v {
v
} else {
<$type as Default>::default()
}).map_err(|err| ::serde::de::Error::custom(
format!("{}.{}", stringify!($field), err)
))?
);
Expand Down
11 changes: 11 additions & 0 deletions src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ pub enum BallColor {
#[serde(rename = "notbuilt_anime")]
NotBuiltAnime,
}
impl Default for BallColor {
fn default() -> Self {
BallColor::NotBuilt
}
}

/// Short Job that is used in lists and links from other structs
#[derive(Debug, Deserialize, Clone)]
Expand Down Expand Up @@ -411,3 +416,9 @@ tagged_enum_or_default!(
GitSCM (_class = "hudson.plugins.git.GitSCM") {},
}
);

impl Default for SCM {
fn default() -> Self {
SCM::NullSCM {}
}
}
8 changes: 8 additions & 0 deletions src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ pub struct ShortUser {
/// Absolute URL to the user profile
pub absolute_url: String,
}
impl Default for ShortUser {
fn default() -> Self {
ShortUser {
full_name: "unknown".to_string(),
absolute_url: "".to_string(),
}
}
}

0 comments on commit f3c4e54

Please sign in to comment.