feat(patch): Allows review tui to return optional action

This commit is contained in:
Erik Kundt
2025-02-12 11:49:56 +01:00
parent 3ab0da05d5
commit 335458de8b
2 changed files with 38 additions and 33 deletions
+30 -30
View File
@@ -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;
+8 -3
View File
@@ -49,7 +49,7 @@ pub struct Args(String);
#[derive(Clone, Debug)]
pub struct Response {
pub state: AppState,
pub action: ReviewAction,
pub action: Option<ReviewAction>,
}
#[derive(Clone)]
@@ -550,7 +550,7 @@ impl<'a> store::Update<Message> 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<Message> for App<'a> {
}
None
}
Message::Quit => Some(Exit { value: None }),
Message::Quit => Some(Exit {
value: Some(Response {
action: None,
state: self.state.clone(),
}),
}),
}
}
}