diff --git a/crates/cuddle-ci/src/cli.rs b/crates/cuddle-ci/src/cli.rs index f4df074..49d8500 100644 --- a/crates/cuddle-ci/src/cli.rs +++ b/crates/cuddle-ci/src/cli.rs @@ -1,16 +1,14 @@ use std::{ collections::BTreeMap, ops::{Deref, DerefMut}, - sync::Arc, }; use async_trait::async_trait; -use tokio::sync::Mutex; pub struct CuddleCI { - pr_action: Vec>>, - main_action: Vec>>, - release_action: Vec>>, + pr_action: Vec>, + main_action: Vec>, + release_action: Vec>, } #[derive(Default, Debug)] @@ -34,9 +32,9 @@ impl DerefMut for Context { impl CuddleCI { pub fn new( - pr: Arc>, - main: Arc>, - release: Arc>, + pr: Box, + main: Box, + release: Box, ) -> Self { Self { pr_action: vec![pr], @@ -45,25 +43,27 @@ impl CuddleCI { } } - pub fn with_pull_request( - &mut self, - pr: T, - ) -> &mut Self { - self.pr_action.push(Arc::new(Mutex::new(pr))); + pub fn with_pull_request(&mut self, pr: T) -> &mut Self + where + T: PullRequestAction + ToOwned + Send + Sync + 'static, + T: ToOwned, + { + self.pr_action.push(Box::new(pr.to_owned())); self } - pub fn with_main(&mut self, main: T) -> &mut Self { - self.main_action.push(Arc::new(Mutex::new(main))); + pub fn with_main(&mut self, main: T) -> &mut Self + where + T: MainAction + Send + Sync + 'static, + T: ToOwned, + { + self.main_action.push(Box::new(main)); self } - pub fn with_release( - &mut self, - release: Arc>, - ) -> &mut Self { + pub fn with_release(&mut self, release: Box) -> &mut Self { self.release_action.push(release); self @@ -88,29 +88,21 @@ impl CuddleCI { ("pr", _args) => { eprintln!("starting pr validate"); for pr_action in self.pr_action.iter() { - pr_action - .lock() - .await - .execute_pull_request(&mut context) - .await?; + pr_action.execute_pull_request(&mut context).await?; } eprintln!("finished pr validate"); } ("main", _args) => { eprintln!("starting main validate"); for main_action in self.main_action.iter() { - main_action.lock().await.execute_main(&mut context).await?; + main_action.execute_main(&mut context).await?; } eprintln!("finished main validate"); } ("release", _args) => { eprintln!("starting release validate"); for release_action in self.release_action.iter() { - release_action - .lock() - .await - .execute_release(&mut context) - .await?; + release_action.execute_release(&mut context).await?; } eprintln!("finished release validate"); } @@ -128,9 +120,9 @@ impl CuddleCI { impl Default for CuddleCI { fn default() -> Self { Self::new( - Arc::new(Mutex::new(DefaultPullRequestAction {})), - Arc::new(Mutex::new(DefaultMainAction {})), - Arc::new(Mutex::new(DefaultReleaseAction {})), + Box::new(DefaultPullRequestAction {}), + Box::new(DefaultMainAction {}), + Box::new(DefaultReleaseAction {}), ) } }