From 293ca1f9a62ab7fbc7a5a7cac3411ae9e1c1d4cb Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Tue, 1 Jan 2019 17:00:41 -0500 Subject: [PATCH] Extract calculate to its own fuction --- ofborg/src/maintainers.rs | 45 +++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/ofborg/src/maintainers.rs b/ofborg/src/maintainers.rs index 3660a2a..cceff92 100644 --- a/ofborg/src/maintainers.rs +++ b/ofborg/src/maintainers.rs @@ -1,4 +1,6 @@ +use ofborg::nix::Nix; use std::collections::HashMap; +use std::path::Path; #[derive(Deserialize, Debug, Eq, PartialEq)] struct ImpactedMaintainers(HashMap>); @@ -17,12 +19,34 @@ impl<'a> From<&'a str> for Package { } } +impl ImpactedMaintainers { + pub fn calculate( + nix: &Nix, + checkout: &Path, + paths: &[String], + attributes: &[Vec<&str>], + ) -> ImpactedMaintainers { + let pathstr = serde_json::to_string(&paths).unwrap(); + let attrstr = serde_json::to_string(&attributes).unwrap(); + + let mut argstrs: HashMap<&str, &str> = HashMap::new(); + argstrs.insert("changedattrsjson", &attrstr); + argstrs.insert("changedpathsjson", &pathstr); + + let ret = nix + .safely_evaluate_expr_cmd(&checkout, include_str!("./maintainers.nix"), argstrs) + .output() + .unwrap(); + + serde_json::from_str(&String::from_utf8(ret.stdout).unwrap()).unwrap() + } +} + #[cfg(test)] mod tests { use super::*; use checkout::cached_cloner; use clone::GitClonable; - use ofborg::nix::Nix; use ofborg::test_scratch::TestScratch; use std::env; use std::ffi::OsStr; @@ -76,26 +100,11 @@ mod tests { working_co.checkout_ref(&OsStr::new(&hash)).unwrap(); - let pathstr = serde_json::to_string(&paths).unwrap(); - let attrstr = serde_json::to_string(&attributes).unwrap(); - - let mut argstrs: HashMap<&str, &str> = HashMap::new(); - argstrs.insert("changedattrsjson", &attrstr); - argstrs.insert("changedpathsjson", &pathstr); - let remote = env::var("NIX_REMOTE").unwrap_or("".to_owned()); let nix = Nix::new("x86_64-linux".to_owned(), remote, 1800, None); - let ret = nix - .safely_evaluate_expr_cmd( - &working_co.clone_to(), - include_str!("./maintainers.nix"), - argstrs, - ) - .output() - .expect(":)"); - let parsed: ImpactedMaintainers = - serde_json::from_str(&String::from_utf8(ret.stdout).unwrap()).unwrap(); + let parsed = + ImpactedMaintainers::calculate(&nix, &working_co.clone_to(), &paths, &attributes); let mut expect = ImpactedMaintainers(HashMap::new()); expect.0.insert(