Radish alpha
r
rad:z39mP9rQAaGmERfUMPULfPUi473tY
Radicle terminal user interface
Radicle
Git
feat(patch): Allows review tui to return optional action
Erik Kundt committed 1 year ago
commit 335458de8b8d2ed3dfe20de941b449a10b9d90c0
parent 3ab0da0
2 files changed +41 -36
modified 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"))?;
-

-
                        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)?;
-

-
                            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");
-
                        }
+
                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);
+

+
                    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");
                    }
+
                } else {
+
                    break;
                }
            } else {
                break;
modified 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<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(),
+
                }),
+
            }),
        }
    }
}