Skip to content

Commit

Permalink
Make bots an enum
Browse files Browse the repository at this point in the history
  • Loading branch information
rylev committed Aug 12, 2022
1 parent 33b6e68 commit f1dc320
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
11 changes: 10 additions & 1 deletion rust_team_data/src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,19 @@ pub struct Repo {
pub org: String,
pub name: String,
pub description: String,
pub bots: Vec<String>,
pub bots: Vec<Bot>,
pub teams: Vec<RepoTeam>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum Bot {
Bors,
Highfive,
Rustbot,
RustTimer,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RepoTeam {
pub name: String,
Expand Down
11 changes: 10 additions & 1 deletion src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ pub(crate) struct Repo {
pub org: String,
pub name: String,
pub description: String,
pub bots: Vec<String>, // TODO: should this be an enum?
pub bots: Vec<Bot>,
pub access: RepoAccess,
}

Expand All @@ -656,6 +656,15 @@ impl Repo {
}
}

#[derive(serde_derive::Deserialize, Debug, Clone)]
#[serde(rename_all = "kebab-case")]
pub(crate) enum Bot {
Bors,
Highfive,
Rustbot,
RustTimer,
}

#[derive(serde_derive::Deserialize, Debug)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
pub(crate) struct RepoAccess {
Expand Down
13 changes: 11 additions & 2 deletions src/static_api.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::data::Data;
use crate::schema::{Permissions, RepoPermission, TeamKind, ZulipGroupMember};
use crate::schema::{Bot, Permissions, RepoPermission, TeamKind, ZulipGroupMember};
use failure::Error;
use indexmap::IndexMap;
use log::info;
Expand Down Expand Up @@ -39,7 +39,16 @@ impl<'a> Generator<'a> {
org: r.org.clone(),
name: r.name.clone(),
description: r.description.clone(),
bots: r.bots.clone(),
bots: r
.bots
.iter()
.map(|b| match b {
Bot::Bors => v1::Bot::Bors,
Bot::Highfive => v1::Bot::Highfive,
Bot::RustTimer => v1::Bot::RustTimer,
Bot::Rustbot => v1::Bot::Rustbot,
})
.collect(),
teams: r
.access
.teams
Expand Down
2 changes: 1 addition & 1 deletion src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ fn validate_zulip_group_extra_people(data: &Data, errors: &mut Vec<String>) {
});
}

/// Ensure working group names start with `wg-`
/// Ensure repos reference valid teams
fn validate_repos(data: &Data, errors: &mut Vec<String>) {
wrapper(data.repos(), errors, |repo, _| {
for (team_name, _) in &repo.access.teams {
Expand Down

0 comments on commit f1dc320

Please sign in to comment.