diff --git a/src/badges.rs b/src/badges.rs deleted file mode 100644 index 6375c09..0000000 --- a/src/badges.rs +++ /dev/null @@ -1,352 +0,0 @@ -//! badges.csv - -use crate::crates::CrateId; -use crate::error::{err, Result}; -use crate::load::FromRecord; -use csv::StringRecord; -use serde_derive::Deserialize; -use std::collections::BTreeMap as Map; - -/// One row of **badges.csv**. -#[derive(Clone, Debug)] -#[non_exhaustive] -pub struct Row { - pub crate_id: CrateId, - pub badge_type: BadgeType, -} - -#[derive(Clone, Debug)] -#[non_exhaustive] -pub enum BadgeType { - #[non_exhaustive] - Appveyor { - repository: String, - project_name: Option, - branch: Option, - service: Option, - id: Option, - }, - - #[non_exhaustive] - AzureDevops { - project: String, - pipeline: String, - build: Option, - }, - - #[non_exhaustive] - BitbucketPipelines { repository: String, branch: String }, - - #[non_exhaustive] - CircleCi { - repository: String, - branch: Option, - }, - - #[non_exhaustive] - CirrusCi { - repository: String, - branch: Option, - }, - - #[non_exhaustive] - Codecov { - repository: String, - branch: Option, - service: Option, - }, - - #[non_exhaustive] - Coveralls { - repository: String, - branch: Option, - service: Option, - }, - - #[non_exhaustive] - Gitlab { - repository: String, - branch: Option, - tag: Option, - }, - - #[non_exhaustive] - IsItMaintainedIssueResolution { - repository: String, - service: Option, - }, - - #[non_exhaustive] - IsItMaintainedOpenIssues { - repository: String, - service: Option, - }, - - #[non_exhaustive] - Maintenance { status: MaintenanceStatus }, - - #[non_exhaustive] - TravisCi { - repository: String, - branch: Option, - service: Option, - master: Option, - tld: Option, - }, - - Other { - badge_type: String, - attributes: Map, - }, -} - -#[derive(Deserialize, Clone, Debug)] -#[serde(rename_all = "kebab-case")] -pub enum MaintenanceStatus { - ActivelyDeveloped, - AsIs, - Deprecated, - Experimental, - LookingForMaintainer, - None, - PassivelyMaintained, -} - -impl FromRecord for Row { - fn from_record(record: &StringRecord, headers: &StringRecord) -> Result { - de(record, headers) - } -} - -fn de(record: &StringRecord, headers: &StringRecord) -> Result { - #[derive(Deserialize)] - #[serde(deny_unknown_fields)] - struct Record<'a> { - attributes: &'a str, - badge_type: &'a str, - crate_id: CrateId, - } - - let record: Record = record.deserialize(Some(headers)).map_err(err)?; - - let badge_type = match record.badge_type { - "appveyor" => { - #[derive(Deserialize)] - #[serde(deny_unknown_fields)] - struct Attributes { - repository: String, - #[serde(alias = "project-name")] - project_name: Option, - branch: Option, - service: Option, - id: Option, - } - serde_json::from_str(record.attributes) - .ok() - .map(|attributes: Attributes| BadgeType::Appveyor { - repository: attributes.repository, - project_name: attributes.project_name, - branch: attributes.branch, - service: attributes.service, - id: attributes.id, - }) - } - - "azure-devops" => { - #[derive(Deserialize)] - #[serde(deny_unknown_fields)] - struct Attributes { - project: String, - pipeline: String, - build: Option, - } - serde_json::from_str(record.attributes) - .ok() - .map(|attributes: Attributes| BadgeType::AzureDevops { - project: attributes.project, - pipeline: attributes.pipeline, - build: attributes.build, - }) - } - - "bitbucket-pipelines" => { - #[derive(Deserialize)] - #[serde(deny_unknown_fields)] - struct Attributes { - repository: String, - branch: String, - } - serde_json::from_str(record.attributes) - .ok() - .map(|attributes: Attributes| BadgeType::BitbucketPipelines { - repository: attributes.repository, - branch: attributes.branch, - }) - } - - "circle-ci" => { - #[derive(Deserialize)] - #[serde(deny_unknown_fields)] - struct Attributes { - repository: String, - branch: Option, - } - serde_json::from_str(record.attributes) - .ok() - .map(|attributes: Attributes| BadgeType::CircleCi { - repository: attributes.repository, - branch: attributes.branch, - }) - } - - "cirrus-ci" => { - #[derive(Deserialize)] - #[serde(deny_unknown_fields)] - struct Attributes { - repository: String, - branch: Option, - } - serde_json::from_str(record.attributes) - .ok() - .map(|attributes: Attributes| BadgeType::CirrusCi { - repository: attributes.repository, - branch: attributes.branch, - }) - } - - "codecov" => { - #[derive(Deserialize)] - #[serde(deny_unknown_fields)] - struct Attributes { - repository: String, - branch: Option, - service: Option, - } - serde_json::from_str(record.attributes) - .ok() - .map(|attributes: Attributes| BadgeType::Codecov { - repository: attributes.repository, - branch: attributes.branch, - service: attributes.service, - }) - } - - "coveralls" => { - #[derive(Deserialize)] - #[serde(deny_unknown_fields)] - struct Attributes { - repository: String, - branch: Option, - service: Option, - } - serde_json::from_str(record.attributes) - .ok() - .map(|attributes: Attributes| BadgeType::Coveralls { - repository: attributes.repository, - branch: attributes.branch, - service: attributes.service, - }) - } - - "gitlab" => { - #[derive(Deserialize)] - #[serde(deny_unknown_fields)] - struct Attributes { - repository: String, - branch: Option, - tag: Option, - } - serde_json::from_str(record.attributes) - .ok() - .map(|attributes: Attributes| BadgeType::Gitlab { - repository: attributes.repository, - branch: attributes.branch, - tag: attributes.tag, - }) - } - - "is-it-maintained-issue-resolution" => { - #[derive(Deserialize)] - #[serde(deny_unknown_fields)] - struct Attributes { - repository: String, - service: Option, - } - serde_json::from_str(record.attributes) - .ok() - .map( - |attributes: Attributes| BadgeType::IsItMaintainedIssueResolution { - repository: attributes.repository, - service: attributes.service, - }, - ) - } - - "is-it-maintained-open-issues" => { - #[derive(Deserialize)] - #[serde(deny_unknown_fields)] - struct Attributes { - repository: String, - service: Option, - } - serde_json::from_str(record.attributes) - .ok() - .map( - |attributes: Attributes| BadgeType::IsItMaintainedOpenIssues { - repository: attributes.repository, - service: attributes.service, - }, - ) - } - - "maintenance" => { - #[derive(Deserialize)] - #[serde(deny_unknown_fields)] - struct Attributes { - status: MaintenanceStatus, - } - serde_json::from_str(record.attributes) - .ok() - .map(|attributes: Attributes| BadgeType::Maintenance { - status: attributes.status, - }) - } - - "travis-ci" => { - #[derive(Deserialize)] - #[serde(deny_unknown_fields)] - struct Attributes { - repository: String, - branch: Option, - service: Option, - master: Option, - tld: Option, - } - serde_json::from_str(record.attributes) - .ok() - .map(|attributes: Attributes| BadgeType::TravisCi { - repository: attributes.repository, - branch: attributes.branch, - service: attributes.service, - master: attributes.master, - tld: attributes.tld, - }) - } - - _other => None, - }; - - let badge_type = if let Some(badge_type) = badge_type { - badge_type - } else { - BadgeType::Other { - badge_type: record.badge_type.to_owned(), - attributes: serde_json::from_str(record.attributes).map_err(err)?, - } - }; - - Ok(Row { - badge_type, - crate_id: record.crate_id, - }) -} diff --git a/src/lib.rs b/src/lib.rs index 4da3982..5b6a06e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,6 @@ mod error; mod index; mod load; -pub mod badges; pub mod categories; pub mod crate_owners; pub mod crates; @@ -56,14 +55,6 @@ pub use crate::load::{load_all, Loader}; #[derive(Default)] #[non_exhaustive] pub struct DbDump { - /// - /// - /// - /// - /// - ///
badges.csvcrate_idbadge_typeattributes
- pub badges: Vec, - /// /// /// diff --git a/src/load.rs b/src/load.rs index 04513c5..bbbcd5d 100644 --- a/src/load.rs +++ b/src/load.rs @@ -42,7 +42,6 @@ use tar::Archive; /// ``` #[derive(Default)] pub struct Loader<'a> { - badges: Option>, categories: Option>, crate_owners: Option>, crates: Option>, @@ -68,11 +67,6 @@ impl<'a> Loader<'a> { Loader::default() } - pub fn badges(&mut self, f: impl FnMut(crate::badges::Row) + 'a) -> &mut Self { - self.badges = Some(Callback::new(f)); - self - } - pub fn categories(&mut self, f: impl FnMut(crate::categories::Row) + 'a) -> &mut Self { self.categories = Some(Callback::new(f)); self @@ -187,7 +181,6 @@ fn do_load(path: &Path, loader: &mut Loader) -> Result<()> { for entry in archive.entries()? { #[deny(unused_variables)] let Loader { - badges, categories, crate_owners, crates, @@ -203,8 +196,7 @@ fn do_load(path: &Path, loader: &mut Loader) -> Result<()> { versions, } = loader; - if badges.as_ref().map_or(true, Callback::done) - && categories.as_ref().map_or(true, Callback::done) + if categories.as_ref().map_or(true, Callback::done) && crate_owners.as_ref().map_or(true, Callback::done) && crates.as_ref().map_or(true, Callback::done) && crates_categories.as_ref().map_or(true, Callback::done) @@ -234,7 +226,6 @@ fn do_load(path: &Path, loader: &mut Loader) -> Result<()> { #[deny(unused_variables)] let Loader { - badges, categories, crate_owners, crates, @@ -251,7 +242,7 @@ fn do_load(path: &Path, loader: &mut Loader) -> Result<()> { } = loader; let (path, result) = if path.ends_with("badges.csv") { - ("badges", read(badges, entry)) + continue; // https://github.com/rust-lang/crates.io/pull/8155 } else if path.ends_with("categories.csv") { ("categories", read(categories, entry)) } else if path.ends_with("crate_owners.csv") { @@ -337,28 +328,28 @@ where /// # use db_dump::Result; /// # /// # struct DbDump { -/// # badges: Vec, /// # categories: Vec, +/// # crate_owners: Vec, /// # versions: Vec, /// # } /// # /// # pub fn load_all(path: impl AsRef) -> Result { /// # let path = path.as_ref(); -/// let mut badges = Vec::new(); /// let mut categories = Vec::new(); +/// let mut crate_owners = Vec::new(); /// /* ... */ /// let mut versions = Vec::new(); /// /// db_dump::Loader::new() -/// .badges(|row| badges.push(row)) /// .categories(|row| categories.push(row)) +/// .crate_owners(|row| crate_owners.push(row)) /// /* ... */ /// .versions(|row| versions.push(row)) /// .load(path)?; /// /// Ok(DbDump { -/// badges, /// categories, +/// crate_owners, /// /* ... */ /// versions, /// }) @@ -373,7 +364,6 @@ pub fn load_all(path: impl AsRef) -> Result { } fn do_load_all(path: &Path) -> Result { - let mut badges = Vec::new(); let mut categories = Vec::new(); let mut crate_owners = Vec::new(); let mut crates = Vec::new(); @@ -389,7 +379,6 @@ fn do_load_all(path: &Path) -> Result { let mut versions = Vec::new(); let mut loader = Loader { - badges: Some(Callback::new(|row| badges.push(row))), categories: Some(Callback::new(|row| categories.push(row))), crate_owners: Some(Callback::new(|row| crate_owners.push(row))), crates: Some(Callback::new(|row| crates.push(row))), @@ -409,7 +398,6 @@ fn do_load_all(path: &Path) -> Result { drop(loader); Ok(DbDump { - badges, categories, crate_owners, crates,
categories.csvid