From 07c845e6b2581283b7162125dea3b077579002fd Mon Sep 17 00:00:00 2001 From: kjuulh Date: Thu, 2 Mar 2023 22:31:03 +0100 Subject: [PATCH] feat: support generic repos --- crates/gitevents_sdk/examples/action/main.rs | 12 +++++++++--- .../examples/generic_repo/main.rs | 4 ++-- crates/gitevents_sdk/src/git/generic.rs | 19 ++++++++++++++++--- crates/gitevents_sdk/src/git/mod.rs | 4 +++- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/crates/gitevents_sdk/examples/action/main.rs b/crates/gitevents_sdk/examples/action/main.rs index 87d8ad0..9cb9dd5 100644 --- a/crates/gitevents_sdk/examples/action/main.rs +++ b/crates/gitevents_sdk/examples/action/main.rs @@ -18,9 +18,15 @@ async fn main() -> eyre::Result<()> { .init(); let simulated_git = GitSimulated::new() - .insert(GitEvent {}) - .insert(GitEvent {}) - .insert(GitEvent {}); + .insert(GitEvent { + commit: "something1".into(), + }) + .insert(GitEvent { + commit: "something2".into(), + }) + .insert(GitEvent { + commit: "something3".into(), + }); gitevents_sdk::builder::Builder::new() .add_git_provider(Arc::new(Mutex::new(simulated_git))) diff --git a/crates/gitevents_sdk/examples/generic_repo/main.rs b/crates/gitevents_sdk/examples/generic_repo/main.rs index 2cfe508..5ab43d8 100644 --- a/crates/gitevents_sdk/examples/generic_repo/main.rs +++ b/crates/gitevents_sdk/examples/generic_repo/main.rs @@ -16,10 +16,10 @@ async fn main() -> eyre::Result<()> { .init(); gitevents_sdk::builder::Builder::new() - .set_generic_git_url("kjuulh/gitevents") + .set_generic_git_url("git@git.front.kjuulh.io:kjuulh/gitevents.git") .set_scheduler_opts(&SchedulerOpts { // Duration must not be lower than 1 second, otherwise async runtime won't proceed - duration: Duration::from_secs(1), + duration: Duration::from_secs(10), }) .action(|_req| async move { Ok(EventResponse {}) }) .action(other_action) diff --git a/crates/gitevents_sdk/src/git/generic.rs b/crates/gitevents_sdk/src/git/generic.rs index 6c6c8d4..e1f6c3d 100644 --- a/crates/gitevents_sdk/src/git/generic.rs +++ b/crates/gitevents_sdk/src/git/generic.rs @@ -80,9 +80,9 @@ impl GitProvider for GitGeneric { let revstr = rev?.to_string(); tracing::trace!(progress = &revstr, "storing progress"); dbg!(&revstr); - *p = revstr; + *p = revstr.clone(); - return Ok(Some(GitEvent {})); + return Ok(Some(GitEvent { commit: revstr })); } } None => { @@ -205,7 +205,20 @@ mod tests { assert!(event.is_some()); assert!(logs_contain("git pull finished")); assert!(logs_contain("err: git pull")); - assert!(logs_contain("storing progress123")); + assert!(logs_contain("storing progress")); + + let mut file_path3 = tempdir.clone(); + file_path3.push("readme3.md"); + write(file_path3, "Some file123").unwrap(); + + git_commit_all(&tempdir, "next commit 4").await.unwrap(); + + let event = git.listen().await.unwrap(); + + assert!(event.is_some()); + assert!(logs_contain("git pull finished")); + assert!(logs_contain("err: git pull")); + assert!(logs_contain("storing progress")); remove_dir_all(tempdir).await.unwrap(); } diff --git a/crates/gitevents_sdk/src/git/mod.rs b/crates/gitevents_sdk/src/git/mod.rs index 9e0f0a0..01e0661 100644 --- a/crates/gitevents_sdk/src/git/mod.rs +++ b/crates/gitevents_sdk/src/git/mod.rs @@ -4,7 +4,9 @@ pub mod simulated; use async_trait::async_trait; #[derive(Debug, Clone)] -pub struct GitEvent {} +pub struct GitEvent { + pub commit: String, +} #[async_trait] pub trait GitProvider {