diff --git a/ofborg/src/tasks/evaluate.rs b/ofborg/src/tasks/evaluate.rs index c377e94..f2ba7cb 100644 --- a/ofborg/src/tasks/evaluate.rs +++ b/ofborg/src/tasks/evaluate.rs @@ -59,6 +59,92 @@ impl EvaluationWorker { tag_paths, } } +} + +impl worker::SimpleWorker for EvaluationWorker { + type J = evaluationjob::EvaluationJob; + + fn msg_to_job( + &mut self, + _: &Deliver, + _: &BasicProperties, + body: &[u8], + ) -> Result { + self.events.notify(Event::JobReceived); + match evaluationjob::from(body) { + Ok(e) => { + self.events.notify(Event::JobDecodeSuccess); + Ok(e) + } + Err(e) => { + self.events.notify(Event::JobDecodeFailure); + error!( + "Failed to decode message: {:?}, Err: {:?}", + String::from_utf8(body.to_vec()), + e + ); + Err("Failed to decode message".to_owned()) + } + } + } + + fn consumer(&mut self, job: &evaluationjob::EvaluationJob) -> worker::Actions { + let mut vending_machine = self + .github_vend + .write() + .expect("Failed to get write lock on github vending machine"); + + let github_client = vending_machine + .for_repo(&job.repo.owner, &job.repo.name) + .expect("Failed to get a github client token"); + + OneEval::new( + github_client, + &self.github, + &self.nix, + &self.acl, + &mut self.events, + &self.identity, + &self.tag_paths, + &self.cloner, + ) + .evaluate_job(job) + } +} + +struct OneEval<'a, E> { + client_app: &'a hubcaps::Github, + client_legacy: &'a hubcaps::Github, + nix: &'a nix::Nix, + acl: &'a ACL, + events: &'a mut E, + identity: &'a str, + tag_paths: &'a HashMap>, + cloner: &'a checkout::CachedCloner, +} + +impl<'a, E: stats::SysEvents + 'static> OneEval<'a, E> { + fn new( + client_app: &'a hubcaps::Github, + client_legacy: &'a hubcaps::Github, + nix: &'a nix::Nix, + acl: &'a ACL, + events: &'a mut E, + identity: &'a str, + tag_paths: &'a HashMap>, + cloner: &'a checkout::CachedCloner, + ) -> OneEval<'a, E> { + OneEval { + client_app, + client_legacy, + nix, + acl, + events, + identity, + tag_paths, + cloner, + } + } fn actions(&self) -> evaluationjob::Actions { evaluationjob::Actions {} @@ -85,15 +171,10 @@ impl EvaluationWorker { } fn evaluate_job(&mut self, job: &evaluationjob::EvaluationJob) -> worker::Actions { - let mut vending_machine = self - .github_vend - .write() - .expect("Failed to get write lock on github vending machine"); - let github_client = vending_machine - .for_repo(&job.repo.owner, &job.repo.name) - .expect("Failed to get a github client token"); - let repo = github_client.repo(job.repo.owner.clone(), job.repo.name.clone()); - let gists = self.github.gists(); + let repo = self + .client_app + .repo(job.repo.owner.clone(), job.repo.name.clone()); + let gists = self.client_legacy.gists(); let pulls = repo.pulls(); let pull = pulls.get(job.pr.number); let issue_ref = repo.issue(job.pr.number); @@ -168,7 +249,7 @@ impl EvaluationWorker { info!("Working on {}", job.pr.number); let co = project - .clone_for("mr-est".to_string(), self.identity.clone()) + .clone_for("mr-est".to_string(), self.identity.to_string()) .unwrap(); let target_branch = match job.pr.target_branch.clone() { @@ -334,38 +415,6 @@ impl EvaluationWorker { } } -impl worker::SimpleWorker for EvaluationWorker { - type J = evaluationjob::EvaluationJob; - - fn msg_to_job( - &mut self, - _: &Deliver, - _: &BasicProperties, - body: &[u8], - ) -> Result { - self.events.notify(Event::JobReceived); - match evaluationjob::from(body) { - Ok(e) => { - self.events.notify(Event::JobDecodeSuccess); - Ok(e) - } - Err(e) => { - self.events.notify(Event::JobDecodeFailure); - error!( - "Failed to decode message: {:?}, Err: {:?}", - String::from_utf8(body.to_vec()), - e - ); - Err("Failed to decode message".to_owned()) - } - } - } - - fn consumer(&mut self, job: &evaluationjob::EvaluationJob) -> worker::Actions { - self.evaluate_job(job) - } -} - fn send_check_statuses(checks: Vec, repo: &hubcaps::repositories::Repository) { for check in checks { match repo.checkruns().create(&check) {