summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPietro Albini <pietro@pietroalbini.org>2019-03-30 11:16:31 +0100
committerPietro Albini <pietro@pietroalbini.org>2019-03-30 11:28:37 +0100
commite5c6237c156065eca542867d1495d0ec48888397 (patch)
treed679fe84b064e25fc5186a18d921b6972280c40a /src
parent84fbef0d92829da723517cdbd87a97585ebba2d5 (diff)
add rfcbot configuration
Diffstat (limited to 'src')
-rw-r--r--src/schema.rs13
-rw-r--r--src/static_api.rs28
-rw-r--r--src/validate.rs14
3 files changed, 55 insertions, 0 deletions
diff --git a/src/schema.rs b/src/schema.rs
index 0143301..be6b7a1 100644
--- a/src/schema.rs
+++ b/src/schema.rs
@@ -103,6 +103,7 @@ pub(crate) struct Team {
people: TeamPeople,
#[serde(default)]
permissions: Permissions,
+ rfcbot: Option<RfcbotData>,
website: Option<WebsiteData>,
#[serde(default)]
lists: Vec<TeamList>,
@@ -125,6 +126,10 @@ impl Team {
self.people.leads.iter().map(|s| s.as_str()).collect()
}
+ pub(crate) fn rfcbot_data(&self) -> Option<&RfcbotData> {
+ self.rfcbot.as_ref()
+ }
+
pub(crate) fn website_data(&self) -> Option<&WebsiteData> {
self.website.as_ref()
}
@@ -218,6 +223,14 @@ struct TeamPeople {
include_all_team_members: bool,
}
+#[derive(serde_derive::Deserialize, Debug)]
+#[serde(rename_all = "kebab-case", deny_unknown_fields)]
+pub(crate) struct RfcbotData {
+ pub(crate) label: String,
+ pub(crate) name: String,
+ pub(crate) ping: String,
+}
+
pub(crate) struct DiscordInvite<'a> {
pub(crate) url: &'a str,
pub(crate) channel: &'a str,
diff --git a/src/static_api.rs b/src/static_api.rs
index 24bd989..3348d74 100644
--- a/src/static_api.rs
+++ b/src/static_api.rs
@@ -25,6 +25,7 @@ impl<'a> Generator<'a> {
self.generate_teams()?;
self.generate_lists()?;
self.generate_permissions()?;
+ self.generate_rfcbot()?;
Ok(())
}
@@ -112,6 +113,33 @@ impl<'a> Generator<'a> {
Ok(())
}
+ fn generate_rfcbot(&self) -> Result<(), Error> {
+ let mut teams = IndexMap::new();
+
+ for team in self.data.teams() {
+ if let Some(rfcbot) = team.rfcbot_data() {
+ let mut members = team
+ .members(&self.data)?
+ .into_iter()
+ .map(|s| s.to_string())
+ .collect::<Vec<_>>();
+ members.sort();
+ teams.insert(
+ rfcbot.label.clone(),
+ v1::RfcbotTeam {
+ name: rfcbot.name.clone(),
+ ping: rfcbot.ping.clone(),
+ members,
+ },
+ );
+ }
+ }
+
+ teams.sort_keys();
+ self.add("v1/rfcbot.json", &v1::Rfcbot { teams })?;
+ Ok(())
+ }
+
fn add<T: serde::Serialize>(&self, path: &str, obj: &T) -> Result<(), Error> {
info!("writing API object {}...", path);
let dest = self.dest.join(path);
diff --git a/src/validate.rs b/src/validate.rs
index 90881fe..21570d2 100644
--- a/src/validate.rs
+++ b/src/validate.rs
@@ -18,6 +18,7 @@ static CHECKS: &[fn(&Data, &mut Vec<String>)] = &[
validate_discord_name,
validate_duplicate_permissions,
validate_permissions,
+ validate_rfcbot_labels,
];
pub(crate) fn validate(data: &Data) -> Result<(), Error> {
@@ -284,6 +285,19 @@ fn validate_permissions(data: &Data, errors: &mut Vec<String>) {
});
}
+/// Ensure there are no duplicate rfcbot labels
+fn validate_rfcbot_labels(data: &Data, errors: &mut Vec<String>) {
+ let mut labels = HashSet::new();
+ wrapper(data.teams(), errors, move |team, errors| {
+ if let Some(rfcbot) = team.rfcbot_data() {
+ if !labels.insert(rfcbot.label.clone()) {
+ errors.push(format!("duplicate rfcbot label: {}", rfcbot.label));
+ }
+ }
+ Ok(())
+ });
+}
+
fn wrapper<T, I, F>(iter: I, errors: &mut Vec<String>, mut func: F)
where
I: Iterator<Item = T>,