feat: with cuddle please
Some checks failed
continuous-integration/drone/push Build is failing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2023-12-29 19:43:04 +01:00
parent 124aa93b98
commit 80b99c27a5
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
5 changed files with 68 additions and 19 deletions

1
Cargo.lock generated
View File

@ -326,6 +326,7 @@ version = "0.2.0"
dependencies = [
"async-trait",
"clap",
"dagger-cuddle-please",
"dagger-rust",
"dagger-sdk",
"eyre",

View File

@ -11,6 +11,7 @@ repository.workspace = true
[dependencies]
dagger-rust.workspace = true
dagger-cuddle-please.workspace = true
dagger-sdk.workspace = true
eyre.workspace = true

View File

@ -4,9 +4,9 @@ use async_trait::async_trait;
use tokio::sync::Mutex;
pub struct CuddleCI {
pr_action: Arc<Mutex<dyn PullRequestAction + Send + Sync>>,
main_action: Arc<Mutex<dyn MainAction + Send + Sync>>,
release_action: Arc<Mutex<dyn ReleaseAction + Send + Sync>>,
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>>>,
}
impl CuddleCI {
@ -16,9 +16,9 @@ impl CuddleCI {
release: Arc<Mutex<dyn ReleaseAction + Send + Sync>>,
) -> Self {
Self {
pr_action: pr,
main_action: main,
release_action: release,
pr_action: vec![pr],
main_action: vec![main],
release_action: vec![release],
}
}
@ -26,13 +26,13 @@ impl CuddleCI {
&mut self,
pr: Arc<Mutex<dyn PullRequestAction + Send + Sync>>,
) -> &mut Self {
self.pr_action = pr;
self.pr_action.push(pr);
self
}
pub fn with_main(&mut self, main: Arc<Mutex<dyn MainAction + Send + Sync>>) -> &mut Self {
self.main_action = main;
self.main_action.push(main);
self
}
@ -41,7 +41,7 @@ impl CuddleCI {
&mut self,
release: Arc<Mutex<dyn ReleaseAction + Send + Sync>>,
) -> &mut Self {
self.release_action = release;
self.release_action.push(release);
self
}
@ -62,17 +62,23 @@ impl CuddleCI {
Some((name, args)) => match (name, args) {
("pr", _args) => {
eprintln!("starting pr validate");
self.pr_action.lock().await.execute_pull_request().await?;
for pr_action in self.pr_action.iter() {
pr_action.lock().await.execute_pull_request().await?;
}
eprintln!("finished pr validate");
}
("main", _args) => {
eprintln!("starting main validate");
self.main_action.lock().await.execute_main().await?;
for main_action in self.main_action.iter() {
main_action.lock().await.execute_main().await?;
}
eprintln!("finished main validate");
}
("release", _args) => {
eprintln!("starting release validate");
self.release_action.lock().await.execute_release().await?;
for release_action in self.release_action.iter() {
release_action.lock().await.execute_release().await?;
}
eprintln!("finished release validate");
}
(command_name, _) => {
@ -110,15 +116,16 @@ impl PullRequestAction for DefaultPullRequestAction {}
#[async_trait]
pub trait MainAction {
async fn execute_main(&self) -> eyre::Result<()> {
eprintln!("validate main: noop");
Ok(())
}
async fn execute_main(&self) -> eyre::Result<()>;
}
pub struct DefaultMainAction {}
#[async_trait]
impl MainAction for DefaultMainAction {}
impl MainAction for DefaultMainAction {
async fn execute_main(&self) -> eyre::Result<()> {
Ok(())
}
}
#[async_trait]
pub trait ReleaseAction {

View File

@ -6,3 +6,43 @@ pub mod dagger_middleware;
pub mod node_service;
pub mod rust_lib;
pub mod rust_service;
pub mod cuddle_please {
use async_trait::async_trait;
use dagger_cuddle_please::{
models::CuddlePleaseSrcArgs, DaggerCuddlePlease, DaggerCuddlePleaseAction,
};
use crate::{MainAction, PullRequestAction};
pub struct CuddlePlease {
client: dagger_sdk::Query,
}
impl CuddlePlease {
pub fn new(client: dagger_sdk::Query) -> Self {
Self { client }
}
}
#[async_trait]
impl MainAction for CuddlePlease {
async fn execute_main(&self) -> eyre::Result<()> {
let client = self.client.clone();
let action = DaggerCuddlePlease::new(client);
action
.cuddle_please_src(&CuddlePleaseSrcArgs {
cuddle_image: "kasperhermansen/cuddle-please:latest".into(),
server: dagger_cuddle_please::models::SrcServer::Gitea {
token: std::env::var("CUDDLE_PLEASE_TOKEN")
.expect("CUDDLE_PLEASE_TOKEN to be present"),
},
log_level: Some(dagger_cuddle_please::models::LogLevel::Debug),
})
.await?;
Ok(())
}
}
}

View File

@ -1,4 +1,4 @@
use std::sync::{Arc};
use std::sync::Arc;
use models::{CuddlePleaseArgs, CuddlePleaseSrcArgs};
use traits::CuddlePlease;
@ -103,7 +103,7 @@ impl DaggerCuddlePleaseAction {
}
#[derive(Clone)]
struct DaggerCuddlePlease {
pub struct DaggerCuddlePlease {
client: dagger_sdk::Query,
}