Tag added/removed packages on PRs

If packages (by name attribute and architecture) are present in the
first eval and absent in the second eval, mark it as having cleanup.

If packages (by name attribute and architecture) are absent in the
first eval and present in the second eval, mark it as having a new
package.

Note, though, that the generic "has cleanup" tag is too generic to
automatically remove it if ofborg thinks it isn't true.

Closes #63
This commit is contained in:
Graham Christensen 2018-02-09 22:23:37 -05:00
parent 55e869e539
commit cf3941741b
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C
3 changed files with 67 additions and 2 deletions

View file

@ -1,7 +1,7 @@
extern crate amqp;
extern crate env_logger;
use std::collections::HashMap;
use std::collections::{HashSet, HashMap};
use std::fs::File;
use std::fs;
use std::io::BufRead;
@ -58,6 +58,23 @@ impl OutPathDiff {
}
}
pub fn package_diff(&self) -> Option<(Vec<PackageArch>, Vec<PackageArch>)> {
if let Some(ref cur) = self.current {
if let Some(ref orig) = self.original {
let orig_set: HashSet<&PackageArch> = orig.keys().collect();
let cur_set: HashSet<&PackageArch> = cur.keys().collect();
let removed: Vec<PackageArch> = orig_set.difference(&cur_set).map(|ref p| (**p).clone()).collect();
let added: Vec<PackageArch> = cur_set.difference(&orig_set).map(|ref p| (**p).clone()).collect();
return Some((removed, added));
} else {
return None;
}
} else {
return None;
}
}
pub fn calculate_rebuild(self) -> Option<Vec<PackageArch>> {
let mut rebuild: Vec<PackageArch> = vec![];

View file

@ -58,6 +58,44 @@ impl StdenvTagger {
}
}
pub struct PkgsAddedRemovedTagger {
possible: Vec<String>,
selected: Vec<String>,
}
impl PkgsAddedRemovedTagger {
pub fn new() -> PkgsAddedRemovedTagger {
let mut t = PkgsAddedRemovedTagger {
possible: vec![
String::from("8.has: package (new)"),
String::from("8.has: clean-up"),
],
selected: vec![],
};
t.possible.sort();
return t;
}
pub fn changed(&mut self, removed: Vec<PackageArch>, added: Vec<PackageArch>) {
if removed.len() > 0 {
self.selected.push(String::from("8.has: clean-up"));
}
if added.len() > 0 {
self.selected.push(String::from("8.has: package (new)"));
}
}
pub fn tags_to_add(&self) -> Vec<String> {
self.selected.clone()
}
pub fn tags_to_remove(&self) -> Vec<String> {
// The cleanup tag is too vague to automatically remove.
return vec![];
}
}
pub struct RebuildTagger {
possible: Vec<String>,

View file

@ -15,7 +15,7 @@ use ofborg::nix::Nix;
use ofborg::acl::ACL;
use ofborg::stats;
use ofborg::worker;
use ofborg::tagger::{StdenvTagger, RebuildTagger, PathsTagger};
use ofborg::tagger::{StdenvTagger, RebuildTagger, PathsTagger, PkgsAddedRemovedTagger};
use ofborg::outpathdiff::{OutPaths, OutPathDiff};
use ofborg::evalchecker::EvalChecker;
use ofborg::commitstatus::CommitStatus;
@ -464,6 +464,16 @@ impl<E: stats::SysEvents> worker::SimpleWorker for MassRebuildWorker<E> {
stdenvtagger.tags_to_remove(),
);
if let Some((removed, added)) = rebuildsniff.package_diff() {
let mut addremovetagger = PkgsAddedRemovedTagger::new();
addremovetagger.changed(removed, added);
update_labels(
&issue,
addremovetagger.tags_to_add(),
addremovetagger.tags_to_remove(),
);
}
let mut rebuild_tags = RebuildTagger::new();
if let Some(attrs) = rebuildsniff.calculate_rebuild() {
let gist_url = make_gist(