diff --git a/ofborg/src/lib.rs b/ofborg/src/lib.rs index 30620d1..39d73ff 100644 --- a/ofborg/src/lib.rs +++ b/ofborg/src/lib.rs @@ -29,6 +29,7 @@ pub mod ghevent; pub mod commentparser; pub mod commitstatus; pub mod outpathdiff; +pub mod tagger; pub mod ofborg { @@ -46,4 +47,5 @@ pub mod ofborg { pub use acl; pub use commentparser; pub use outpathdiff; + pub use tagger; } diff --git a/ofborg/src/tagger.rs b/ofborg/src/tagger.rs index 765b7aa..cfaf6f4 100644 --- a/ofborg/src/tagger.rs +++ b/ofborg/src/tagger.rs @@ -1,9 +1,83 @@ -struct Tagger { +pub struct RebuildTagger { possible: Vec, selected: Vec, } -impl Tagger { +impl RebuildTagger { + pub fn new() -> RebuildTagger { + let mut t = RebuildTagger { + possible: vec![ + String::from("10.rebuild-linux: 501+"), + String::from("10.rebuild-linux: 101-500"), + String::from("10.rebuild-linux: 11-100"), + String::from("10.rebuild-linux: 1-10"), + String::from("10.rebuild-linux: 0"), + String::from("10.rebuild-darwin: 501+"), + String::from("10.rebuild-darwin: 101-500"), + String::from("10.rebuild-darwin: 11-100"), + String::from("10.rebuild-darwin: 1-10"), + String::from("10.rebuild-darwin: 0"), + ], + selected: vec![], + }; + t.possible.sort(); + + return t; + } + + pub fn parse_attrs(&mut self, attrs: Vec) { + let mut counter_darwin = 0; + let mut counter_linux = 0; + + for attr in attrs { + match attr.rsplit(".").next() { + Some("x86_64-darwin") => { counter_darwin += 1; } + Some("x86_64-linux") => { counter_linux += 1; } + Some(arch) => { info!("Unknown arch: {:?}", arch); } + None => { info!("Cannot grok attr: {:?}", attr); } + } + } + + self.selected = vec![ + String::from(format!("10.rebuild-linux: {}", self.bucket(counter_linux))), + String::from(format!("10.rebuild-darwin: {}", self.bucket(counter_darwin))), + ]; + + for tag in &self.selected { + if !self.possible.contains(&tag) { + panic!("Tried to add label {} but it isn't in the possible list!", tag); + } + } + } + + pub fn tags_to_add(&self) -> Vec { + self.selected.clone() + } + + pub fn tags_to_remove(&self) -> Vec { + let mut remove = self.possible.clone(); + for tag in &self.selected { + let pos = remove.binary_search(&tag).unwrap(); + remove.remove(pos); + } + + return remove; + } + + fn bucket(&self, count: u64) -> &str{ + if count > 500 { + return "501+"; + } else if count > 100 { + return "101-500"; + } else if count > 10 { + return "11-100"; + } else if count > 0 { + return "1-10"; + } else { + return "0"; + } + + } } diff --git a/ofborg/src/tasks/massrebuilder.rs b/ofborg/src/tasks/massrebuilder.rs index cda1167..6d5b8de 100644 --- a/ofborg/src/tasks/massrebuilder.rs +++ b/ofborg/src/tasks/massrebuilder.rs @@ -13,6 +13,7 @@ use ofborg::message::massrebuildjob; use ofborg::nix; use ofborg::worker; +use ofborg::tagger::RebuildTagger; use ofborg::outpathdiff::OutPathDiff; use ofborg::evalchecker::EvalChecker; use ofborg::commitstatus::CommitStatus; @@ -288,14 +289,18 @@ impl worker::SimpleWorker for MassRebuildWorker { hubcaps::statuses::State::Pending ); - tagger = StdenvTagger::new(); + // let tagger = StdenvTagger::new(); if !stdenvs.are_same() { println!("Stdenvs changed? {:?}", stdenvs.changed()); } + let mut rebuildTags = RebuildTagger::new(); if let Some(attrs) = rebuildsniff.calculate_rebuild() { - bucketize_attrs(attrs) + tagger.parse_attrs(attrs); } + println!("New Tags: {:?}", tagger.tags_to_add()); + println!("Drop Tags: {:?}", tagger.tags_to_remove()); + overall_status.set_with_description( "^.^!",