Skip to content

Commit

Permalink
feat: support generic repos
Browse files Browse the repository at this point in the history
  • Loading branch information
kjuulh committed Mar 2, 2023
1 parent dbcb6e1 commit 07c845e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
12 changes: 9 additions & 3 deletions crates/gitevents_sdk/examples/action/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
4 changes: 2 additions & 2 deletions crates/gitevents_sdk/examples/generic_repo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected].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)
Expand Down
19 changes: 16 additions & 3 deletions crates/gitevents_sdk/src/git/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 3 additions & 1 deletion crates/gitevents_sdk/src/git/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 07c845e

Please sign in to comment.