summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPietro Albini <pietro@pietroalbini.org>2019-09-04 17:37:59 +0200
committerPietro Albini <pietro@pietroalbini.org>2019-09-04 17:38:59 +0200
commita4170ba3d5cd5c729162cfdbcfca3710a8c0d0de (patch)
tree584949cc483119405878f6f865f7b81465726f5f /src
parente31b7519f5b89f52a7b8761775448de85e407bce (diff)
static-api: explicitly list github team members
This will allow the list of members to be expanded in the future.
Diffstat (limited to 'src')
-rw-r--r--src/schema.rs38
-rw-r--r--src/static_api.rs11
-rw-r--r--src/validate.rs42
3 files changed, 64 insertions, 27 deletions
diff --git a/src/schema.rs b/src/schema.rs
index fd91120..a95cced 100644
--- a/src/schema.rs
+++ b/src/schema.rs
@@ -220,20 +220,52 @@ impl Team {
&self.permissions
}
- pub(crate) fn github_teams(&self) -> Vec<(&str, &str)> {
+ pub(crate) fn github_teams<'a>(&'a self, data: &Data) -> Result<Vec<GitHubTeam<'a>>, Error> {
if let Some(github) = &self.github {
+ let members = self
+ .members(data)?
+ .iter()
+ .filter_map(|name| data.person(name).map(|p| p.github_id()))
+ .collect::<Vec<_>>();
let name = github
.team_name
.as_ref()
.map(|n| n.as_str())
.unwrap_or(&self.name);
- github.orgs.iter().map(|org| (org.as_str(), name)).collect()
+ Ok(github
+ .orgs
+ .iter()
+ .map(|org| GitHubTeam {
+ org: org.as_str(),
+ name,
+ members: members.clone(),
+ })
+ .collect())
} else {
- Vec::new()
+ Ok(Vec::new())
}
}
}
+#[derive(Eq, PartialEq)]
+pub(crate) struct GitHubTeam<'a> {
+ pub(crate) org: &'a str,
+ pub(crate) name: &'a str,
+ pub(crate) members: Vec<usize>,
+}
+
+impl std::cmp::PartialOrd for GitHubTeam<'_> {
+ fn partial_cmp(&self, other: &GitHubTeam) -> Option<std::cmp::Ordering> {
+ Some(self.cmp(other))
+ }
+}
+
+impl std::cmp::Ord for GitHubTeam<'_> {
+ fn cmp(&self, other: &GitHubTeam) -> std::cmp::Ordering {
+ self.org.cmp(&other.org).then(self.name.cmp(&other.name))
+ }
+}
+
#[derive(serde_derive::Deserialize, Debug)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
struct TeamPeople {
diff --git a/src/static_api.rs b/src/static_api.rs
index 3760b4e..d360927 100644
--- a/src/static_api.rs
+++ b/src/static_api.rs
@@ -48,7 +48,7 @@ impl<'a> Generator<'a> {
members.sort_by_key(|member| member.github.to_lowercase());
members.sort_by_key(|member| !member.is_lead);
- let mut github_teams = team.github_teams();
+ let mut github_teams = team.github_teams(&self.data)?;
github_teams.sort();
let team_data = v1::Team {
@@ -62,10 +62,11 @@ impl<'a> Generator<'a> {
members,
github: Some(v1::TeamGitHub {
teams: github_teams
- .iter()
- .map(|(org, name)| v1::GitHubTeam {
- org: org.to_string(),
- name: name.to_string(),
+ .into_iter()
+ .map(|team| v1::GitHubTeam {
+ org: team.org.to_string(),
+ name: team.name.to_string(),
+ members: team.members,
})
.collect::<Vec<_>>(),
})
diff --git a/src/validate.rs b/src/validate.rs
index e33f391..c6e2657 100644
--- a/src/validate.rs
+++ b/src/validate.rs
@@ -387,25 +387,29 @@ fn validate_github_teams(data: &Data, errors: &mut Vec<String>) {
let mut found = HashMap::new();
let allowed = data.config().allowed_github_orgs();
wrapper(data.teams(), errors, |team, errors| {
- wrapper(team.github_teams().into_iter(), errors, |(org, name), _| {
- if !allowed.contains(&*org) {
- bail!(
- "GitHub organization `{}` isn't allowed (in team `{}`)",
- org,
- team.name()
- );
- }
- if let Some(other) = found.insert((org, name), team.name()) {
- bail!(
- "GitHub team `{}/{}` is defined for both the `{}` and `{}` teams",
- org,
- name,
- team.name(),
- other
- );
- }
- Ok(())
- });
+ wrapper(
+ team.github_teams(data)?.into_iter(),
+ errors,
+ |gh_team, _| {
+ if !allowed.contains(&*gh_team.org) {
+ bail!(
+ "GitHub organization `{}` isn't allowed (in team `{}`)",
+ gh_team.org,
+ team.name()
+ );
+ }
+ if let Some(other) = found.insert((gh_team.org, gh_team.name), team.name()) {
+ bail!(
+ "GitHub team `{}/{}` is defined for both the `{}` and `{}` teams",
+ gh_team.org,
+ gh_team.name,
+ team.name(),
+ other
+ );
+ }
+ Ok(())
+ },
+ );
Ok(())
});
}