diff options
author | Pietro Albini <pietro@pietroalbini.org> | 2018-11-25 18:43:11 +0100 |
---|---|---|
committer | Pietro Albini <pietro@pietroalbini.org> | 2018-11-25 18:43:11 +0100 |
commit | 17618b4912eb46f41154c515157bedd80b7caf3d (patch) | |
tree | 6e29b5bd83a7aa526b6301f142d6d08e6ff5ccfb /src/schema.rs | |
parent | 484ad8557dd22a5e221191997d55e731c93168a0 (diff) |
add basic team structure handling
Diffstat (limited to 'src/schema.rs')
-rw-r--r-- | src/schema.rs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/schema.rs b/src/schema.rs new file mode 100644 index 0000000..bab5809 --- /dev/null +++ b/src/schema.rs @@ -0,0 +1,65 @@ +use crate::data::Data; +use failure::{Error, err_msg}; +use std::collections::HashSet; + +#[derive(serde_derive::Deserialize, Debug)] +pub(crate) struct Person { + name: String, + github: String, + irc: Option<String>, +} + +impl Person { + pub(crate) fn name(&self) -> &str { + &self.name + } + + pub(crate) fn github(&self) -> &str { + &self.github + } + + pub(crate) fn irc(&self) -> &str { + if let Some(irc) = &self.irc { + irc + } else { + &self.github + } + } +} + +#[derive(serde_derive::Deserialize, Debug)] +pub(crate) struct Team { + name: String, + #[serde(default)] + children: Vec<String>, + people: TeamPeople, +} + +impl Team { + pub(crate) fn name(&self) -> &str { + &self.name + } + + pub(crate) fn leads(&self) -> HashSet<&str> { + self.people.leads.iter().map(|s| s.as_str()).collect() + } + + pub(crate) fn members<'a>(&'a self, data: &'a Data) -> Result<HashSet<&'a str>, Error> { + let mut members: HashSet<_> = self.people.members.iter().map(|s| s.as_str()).collect(); + for subteam in &self.children { + let submembers = data + .team(&subteam) + .ok_or_else(|| err_msg(format!("missing team {}", subteam)))?; + for person in submembers.members(data)? { + members.insert(person); + } + } + Ok(members) + } +} + +#[derive(serde_derive::Deserialize, Debug)] +struct TeamPeople { + leads: Vec<String>, + members: Vec<String>, +} |