maintainer label: tag if submitter is a maintainer of each of their packages

If the author of the PR is one of any number of maintainers, add the
label. This is in contrast to the previous version, where the submitter
of the PR had to be the ONLY maintainer on ANY package they touched.
This commit is contained in:
Graham Christensen 2019-01-24 21:56:20 -05:00
parent 734466201d
commit d05d8030f0
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C
3 changed files with 45 additions and 13 deletions

View file

@ -1,20 +1,22 @@
use ofborg::nix::Nix; use ofborg::nix::Nix;
use std::collections::HashMap; use std::collections::{HashMap, HashSet};
use std::io::Write; use std::io::Write;
use std::path::Path; use std::path::Path;
use tempfile::NamedTempFile; use tempfile::NamedTempFile;
#[derive(Deserialize, Debug, Eq, PartialEq)] #[derive(Deserialize, Debug, Eq, PartialEq)]
pub struct ImpactedMaintainers(HashMap<Maintainer, Vec<Package>>); pub struct ImpactedMaintainers(HashMap<Maintainer, Vec<Package>>);
#[derive(Deserialize, Debug, Eq, PartialEq, Hash)] pub struct MaintainersByPackage(pub HashMap<Package, HashSet<Maintainer>>);
struct Maintainer(String);
#[derive(Deserialize, Clone, Debug, Eq, PartialEq, Hash)]
pub struct Maintainer(String);
impl<'a> From<&'a str> for Maintainer { impl<'a> From<&'a str> for Maintainer {
fn from(name: &'a str) -> Maintainer { fn from(name: &'a str) -> Maintainer {
Maintainer(name.to_owned()) Maintainer(name.to_owned())
} }
} }
#[derive(Deserialize, Debug, Eq, PartialEq, Hash)] #[derive(Deserialize, Clone, Debug, Eq, PartialEq, Hash)]
struct Package(String); pub struct Package(String);
impl<'a> From<&'a str> for Package { impl<'a> From<&'a str> for Package {
fn from(name: &'a str) -> Package { fn from(name: &'a str) -> Package {
Package(name.to_owned()) Package(name.to_owned())
@ -80,6 +82,22 @@ impl ImpactedMaintainers {
.map(|(maintainer, _)| maintainer.0.clone()) .map(|(maintainer, _)| maintainer.0.clone())
.collect() .collect()
} }
pub fn maintainers_by_package(&self) -> MaintainersByPackage {
let mut bypkg = MaintainersByPackage(HashMap::new());
for (maintainer, packages) in self.0.iter() {
for package in packages.iter() {
bypkg
.0
.entry(package.clone())
.or_insert_with(HashSet::new)
.insert(maintainer.clone());
}
}
bypkg
}
} }
impl std::fmt::Display for ImpactedMaintainers { impl std::fmt::Display for ImpactedMaintainers {

View file

@ -1,3 +1,4 @@
use crate::maintainers::{Maintainer, MaintainersByPackage};
use ofborg::outpathdiff::PackageArch; use ofborg::outpathdiff::PackageArch;
use ofborg::tasks; use ofborg::tasks;
use std::collections::HashMap; use std::collections::HashMap;
@ -269,15 +270,27 @@ impl MaintainerPRTagger {
Default::default() Default::default()
} }
pub fn record_maintainer(&mut self, pr_submitter: &str, identified_maintainers: &[String]) { pub fn record_maintainer(
let mut compare_to: Vec<String> = identified_maintainers.to_vec().clone(); &mut self,
compare_to.sort(); pr_submitter: &str,
compare_to.dedup(); identified_maintainers: &MaintainersByPackage,
) {
let submitter = Maintainer::from(pr_submitter);
if compare_to.len() == 1 && compare_to.contains(&pr_submitter.to_string()) { if identified_maintainers.0.is_empty() {
self.selected // No packages -> not from the maintainer
.push(String::from("11.by: package-maintainer")); return;
} }
for (_package, maintainers) in identified_maintainers.0.iter() {
if !maintainers.contains(&submitter) {
// One of the packages is not maintained by this submitter
return;
}
}
self.selected
.push(String::from("11.by: package-maintainer"));
} }
pub fn tags_to_add(&self) -> Vec<String> { pub fn tags_to_add(&self) -> Vec<String> {

View file

@ -572,7 +572,8 @@ impl<E: stats::SysEvents + 'static> worker::SimpleWorker for MassRebuildWorker<E
if let Ok(ref maint) = m { if let Ok(ref maint) = m {
request_reviews(&maint, &pull); request_reviews(&maint, &pull);
let mut maint_tagger = MaintainerPRTagger::new(); let mut maint_tagger = MaintainerPRTagger::new();
maint_tagger.record_maintainer(&issue.user.login, &maint.maintainers()); maint_tagger
.record_maintainer(&issue.user.login, &maint.maintainers_by_package());
update_labels( update_labels(
&issue_ref, &issue_ref,
&maint_tagger.tags_to_add(), &maint_tagger.tags_to_add(),