From 335458de8b8d2ed3dfe20de941b449a10b9d90c0 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Tue, 11 Feb 2025 15:29:56 +0100 Subject: [PATCH] feat(patch): Allows review tui to return optional action --- bin/commands/patch.rs | 60 ++++++++++++++++++------------------ bin/commands/patch/review.rs | 11 +++++-- 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/bin/commands/patch.rs b/bin/commands/patch.rs index 5bb86c4b..d62fa7ff 100644 --- a/bin/commands/patch.rs +++ b/bin/commands/patch.rs @@ -424,40 +424,40 @@ mod interface { log::debug!("Received response from TUI: {:?}", response); if let Some(response) = response.as_ref() { - match response.action { - ReviewAction::Comment => { - let hunk = response - .state - .selected_hunk() - .ok_or_else(|| anyhow!("expected a selected hunk"))?; - let item = hunks - .get(hunk) - .ok_or_else(|| anyhow!("expected a hunk to comment on"))?; + if let Some(ReviewAction::Comment) = response.action { + let hunk = response + .state + .selected_hunk() + .ok_or_else(|| anyhow!("expected a selected hunk"))?; + let item = hunks + .get(hunk) + .ok_or_else(|| anyhow!("expected a hunk to comment on"))?; - let (old, new) = item.paths(); - let path = old.or(new); + let (old, new) = item.paths(); + let path = old.or(new); - if let (Some(hunk), Some((path, _))) = (item.hunk(), path) { - let builder = CommentBuilder::new(revision.head(), path.to_path_buf()); - let comments = builder.edit(hunk)?; + if let (Some(hunk), Some((path, _))) = (item.hunk(), path) { + let builder = CommentBuilder::new(revision.head(), path.to_path_buf()); + let comments = builder.edit(hunk)?; - let signer = profile.signer()?; - patch.transaction("Review comments", &signer, |tx| { - for comment in comments { - tx.review_comment( - review_id, - comment.body, - Some(comment.location), - None, // Not a reply. - vec![], // No embeds. - )?; - } - Ok(()) - })?; - } else { - log::warn!("Commenting on binary blobs is not yet implemented"); - } + let signer = profile.signer()?; + patch.transaction("Review comments", &signer, |tx| { + for comment in comments { + tx.review_comment( + review_id, + comment.body, + Some(comment.location), + None, // Not a reply. + vec![], // No embeds. + )?; + } + Ok(()) + })?; + } else { + log::warn!("Commenting on binary blobs is not yet implemented"); } + } else { + break; } } else { break; diff --git a/bin/commands/patch/review.rs b/bin/commands/patch/review.rs index 78745464..25b0b1ac 100644 --- a/bin/commands/patch/review.rs +++ b/bin/commands/patch/review.rs @@ -49,7 +49,7 @@ pub struct Args(String); #[derive(Clone, Debug)] pub struct Response { pub state: AppState, - pub action: ReviewAction, + pub action: Option, } #[derive(Clone)] @@ -550,7 +550,7 @@ impl<'a> store::Update for App<'a> { } Message::Comment => Some(Exit { value: Some(Response { - action: ReviewAction::Comment, + action: Some(ReviewAction::Comment), state: self.state.clone(), }), }), @@ -568,7 +568,12 @@ impl<'a> store::Update for App<'a> { } None } - Message::Quit => Some(Exit { value: None }), + Message::Quit => Some(Exit { + value: Some(Response { + action: None, + state: self.state.clone(), + }), + }), } } }