refactor: flatten nested blocks with early returns
All checks were successful
Rust / build (push) Successful in 5m52s
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
Release Please / Release-plz (push) Successful in 1m4s

This commit is contained in:
Paul Campbell 2024-09-01 07:18:05 +01:00
parent f475095f4a
commit ca70c03e8b
7 changed files with 106 additions and 99 deletions

View file

@ -18,7 +18,9 @@ impl Handler<NotifyUser> for AlertsActor {
};
let net = self.net.clone();
let shout = shout.clone();
if let Some(user_notification) = self.history.sendable(msg.peel()) {
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;
@ -37,4 +39,3 @@ impl Handler<NotifyUser> for AlertsActor {
.wait(ctx);
}
}
}

View file

@ -12,7 +12,9 @@ impl Handler<UnRegisterWebhook> 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() {
let Some(webhook_id) = self.webhook_id.take() else {
return;
};
self.update_tui(RepoUpdate::UnregisteringWebhook);
let forge = self.forge.duplicate();
debug!("unregistering webhook");
@ -28,4 +30,3 @@ impl Handler<UnRegisterWebhook> for RepoActor {
debug!("unregistering webhook done");
}
}
}

View file

@ -59,8 +59,12 @@ impl Tui {
fn handle_input(&mut self, ctx: &mut <Self as actix::Actor>::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 {
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();
@ -85,8 +89,6 @@ impl Tui {
_ => (),
}
}
}
}
Ok(())
}
}

View file

@ -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::{

View file

@ -56,7 +56,8 @@ lazy_static::lazy_static! {
}
impl From<LogLine> for Line<'_> {
fn from(value: LogLine) -> Self {
if let Some(caps) = RE.captures(&value.raw) {
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();
@ -88,12 +89,14 @@ impl From<LogLine> for Line<'_> {
spans.push(message.into());
Line::from(spans)
}
} else {
}
None => {
// non-commit line
Line::from(value.raw.clone())
}
}
}
}
#[cfg(test)]
mod tests {

View file

@ -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"))
)),
}
}

View file

@ -24,12 +24,13 @@ pub async fn unregister(
None,
network::NetRequestLogging::None,
);
let result = net.delete(request).await;
if let Err(e) = result {
match net.delete(request).await {
Err(e) => {
tracing::warn!("Failed to unregister webhook");
return Err(git::forge::webhook::Error::FailedToUnregister(
Err(git::forge::webhook::Error::FailedToUnregister(
e.to_string(),
));
))
}
_ => Ok(()),
}
Ok(())
}