feat: now with to owned as well
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
20ea9fd3c6
commit
8690a06aa4
@ -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<Arc<Mutex<dyn PullRequestAction + Send + Sync>>>,
|
||||
main_action: Vec<Arc<Mutex<dyn MainAction + Send + Sync>>>,
|
||||
release_action: Vec<Arc<Mutex<dyn ReleaseAction + Send + Sync>>>,
|
||||
pr_action: Vec<Box<dyn PullRequestAction + Send + Sync>>,
|
||||
main_action: Vec<Box<dyn MainAction + Send + Sync>>,
|
||||
release_action: Vec<Box<dyn ReleaseAction + Send + Sync>>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
@ -34,9 +32,9 @@ impl DerefMut for Context {
|
||||
|
||||
impl CuddleCI {
|
||||
pub fn new(
|
||||
pr: Arc<Mutex<dyn PullRequestAction + Send + Sync>>,
|
||||
main: Arc<Mutex<dyn MainAction + Send + Sync>>,
|
||||
release: Arc<Mutex<dyn ReleaseAction + Send + Sync>>,
|
||||
pr: Box<dyn PullRequestAction + Send + Sync>,
|
||||
main: Box<dyn MainAction + Send + Sync>,
|
||||
release: Box<dyn ReleaseAction + Send + Sync>,
|
||||
) -> Self {
|
||||
Self {
|
||||
pr_action: vec![pr],
|
||||
@ -45,25 +43,27 @@ impl CuddleCI {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_pull_request<T: PullRequestAction + Send + Sync + 'static>(
|
||||
&mut self,
|
||||
pr: T,
|
||||
) -> &mut Self {
|
||||
self.pr_action.push(Arc::new(Mutex::new(pr)));
|
||||
pub fn with_pull_request<T>(&mut self, pr: T) -> &mut Self
|
||||
where
|
||||
T: PullRequestAction + ToOwned + Send + Sync + 'static,
|
||||
T: ToOwned<Owned = T>,
|
||||
{
|
||||
self.pr_action.push(Box::new(pr.to_owned()));
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_main<T: MainAction + Send + Sync + 'static>(&mut self, main: T) -> &mut Self {
|
||||
self.main_action.push(Arc::new(Mutex::new(main)));
|
||||
pub fn with_main<T>(&mut self, main: T) -> &mut Self
|
||||
where
|
||||
T: MainAction + Send + Sync + 'static,
|
||||
T: ToOwned<Owned = T>,
|
||||
{
|
||||
self.main_action.push(Box::new(main));
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_release(
|
||||
&mut self,
|
||||
release: Arc<Mutex<dyn ReleaseAction + Send + Sync>>,
|
||||
) -> &mut Self {
|
||||
pub fn with_release(&mut self, release: Box<dyn ReleaseAction + Send + Sync>) -> &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 {}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user