From 3a47003578e33a1cf6dff40885325bbe66bcab35 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Tue, 15 Jul 2025 09:53:50 +0100 Subject: [PATCH] radicle: add ReviewEdit getter methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Downstream clients require access to the data for a `ReviewEdit` – for example, the desktop client builds a representation of `Action`s for TypeScript generation. To allow these kinds of use cases, methods are added to `ReviewEdit` to allow access to its underlying data. --- crates/radicle/src/cob/patch/actions.rs | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/crates/radicle/src/cob/patch/actions.rs b/crates/radicle/src/cob/patch/actions.rs index e5768f7b..67f6cfc1 100644 --- a/crates/radicle/src/cob/patch/actions.rs +++ b/crates/radicle/src/cob/patch/actions.rs @@ -59,6 +59,44 @@ impl ReviewEdit { } } + /// Get the summary of the [`ReviewEdit`]. + /// + /// The summary was optional in the first version, so it may be `None`. + pub fn summary(&self) -> Option<&String> { + match self { + ReviewEdit::V1(ReviewEditV1 { summary, .. }) => summary.as_ref(), + ReviewEdit::V2(ReviewEditV2 { summary, .. }) => Some(summary), + } + } + + /// Get the [`Verdict`] of the [`ReviewEdit`]. + pub fn verdict(&self) -> Option<&Verdict> { + match self { + ReviewEdit::V1(ReviewEditV1 { verdict, .. }) => verdict.as_ref(), + ReviewEdit::V2(ReviewEditV2 { verdict, .. }) => verdict.as_ref(), + } + } + + /// Get the list of [`Label`]s of the [`ReviewEdit`]. + pub fn labels(&self) -> &[Label] { + match self { + ReviewEdit::V1(ReviewEditV1 { labels, .. }) => labels, + ReviewEdit::V2(ReviewEditV2 { labels, .. }) => labels, + } + } + + /// Get the [`Embed`]s of the [`ReviewEdit`]. + /// + /// [`Embed`]s were introduced in the second version of edits. For this + /// reason, an [`Option`] is returned instead of a [`Vec`] – this allows to + /// avoid an unnecessary clone of the [`Vec`] when it is present. + pub fn embeds(&self) -> Option<&Vec>> { + match self { + ReviewEdit::V1(_) => None, + ReviewEdit::V2(ReviewEditV2 { embeds, .. }) => Some(embeds), + } + } + /// Apply the action to the given [`Patch`]. pub fn run( self,