diff --git a/crates/cli/src/alerts/handlers/notify_user.rs b/crates/cli/src/alerts/handlers/notify_user.rs index 6717bd9..ea1b3a5 100644 --- a/crates/cli/src/alerts/handlers/notify_user.rs +++ b/crates/cli/src/alerts/handlers/notify_user.rs @@ -18,23 +18,24 @@ impl Handler for AlertsActor { }; let net = self.net.clone(); let shout = shout.clone(); - if let Some(user_notification) = self.history.sendable(msg.peel()) { - async move { - if let Some(webhook_config) = shout.webhook() { - send_webhook(&user_notification, webhook_config, &net).await; - } - if let Some(email_config) = shout.email() { - send_email(&user_notification, email_config); - } - if let Some(desktop) = shout.desktop() { - if desktop { - send_desktop_notification(&user_notification); - } + let Some(user_notification) = self.history.sendable(msg.peel()) else { + return; + }; + async move { + if let Some(webhook_config) = shout.webhook() { + send_webhook(&user_notification, webhook_config, &net).await; + } + if let Some(email_config) = shout.email() { + send_email(&user_notification, email_config); + } + if let Some(desktop) = shout.desktop() { + if desktop { + send_desktop_notification(&user_notification); } } - .in_current_span() - .into_actor(self) - .wait(ctx); } + .in_current_span() + .into_actor(self) + .wait(ctx); } } diff --git a/crates/cli/src/repo/handlers/unregister_webhook.rs b/crates/cli/src/repo/handlers/unregister_webhook.rs index fcc7725..c071b2c 100644 --- a/crates/cli/src/repo/handlers/unregister_webhook.rs +++ b/crates/cli/src/repo/handlers/unregister_webhook.rs @@ -12,20 +12,21 @@ impl Handler for RepoActor { type Result = (); fn handle(&mut self, _msg: UnRegisterWebhook, ctx: &mut Self::Context) -> Self::Result { - if let Some(webhook_id) = self.webhook_id.take() { - self.update_tui(RepoUpdate::UnregisteringWebhook); - let forge = self.forge.duplicate(); - debug!("unregistering webhook"); - async move { - match forge.unregister_webhook(&webhook_id).await { - Ok(()) => debug!("unregistered webhook"), - Err(err) => warn!(?err, "unregistering webhook"), - } + let Some(webhook_id) = self.webhook_id.take() else { + return; + }; + self.update_tui(RepoUpdate::UnregisteringWebhook); + let forge = self.forge.duplicate(); + debug!("unregistering webhook"); + async move { + match forge.unregister_webhook(&webhook_id).await { + Ok(()) => debug!("unregistered webhook"), + Err(err) => warn!(?err, "unregistering webhook"), } - .in_current_span() - .into_actor(self) - .wait(ctx); - debug!("unregistering webhook done"); } + .in_current_span() + .into_actor(self) + .wait(ctx); + debug!("unregistering webhook done"); } } diff --git a/crates/cli/src/tui/actor/mod.rs b/crates/cli/src/tui/actor/mod.rs index dc894d6..a156031 100644 --- a/crates/cli/src/tui/actor/mod.rs +++ b/crates/cli/src/tui/actor/mod.rs @@ -59,32 +59,34 @@ impl Tui { fn handle_input(&mut self, ctx: &mut ::Context) -> std::io::Result<()> { if event::poll(std::time::Duration::from_millis(16))? { - if let event::Event::Key(key) = event::read()? { - if key.kind == KeyEventKind::Press { - match key.code { - KeyCode::Char('q') => { - ctx.stop(); - if let Err(err) = self.signal_shutdown.send(()) { - tracing::error!(?err, "Failed to signal shutdown"); - } - } - KeyCode::Char('j') | KeyCode::Down => self.scroll_view_state.scroll_down(), - KeyCode::Char('k') | KeyCode::Up => self.scroll_view_state.scroll_up(), - KeyCode::Char('f') | KeyCode::PageDown => { - self.scroll_view_state.scroll_page_down(); - } - KeyCode::Char('b') | KeyCode::PageUp => { - self.scroll_view_state.scroll_page_up(); - } - KeyCode::Char('g') | KeyCode::Home => { - self.scroll_view_state.scroll_to_top(); - } - KeyCode::Char('G') | KeyCode::End => { - self.scroll_view_state.scroll_to_bottom(); - } - _ => (), + let event::Event::Key(key) = event::read()? else { + return Ok(()); + }; + if key.kind != KeyEventKind::Press { + return Ok(()); + } + match key.code { + KeyCode::Char('q') => { + ctx.stop(); + if let Err(err) = self.signal_shutdown.send(()) { + tracing::error!(?err, "Failed to signal shutdown"); } } + KeyCode::Char('j') | KeyCode::Down => self.scroll_view_state.scroll_down(), + KeyCode::Char('k') | KeyCode::Up => self.scroll_view_state.scroll_up(), + KeyCode::Char('f') | KeyCode::PageDown => { + self.scroll_view_state.scroll_page_down(); + } + KeyCode::Char('b') | KeyCode::PageUp => { + self.scroll_view_state.scroll_page_up(); + } + KeyCode::Char('g') | KeyCode::Home => { + self.scroll_view_state.scroll_to_top(); + } + KeyCode::Char('G') | KeyCode::End => { + self.scroll_view_state.scroll_to_bottom(); + } + _ => (), } } Ok(()) diff --git a/crates/cli/src/tui/components/forge/expanded.rs b/crates/cli/src/tui/components/forge/expanded.rs index 0f3faf9..cc254c2 100644 --- a/crates/cli/src/tui/components/forge/expanded.rs +++ b/crates/cli/src/tui/components/forge/expanded.rs @@ -5,7 +5,7 @@ use git_next_core::{ForgeAlias, RepoAlias}; use ratatui::{ buffer::Buffer, layout::{Alignment, Direction, Layout, Rect}, - widgets::{block::Title, Block, Borders, Widget}, + widgets::{block::Title, Block, Widget}, }; use crate::tui::{ diff --git a/crates/cli/src/tui/components/history.rs b/crates/cli/src/tui/components/history.rs index 8e702f9..f18f270 100644 --- a/crates/cli/src/tui/components/history.rs +++ b/crates/cli/src/tui/components/history.rs @@ -56,41 +56,44 @@ lazy_static::lazy_static! { } impl From for Line<'_> { fn from(value: LogLine) -> Self { - if let Some(caps) = RE.captures(&value.raw) { - let pre = caps["pre"].to_owned(); - let hash = caps["hash"].to_owned(); - let message = caps["message"].to_owned(); - let mut branches = BRANCHES - .captures_iter(&caps["branches"]) - .map(|captures| captures["branch"].to_owned()) - .filter(|branch| branch != "HEAD") - .collect::>(); - if branches.is_empty() { - // line without branches - Line::from(vec![ - pre.into(), - " ".into(), - hash.into(), - " ".into(), - message.into(), - ]) - } else { - // line withbranches - let mut spans = vec![pre.into(), " ".into(), hash.into(), " ".into()]; - branches.sort(); - branches - .into_iter() - .map(|branch| format!("({branch})")) - .map(Span::from) - .map(|span| span.style(Style::default().fg(Color::White).bg(Color::Blue))) - .for_each(|span| spans.push(span)); - spans.push(" ".into()); - spans.push(message.into()); - Line::from(spans) + match RE.captures(&value.raw) { + Some(caps) => { + let pre = caps["pre"].to_owned(); + let hash = caps["hash"].to_owned(); + let message = caps["message"].to_owned(); + let mut branches = BRANCHES + .captures_iter(&caps["branches"]) + .map(|captures| captures["branch"].to_owned()) + .filter(|branch| branch != "HEAD") + .collect::>(); + if branches.is_empty() { + // line without branches + Line::from(vec![ + pre.into(), + " ".into(), + hash.into(), + " ".into(), + message.into(), + ]) + } else { + // line withbranches + let mut spans = vec![pre.into(), " ".into(), hash.into(), " ".into()]; + branches.sort(); + branches + .into_iter() + .map(|branch| format!("({branch})")) + .map(Span::from) + .map(|span| span.style(Style::default().fg(Color::White).bg(Color::Blue))) + .for_each(|span| spans.push(span)); + spans.push(" ".into()); + spans.push(message.into()); + Line::from(spans) + } + } + None => { + // non-commit line + Line::from(value.raw.clone()) } - } else { - // non-commit line - Line::from(value.raw.clone()) } } } diff --git a/crates/core/src/git/validation/positions.rs b/crates/core/src/git/validation/positions.rs index bdd953b..3c3411c 100644 --- a/crates/core/src/git/validation/positions.rs +++ b/crates/core/src/git/validation/positions.rs @@ -122,18 +122,17 @@ fn reset_next_to_main( next: &git::Commit, next_branch: &BranchName, ) -> Error { - if let Err(err) = git::push::reset( + match git::push::reset( open_repository, repo_details, next_branch, &main.clone().into(), &git::push::Force::From(next.clone().into()), ) { - Error::NonRetryable(format!( + Ok(()) => Error::Retryable(format!("Branch {next_branch} has been reset")), + Err(err) => Error::NonRetryable(format!( "Failed to reset branch '{next_branch}' to commit '{next}': {err}" - )) - } else { - Error::Retryable(format!("Branch {next_branch} has been reset")) + )), } } diff --git a/crates/forge-forgejo/src/webhook/unregister.rs b/crates/forge-forgejo/src/webhook/unregister.rs index 135b260..c07a5f6 100644 --- a/crates/forge-forgejo/src/webhook/unregister.rs +++ b/crates/forge-forgejo/src/webhook/unregister.rs @@ -24,12 +24,13 @@ pub async fn unregister( None, network::NetRequestLogging::None, ); - let result = net.delete(request).await; - if let Err(e) = result { - tracing::warn!("Failed to unregister webhook"); - return Err(git::forge::webhook::Error::FailedToUnregister( - e.to_string(), - )); + match net.delete(request).await { + Err(e) => { + tracing::warn!("Failed to unregister webhook"); + Err(git::forge::webhook::Error::FailedToUnregister( + e.to_string(), + )) + } + _ => Ok(()), } - Ok(()) }