From 68005d757d919a48bca3ac9d76583b9d98e3f89a Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 30 Jun 2024 16:54:26 +0100 Subject: [PATCH] fix: start validating repo after registering webhook Clone Repo wasn't sending the second message, so workaround: have it be sent after registering the webhook. --- crates/repo-actor/README.md | 3 +- crates/repo-actor/src/handlers/clone_repo.rs | 5 -- .../src/handlers/webhook_registered.rs | 7 ++- .../src/tests/handlers/clone_repo.rs | 51 ------------------- .../src/tests/handlers/webhook_registered.rs | 26 ++++++++++ 5 files changed, 33 insertions(+), 59 deletions(-) diff --git a/crates/repo-actor/README.md b/crates/repo-actor/README.md index 2fddd0b..631ea69 100644 --- a/crates/repo-actor/README.md +++ b/crates/repo-actor/README.md @@ -21,12 +21,11 @@ ReceiveCIStatus --> [*] :on Fail AdvanceNext --> ValidateRepo -ReceiveRepoConfig --> ValidateRepo ReceiveRepoConfig --> RegisterWebhook RegisterWebhook --> WebhookRegistered -WebhookRegistered --> [*] +WebhookRegistered --> ValidateRepo AdvanceMain --> LoadConfigFromRepo :on repo config AdvanceMain --> ValidateRepo :on server config diff --git a/crates/repo-actor/src/handlers/clone_repo.rs b/crates/repo-actor/src/handlers/clone_repo.rs index a5ff362..6fa143c 100644 --- a/crates/repo-actor/src/handlers/clone_repo.rs +++ b/crates/repo-actor/src/handlers/clone_repo.rs @@ -32,11 +32,6 @@ impl Handler for actor::RepoActor { actor::messages::RegisterWebhook::new(), &self.log, ); - actor::do_send( - ctx.address(), - actor::messages::ValidateRepo::new(self.message_token), - &self.log, - ); } } Err(err) => { diff --git a/crates/repo-actor/src/handlers/webhook_registered.rs b/crates/repo-actor/src/handlers/webhook_registered.rs index f11ff2b..398f56e 100644 --- a/crates/repo-actor/src/handlers/webhook_registered.rs +++ b/crates/repo-actor/src/handlers/webhook_registered.rs @@ -9,9 +9,14 @@ impl Handler for actor::RepoActor { fn handle( &mut self, msg: actor::messages::WebhookRegistered, - _ctx: &mut Self::Context, + ctx: &mut Self::Context, ) -> Self::Result { self.webhook_id.replace(msg.webhook_id().clone()); self.webhook_auth.replace(msg.webhook_auth().clone()); + actor::do_send( + ctx.address(), + actor::messages::ValidateRepo::new(self.message_token), + &self.log, + ); } } diff --git a/crates/repo-actor/src/tests/handlers/clone_repo.rs b/crates/repo-actor/src/tests/handlers/clone_repo.rs index 8b8c1ce..3c1ac02 100644 --- a/crates/repo-actor/src/tests/handlers/clone_repo.rs +++ b/crates/repo-actor/src/tests/handlers/clone_repo.rs @@ -1,5 +1,4 @@ // - use super::*; #[actix::test] @@ -105,31 +104,6 @@ async fn when_server_has_no_repo_config_should_send_load_from_repo() -> TestResu Ok(()) } -/// The server config can optionally include the names of the main, next and dev -/// branches. When it does we should go straight to sending a [ValidateRepo] message. -#[actix::test] -async fn when_server_has_repo_config_should_send_validate_repo() -> TestResult { - //given - let fs = given::a_filesystem(); - let (mut open_repository, repo_details) = given::an_open_repository(&fs); - #[allow(clippy::unwrap_used)] - given::has_all_valid_remote_defaults(&mut open_repository, &repo_details); - - let mut repository_factory = MockRepositoryFactory::new(); - expect::open_repository(&mut repository_factory, open_repository); - fs.dir_create(&repo_details.gitdir)?; - - //when - let (addr, log) = when::start_actor(repository_factory, repo_details, given::a_forge()); - addr.send(CloneRepo::new()).await?; - System::current().stop(); - - //then - log.require_message_containing("send: ValidateRepo")?; - - Ok(()) -} - /// The server config can optionally include the names of the main, next and dev /// branches. When it does we should register the webhook by sending [RegisterWebhook] message. #[actix::test] @@ -212,28 +186,3 @@ async fn opened_repo_with_no_default_fetch_should_not_proceed() -> TestResult { Ok(()) } - -#[test_log::test(actix::test)] -async fn valid_repo_with_default_remotes_should_assess_branch_positions() -> TestResult { - //given - let fs = given::a_filesystem(); - let (mut open_repository, repo_details) = given::an_open_repository(&fs); - - given::has_all_valid_remote_defaults(&mut open_repository, &repo_details); - - let mut repository_factory = MockRepositoryFactory::new(); - expect::open_repository(&mut repository_factory, open_repository); - fs.dir_create(&repo_details.gitdir)?; - - //when - let (addr, log) = when::start_actor(repository_factory, repo_details, given::a_forge()); - addr.send(CloneRepo::new()).await?; - System::current().stop(); - - //then - log.read() - .map_err(|e| e.to_string()) - .map(|l| assert!(l.iter().any(|l| l.contains("send: ValidateRepo"))))?; - - Ok(()) -} diff --git a/crates/repo-actor/src/tests/handlers/webhook_registered.rs b/crates/repo-actor/src/tests/handlers/webhook_registered.rs index 3be9b43..69d0321 100644 --- a/crates/repo-actor/src/tests/handlers/webhook_registered.rs +++ b/crates/repo-actor/src/tests/handlers/webhook_registered.rs @@ -28,3 +28,29 @@ async fn should_store_webhook_details() -> TestResult { assert_eq!(view.webhook_auth, Some(webhook_auth)); Ok(()) } + +#[actix::test] +async fn should_send_validate_repo_message() -> TestResult { + //given + let fs = given::a_filesystem(); + let (open_repository, repo_details) = given::an_open_repository(&fs); + let webhook_id = given::a_webhook_id(); + let webhook_auth = given::a_webhook_auth(); + + //when + let (addr, log) = when::start_actor_with_open_repository( + Box::new(open_repository), + repo_details, + given::a_forge(), + ); + addr.send(actor::messages::WebhookRegistered::new(( + webhook_id.clone(), + webhook_auth.clone(), + ))) + .await?; + System::current().stop(); + + //then + log.require_message_containing("send: ValidateRepo")?; + Ok(()) +}