fix(tui): update ui when push next or main finishes
Some checks failed
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
Rust / build (push) Failing after 6m48s

Removes the artificial pause while we wait for any CI to start before
checking the CI status.

Closes kemitix/git-next#160
This commit is contained in:
Paul Campbell 2024-09-06 15:36:17 +01:00
parent 35c2057f05
commit 4662ad47e4
9 changed files with 52 additions and 23 deletions

View file

@ -1,4 +1,6 @@
// //
#[cfg(feature = "forgejo")]
#[cfg(feature = "github")]
use super::*; use super::*;
use git_next_core::{ use git_next_core::{

View file

@ -1,7 +1,7 @@
// //
use actix::prelude::*; use actix::prelude::*;
use git_next_core::RepoConfigSource; use git_next_core::{git, RepoConfigSource};
use tracing::warn; use tracing::warn;
@ -35,18 +35,25 @@ impl Handler<AdvanceMain> for RepoActor {
commit: commit.clone(), commit: commit.clone(),
}); });
match advance_main(commit, &repo_details, &repo_config, &**open_repository) { if let Err(err) = advance_main(commit, &repo_details, &repo_config, &**open_repository) {
Err(err) => {
warn!("advance main: {err}"); 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 => { RepoConfigSource::Repo => {
do_send(&addr, LoadConfigFromRepo, self.log.as_ref()); do_send(&addr, LoadConfigFromRepo, self.log.as_ref());
} }
RepoConfigSource::Server => { RepoConfigSource::Server => {
do_send(&addr, ValidateRepo::new(message_token), self.log.as_ref()); do_send(&addr, ValidateRepo::new(message_token), self.log.as_ref());
} }
}, }
} }
} }
} }

View file

@ -1,6 +1,7 @@
// //
use actix::prelude::*; use actix::prelude::*;
use git_next_core::git;
use tracing::{warn, Instrument}; use tracing::{warn, Instrument};
use crate::{ use crate::{
@ -49,7 +50,12 @@ impl Handler<AdvanceNext> for RepoActor {
self.message_token, self.message_token,
) { ) {
Ok(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 sleep_duration = self.sleep_duration;
let log = self.log.clone(); let log = self.log.clone();
async move { async move {

View file

@ -99,8 +99,7 @@ impl RepoActor {
} }
fn update_tui_branches(&self) { fn update_tui_branches(&self) {
#[cfg(feature = "tui")] if cfg!(feature = "tui") {
{
use crate::server::actor::messages::RepoUpdate; use crate::server::actor::messages::RepoUpdate;
let Some(repo_config) = &self.repo_details.repo_config else { let Some(repo_config) = &self.repo_details.repo_config else {
return; return;
@ -112,16 +111,14 @@ impl RepoActor {
#[allow(unused_variables)] #[allow(unused_variables)]
fn update_tui_log(&self, log: git::graph::Log) { fn update_tui_log(&self, log: git::graph::Log) {
#[cfg(feature = "tui")] if cfg!(feature = "tui") {
{
self.update_tui(RepoUpdate::Log { log }); self.update_tui(RepoUpdate::Log { log });
} }
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn alert_tui(&self, alert: impl Into<String>) { fn alert_tui(&self, alert: impl Into<String>) {
#[cfg(feature = "tui")] if cfg!(feature = "tui") {
{
self.update_tui(RepoUpdate::Alert { self.update_tui(RepoUpdate::Alert {
alert: alert.into(), alert: alert.into(),
}); });
@ -130,8 +127,7 @@ impl RepoActor {
#[allow(unused_variables)] #[allow(unused_variables)]
fn update_tui(&self, repo_update: RepoUpdate) { fn update_tui(&self, repo_update: RepoUpdate) {
#[cfg(feature = "tui")] if cfg!(feature = "tui") {
{
let Some(server_addr) = &self.server_addr else { let Some(server_addr) = &self.server_addr else {
return; return;
}; };

View file

@ -25,6 +25,11 @@ async fn when_repo_config_should_fetch_then_push_then_revalidate() -> TestResult
.times(1) .times(1)
.in_sequence(&mut seq) .in_sequence(&mut seq)
.return_once(|_, _, _, _| Ok(())); .return_once(|_, _, _, _| Ok(()));
open_repository
.expect_fetch()
.times(1)
.in_sequence(&mut seq)
.return_once(|| Ok(()));
//when //when
let (addr, log) = when::start_actor_with_open_repository( 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) .times(1)
.in_sequence(&mut seq) .in_sequence(&mut seq)
.return_once(|_, _, _, _| Ok(())); .return_once(|_, _, _, _| Ok(()));
open_repository
.expect_fetch()
.times(1)
.in_sequence(&mut seq)
.return_once(|| Ok(()));
//when //when
let (addr, log) = when::start_actor_with_open_repository( 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 //then
tracing::debug!(?log, ""); tracing::debug!(?log, "");
log.read().map_err(|e| e.to_string()).map(|l| { log.require_message_containing("send: ValidateRepo")?;
assert!(l
.iter()
.any(|message| message.contains("send: ValidateRepo")));
})?;
Ok(()) Ok(())
} }

View file

@ -28,6 +28,11 @@ async fn should_fetch_then_push_then_revalidate() -> TestResult {
.times(1) .times(1)
.in_sequence(&mut seq) .in_sequence(&mut seq)
.return_once(|_, _, _, _| Ok(())); .return_once(|_, _, _, _| Ok(()));
open_repository
.expect_fetch()
.times(1)
.in_sequence(&mut seq)
.return_once(|| Ok(()));
//when //when
let (addr, log) = when::start_actor_with_open_repository( let (addr, log) = when::start_actor_with_open_repository(

View file

@ -92,6 +92,8 @@ pub enum RepoUpdate {
}, },
RegisteredWebhook, RegisteredWebhook,
Opened, Opened,
NextUpdated,
MainUpdated,
} }
message!( message!(

View file

@ -58,10 +58,16 @@ impl Handler<ServerUpdate> for Tui {
repo_state repo_state
.update_message(format!("advancing next to {commit}"), ACTING); .update_message(format!("advancing next to {commit}"), ACTING);
} }
RepoUpdate::NextUpdated => {
repo_state.update_message("next updated - pause while CI starts", OKAY);
}
RepoUpdate::AdvancingMain { commit } => { RepoUpdate::AdvancingMain { commit } => {
repo_state repo_state
.update_message(format!("advancing main to {commit}"), ACTING); .update_message(format!("advancing main to {commit}"), ACTING);
} }
RepoUpdate::MainUpdated => {
repo_state.update_message("main updated", OKAY);
}
RepoUpdate::Opening => { RepoUpdate::Opening => {
repo_state.update_message("opening...", PREP); repo_state.update_message("opening...", PREP);
} }

View file

@ -277,9 +277,8 @@ impl RepoState {
#[tracing::instrument] #[tracing::instrument]
pub fn clear_alert(&mut self) { pub fn clear_alert(&mut self) {
match self { if let Self::Ready { alert, .. } = self {
Self::Identified { .. } | Self::Configured { .. } => (), *alert = None;
Self::Ready { alert, .. } => *alert = None,
} }
} }