From 4662ad47e49544661eb0233e70cc16fe562f18df Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 6 Sep 2024 15:36:17 +0100 Subject: [PATCH] fix(tui): update ui when push next or main finishes Removes the artificial pause while we wait for any CI to start before checking the CI status. Closes kemitix/git-next#160 --- crates/cli/src/forge/tests.rs | 2 ++ crates/cli/src/repo/handlers/advance_main.rs | 19 +++++++++++++------ crates/cli/src/repo/handlers/advance_next.rs | 8 +++++++- crates/cli/src/repo/mod.rs | 12 ++++-------- .../src/repo/tests/handlers/advance_main.rs | 16 +++++++++++----- .../src/repo/tests/handlers/advance_next.rs | 5 +++++ crates/cli/src/server/actor/messages.rs | 2 ++ .../src/tui/actor/handlers/server_update.rs | 6 ++++++ crates/cli/src/tui/actor/model.rs | 5 ++--- 9 files changed, 52 insertions(+), 23 deletions(-) diff --git a/crates/cli/src/forge/tests.rs b/crates/cli/src/forge/tests.rs index e71c7e7..b1efaea 100644 --- a/crates/cli/src/forge/tests.rs +++ b/crates/cli/src/forge/tests.rs @@ -1,4 +1,6 @@ // +#[cfg(feature = "forgejo")] +#[cfg(feature = "github")] use super::*; use git_next_core::{ diff --git a/crates/cli/src/repo/handlers/advance_main.rs b/crates/cli/src/repo/handlers/advance_main.rs index f1d2adc..1c18485 100644 --- a/crates/cli/src/repo/handlers/advance_main.rs +++ b/crates/cli/src/repo/handlers/advance_main.rs @@ -1,7 +1,7 @@ // use actix::prelude::*; -use git_next_core::RepoConfigSource; +use git_next_core::{git, RepoConfigSource}; use tracing::warn; @@ -35,18 +35,25 @@ impl Handler for RepoActor { commit: commit.clone(), }); - match advance_main(commit, &repo_details, &repo_config, &**open_repository) { - Err(err) => { - warn!("advance main: {err}"); + if let Err(err) = advance_main(commit, &repo_details, &repo_config, &**open_repository) { + warn!("advance main: {err}"); + self.alert_tui(format!("advance main: {err}")); + } else { + self.update_tui(RepoUpdate::MainUpdated); + if let Some(open_repository) = &self.open_repository { + match open_repository.fetch() { + Ok(()) => self.update_tui_log(git::graph::log(&self.repo_details)), + Err(err) => self.alert_tui(format!("fetching: {err}")), + } } - Ok(()) => match repo_config.source() { + match repo_config.source() { RepoConfigSource::Repo => { do_send(&addr, LoadConfigFromRepo, self.log.as_ref()); } RepoConfigSource::Server => { do_send(&addr, ValidateRepo::new(message_token), self.log.as_ref()); } - }, + } } } } diff --git a/crates/cli/src/repo/handlers/advance_next.rs b/crates/cli/src/repo/handlers/advance_next.rs index 2951601..e4908e8 100644 --- a/crates/cli/src/repo/handlers/advance_next.rs +++ b/crates/cli/src/repo/handlers/advance_next.rs @@ -1,6 +1,7 @@ // use actix::prelude::*; +use git_next_core::git; use tracing::{warn, Instrument}; use crate::{ @@ -49,7 +50,12 @@ impl Handler for RepoActor { self.message_token, ) { Ok(message_token) => { - // pause to allow any CI checks to be started + self.update_tui(RepoUpdate::NextUpdated); + match open_repository.fetch() { + Ok(()) => self.update_tui_log(git::graph::log(&self.repo_details)), + Err(err) => self.alert_tui(format!("fetching: {err}")), + } + // INFO: pause to allow any CI checks to be started let sleep_duration = self.sleep_duration; let log = self.log.clone(); async move { diff --git a/crates/cli/src/repo/mod.rs b/crates/cli/src/repo/mod.rs index 391ba1a..f60ec51 100644 --- a/crates/cli/src/repo/mod.rs +++ b/crates/cli/src/repo/mod.rs @@ -99,8 +99,7 @@ impl RepoActor { } fn update_tui_branches(&self) { - #[cfg(feature = "tui")] - { + if cfg!(feature = "tui") { use crate::server::actor::messages::RepoUpdate; let Some(repo_config) = &self.repo_details.repo_config else { return; @@ -112,16 +111,14 @@ impl RepoActor { #[allow(unused_variables)] fn update_tui_log(&self, log: git::graph::Log) { - #[cfg(feature = "tui")] - { + if cfg!(feature = "tui") { self.update_tui(RepoUpdate::Log { log }); } } #[allow(unused_variables)] fn alert_tui(&self, alert: impl Into) { - #[cfg(feature = "tui")] - { + if cfg!(feature = "tui") { self.update_tui(RepoUpdate::Alert { alert: alert.into(), }); @@ -130,8 +127,7 @@ impl RepoActor { #[allow(unused_variables)] fn update_tui(&self, repo_update: RepoUpdate) { - #[cfg(feature = "tui")] - { + if cfg!(feature = "tui") { let Some(server_addr) = &self.server_addr else { return; }; diff --git a/crates/cli/src/repo/tests/handlers/advance_main.rs b/crates/cli/src/repo/tests/handlers/advance_main.rs index e166ffa..2f89656 100644 --- a/crates/cli/src/repo/tests/handlers/advance_main.rs +++ b/crates/cli/src/repo/tests/handlers/advance_main.rs @@ -25,6 +25,11 @@ async fn when_repo_config_should_fetch_then_push_then_revalidate() -> TestResult .times(1) .in_sequence(&mut seq) .return_once(|_, _, _, _| Ok(())); + open_repository + .expect_fetch() + .times(1) + .in_sequence(&mut seq) + .return_once(|| Ok(())); //when let (addr, log) = when::start_actor_with_open_repository( @@ -70,6 +75,11 @@ async fn when_app_config_should_fetch_then_push_then_revalidate() -> TestResult .times(1) .in_sequence(&mut seq) .return_once(|_, _, _, _| Ok(())); + open_repository + .expect_fetch() + .times(1) + .in_sequence(&mut seq) + .return_once(|| Ok(())); //when let (addr, log) = when::start_actor_with_open_repository( @@ -83,10 +93,6 @@ async fn when_app_config_should_fetch_then_push_then_revalidate() -> TestResult //then tracing::debug!(?log, ""); - log.read().map_err(|e| e.to_string()).map(|l| { - assert!(l - .iter() - .any(|message| message.contains("send: ValidateRepo"))); - })?; + log.require_message_containing("send: ValidateRepo")?; Ok(()) } diff --git a/crates/cli/src/repo/tests/handlers/advance_next.rs b/crates/cli/src/repo/tests/handlers/advance_next.rs index 4a681c7..6570be8 100644 --- a/crates/cli/src/repo/tests/handlers/advance_next.rs +++ b/crates/cli/src/repo/tests/handlers/advance_next.rs @@ -28,6 +28,11 @@ async fn should_fetch_then_push_then_revalidate() -> TestResult { .times(1) .in_sequence(&mut seq) .return_once(|_, _, _, _| Ok(())); + open_repository + .expect_fetch() + .times(1) + .in_sequence(&mut seq) + .return_once(|| Ok(())); //when let (addr, log) = when::start_actor_with_open_repository( diff --git a/crates/cli/src/server/actor/messages.rs b/crates/cli/src/server/actor/messages.rs index a6ba308..ca98552 100644 --- a/crates/cli/src/server/actor/messages.rs +++ b/crates/cli/src/server/actor/messages.rs @@ -92,6 +92,8 @@ pub enum RepoUpdate { }, RegisteredWebhook, Opened, + NextUpdated, + MainUpdated, } message!( diff --git a/crates/cli/src/tui/actor/handlers/server_update.rs b/crates/cli/src/tui/actor/handlers/server_update.rs index ebaee6d..d82963f 100644 --- a/crates/cli/src/tui/actor/handlers/server_update.rs +++ b/crates/cli/src/tui/actor/handlers/server_update.rs @@ -58,10 +58,16 @@ impl Handler for Tui { repo_state .update_message(format!("advancing next to {commit}"), ACTING); } + RepoUpdate::NextUpdated => { + repo_state.update_message("next updated - pause while CI starts", OKAY); + } RepoUpdate::AdvancingMain { commit } => { repo_state .update_message(format!("advancing main to {commit}"), ACTING); } + RepoUpdate::MainUpdated => { + repo_state.update_message("main updated", OKAY); + } RepoUpdate::Opening => { repo_state.update_message("opening...", PREP); } diff --git a/crates/cli/src/tui/actor/model.rs b/crates/cli/src/tui/actor/model.rs index cdd4c43..524e4cf 100644 --- a/crates/cli/src/tui/actor/model.rs +++ b/crates/cli/src/tui/actor/model.rs @@ -277,9 +277,8 @@ impl RepoState { #[tracing::instrument] pub fn clear_alert(&mut self) { - match self { - Self::Identified { .. } | Self::Configured { .. } => (), - Self::Ready { alert, .. } => *alert = None, + if let Self::Ready { alert, .. } = self { + *alert = None; } }