Skip to content

Commit

Permalink
Use default value when deserializing some fields (cncf#604)
Browse files Browse the repository at this point in the history
Signed-off-by: Sergio Castaño Arteaga <[email protected]>
  • Loading branch information
tegioz authored and ES-zxy committed May 6, 2024
1 parent 7daef60 commit 6ef3559
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
1 change: 1 addition & 0 deletions crates/core/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ pub struct RepositoryGithubData {
pub latest_commit: Commit,
pub participation_stats: Vec<i64>,
pub stars: i64,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub topics: Vec<String>,
pub url: String,

Expand Down
16 changes: 8 additions & 8 deletions crates/core/src/datasets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ pub mod base {
#[serde(skip_serializing_if = "Option::is_none")]
pub base_path: Option<String>,

#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub categories: Vec<Category>,

#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub categories_overridden: Vec<CategoryName>,

#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -95,10 +95,10 @@ pub mod base {
#[serde(skip_serializing_if = "Option::is_none")]
pub grid_items_size: Option<GridItemsSize>,

#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub groups: Vec<Group>,

#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub guide_summary: GuideSummary,

#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -107,7 +107,7 @@ pub mod base {
#[serde(skip_serializing_if = "Option::is_none")]
pub images: Option<Images>,

#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub items: Vec<Item>,

#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -260,7 +260,7 @@ pub mod embed {
/// Embed dataset information.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct Embed {
#[serde(flatten, skip_serializing_if = "HashMap::is_empty")]
#[serde(default, flatten, skip_serializing_if = "HashMap::is_empty")]
pub views: HashMap<EmbedKey, EmbedView>,
}

Expand Down Expand Up @@ -315,7 +315,7 @@ pub mod embed {
pub struct EmbedView {
pub category: Category,

#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub items: Vec<Item>,
}
}
Expand All @@ -339,7 +339,7 @@ pub mod full {
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub github_data: GithubData,

#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub items: Vec<Item>,
}

Expand Down
42 changes: 21 additions & 21 deletions crates/core/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ impl Stats {
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct MembersStats {
/// Number of members joined per year-month.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub joined_at: BTreeMap<YearMonth, u64>,

/// Running total of number of members joined per year-month.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub joined_at_rt: BTreeMap<YearMonth, u64>,

/// Total number of members.
pub members: u64,

/// Number of members per subcategory.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub subcategories: BTreeMap<String, u64>,
}

Expand Down Expand Up @@ -111,19 +111,19 @@ impl MembersStats {
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct OrganizationsStats {
/// Total number of acquisitions per year across all organizations.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub acquisitions: BTreeMap<Year, u64>,

/// Total acquisitions price per year across all organizations.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub acquisitions_price: BTreeMap<Year, u64>,

/// Total number of funding rounds per year across all organizations.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub funding_rounds: BTreeMap<Year, u64>,

/// Total money raised on funding rounds per year across all organizations.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub funding_rounds_money_raised: BTreeMap<Year, u64>,
}

Expand Down Expand Up @@ -194,42 +194,42 @@ impl OrganizationsStats {
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ProjectsStats {
/// Number of projects accepted per year-month.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub accepted_at: BTreeMap<YearMonth, u64>,

/// Running total of number of projects accepted per year-month.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub accepted_at_rt: BTreeMap<YearMonth, u64>,

/// Number of security audits per year-month.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub audits: BTreeMap<YearMonth, u64>,

/// Running total of number of security audits per year-month.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub audits_rt: BTreeMap<YearMonth, u64>,

/// Number of projects per category and subcategory.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub category: BTreeMap<CategoryName, CategoryProjectsStats>,

/// Promotions from incubating to graduated per year-month.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub incubating_to_graduated: BTreeMap<YearMonth, u64>,

/// Number of projects per maturity.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub maturity: BTreeMap<String, u64>,

/// Total number of projects.
pub projects: u64,

/// Promotions from sandbox to incubating per year-month.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub sandbox_to_incubating: BTreeMap<YearMonth, u64>,

/// Number of projects per TAG.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub tag: BTreeMap<TagName, u64>,
}

Expand Down Expand Up @@ -324,7 +324,7 @@ pub struct CategoryProjectsStats {
pub projects: u64,

/// Number of projects per subcategory.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub subcategories: BTreeMap<SubCategoryName, u64>,
}

Expand All @@ -338,19 +338,19 @@ pub struct RepositoriesStats {
pub contributors: u64,

/// Number of repositories where each language is used.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub languages: BTreeMap<String, u64>,

/// Source code bytes written on each language.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub languages_bytes: BTreeMap<String, u64>,

/// Number of repositories where each license is used.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub licenses: BTreeMap<String, u64>,

/// Number of commits per week over the last year.
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub participation_stats: Vec<i64>,

/// Number of repositories.
Expand Down

0 comments on commit 6ef3559

Please sign in to comment.