From 670c2d554bdbbe13e98deff3d6821b894943b812 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Tue, 5 Feb 2019 10:27:20 +0100 Subject: add mailing lists to the static API --- rust_team_data/src/v1.rs | 11 +++++++++++ src/static_api.rs | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/rust_team_data/src/v1.rs b/rust_team_data/src/v1.rs index 5387028..2bf5bfd 100644 --- a/rust_team_data/src/v1.rs +++ b/rust_team_data/src/v1.rs @@ -48,3 +48,14 @@ pub struct Teams { #[serde(flatten)] pub teams: IndexMap, } + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct List { + pub address: String, + pub members: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Lists { + pub lists: IndexMap, +} diff --git a/src/static_api.rs b/src/static_api.rs index 1beea23..164cfbe 100644 --- a/src/static_api.rs +++ b/src/static_api.rs @@ -22,6 +22,7 @@ impl<'a> Generator<'a> { pub(crate) fn generate(&self) -> Result<(), Error> { self.generate_teams()?; + self.generate_lists()?; Ok(()) } @@ -78,6 +79,26 @@ impl<'a> Generator<'a> { Ok(()) } + fn generate_lists(&self) -> Result<(), Error> { + let mut lists = IndexMap::new(); + + for list in self.data.lists()?.values() { + let mut members = list.emails().to_vec(); + members.sort(); + lists.insert(list.address().to_string(), v1::List { + address: list.address().to_string(), + members, + }); + } + + lists.sort_keys(); + self.add( + "v1/lists.json", + &v1::Lists { lists }, + )?; + Ok(()) + } + fn add(&self, path: &str, obj: &T) -> Result<(), Error> { info!("writing API object {}...", path); let dest = self.dest.join(path); -- cgit v1.2.3