mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-11-21 02:20:48 +08:00
feat(patch): Allows review tui to return optional action
This commit is contained in:
+30
-30
@@ -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;
|
||||
|
||||
@@ -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(),
|
||||
}),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user