Radish alpha
r
rad:z4D5UCArafTzTQpDZNQRuqswh3ury
Radicle desktop app
Radicle
Git
Strongly type patch review verdict
Merged did:key:z6MkkfM3...sVz5 opened 1 year ago

Instead of typing a review verdict as string | null we should do "accept" | "reject" | null

  • Remove optional argument from review comments
7 files changed +60 -19 c2f38bb0 6da4ffe3
modified crates/radicle-types/bindings/cob/patch/Action.ts
@@ -1,6 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { CodeLocation } from "../thread/CodeLocation";
import type { Embed } from "../thread/Embed";
+
import type { Verdict } from "./Verdict";

export type Action =
  | { "type": "edit"; title: string; target: string }
@@ -12,14 +13,14 @@ export type Action =
    "type": "review";
    revision: string;
    summary?: string;
-
    verdict?: string;
+
    verdict?: Verdict;
    labels?: Array<string>;
  }
  | {
    "type": "review.edit";
    review: string;
    summary?: string;
-
    verdict?: string;
+
    verdict?: Verdict;
    labels?: Array<string>;
  }
  | { "type": "review.redact"; review: string }
modified crates/radicle-types/bindings/cob/patch/Review.ts
@@ -2,12 +2,13 @@
import type { Author } from "../Author";
import type { CodeLocation } from "../thread/CodeLocation";
import type { Comment } from "../thread/Comment";
+
import type { Verdict } from "./Verdict";

export type Review = {
  id: string;
  author: Author;
-
  verdict?: "accept" | "reject";
+
  verdict?: Verdict;
  summary?: string;
-
  comments?: Array<Comment<CodeLocation>>;
+
  comments: Array<Comment<CodeLocation>>;
  timestamp: number;
};
modified crates/radicle-types/bindings/cob/patch/ReviewEdit.ts
@@ -1,8 +1,9 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
+
import type { Verdict } from "./Verdict";

export type ReviewEdit = {
  reviewId: string;
-
  verdict?: string;
+
  verdict?: Verdict;
  summary?: string;
  labels?: Array<string>;
};
added crates/radicle-types/bindings/cob/patch/Verdict.ts
@@ -0,0 +1,3 @@
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
+

+
export type Verdict = "accept" | "reject";
modified crates/radicle-types/src/cobs/patch.rs
@@ -107,8 +107,10 @@ impl From<patch::State> for State {
pub struct ReviewEdit {
    #[ts(as = "String")]
    pub review_id: cob::patch::ReviewId,
-
    #[ts(as = "Option<String>", optional)]
-
    pub verdict: Option<cob::patch::Verdict>,
+
    #[serde(default, skip_serializing_if = "Option::is_none")]
+
    #[ts(optional)]
+
    pub verdict: Option<Verdict>,
+
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub summary: Option<String>,
    #[ts(as = "Option<Vec<String>>", optional)]
@@ -232,12 +234,12 @@ pub struct Review {
    #[ts(as = "String")]
    id: identity::PublicKey,
    author: cobs::Author,
-
    #[ts(type = "'accept' | 'reject'")]
+
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
-
    verdict: Option<cob::patch::Verdict>,
+
    verdict: Option<Verdict>,
+
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    summary: Option<String>,
-
    #[ts(as = "Option<_>", optional)]
    comments: Vec<cobs::thread::Comment<cobs::thread::CodeLocation>>,
    #[ts(type = "number")]
    timestamp: cob::common::Timestamp,
@@ -252,7 +254,7 @@ impl Review {
        Self {
            id,
            author: cobs::Author::new(&review.author().id, aliases),
-
            verdict: review.verdict(),
+
            verdict: review.verdict().map(|v| v.into()),
            summary: review.summary().map(|s| s.to_string()),
            comments: review
                .comments()
@@ -269,6 +271,33 @@ impl Review {
    }
}

+
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
+
#[serde(rename_all = "camelCase")]
+
#[ts(export)]
+
#[ts(export_to = "cob/patch/")]
+
pub enum Verdict {
+
    Accept,
+
    Reject,
+
}
+

+
impl From<cob::patch::Verdict> for Verdict {
+
    fn from(value: cob::patch::Verdict) -> Self {
+
        match value {
+
            cob::patch::Verdict::Accept => Self::Accept,
+
            cob::patch::Verdict::Reject => Self::Reject,
+
        }
+
    }
+
}
+

+
impl From<Verdict> for cob::patch::Verdict {
+
    fn from(value: Verdict) -> Self {
+
        match value {
+
            Verdict::Accept => Self::Accept,
+
            Verdict::Reject => Self::Reject,
+
        }
+
    }
+
}
+

#[derive(Serialize, Deserialize, TS)]
#[serde(tag = "type", rename_all = "camelCase")]
#[ts(export)]
@@ -311,8 +340,8 @@ pub enum Action {
        #[ts(optional)]
        summary: Option<String>,
        #[serde(default, skip_serializing_if = "Option::is_none")]
-
        #[ts(as = "Option<String>", optional)]
-
        verdict: Option<patch::Verdict>,
+
        #[ts(optional)]
+
        verdict: Option<Verdict>,
        #[serde(default, skip_serializing_if = "Vec::is_empty")]
        #[ts(as = "Option<Vec<String>>", optional)]
        labels: Vec<cob::Label>,
@@ -325,8 +354,8 @@ pub enum Action {
        #[ts(optional)]
        summary: Option<String>,
        #[serde(default, skip_serializing_if = "Option::is_none")]
-
        #[ts(as = "Option<String>", optional)]
-
        verdict: Option<patch::Verdict>,
+
        #[ts(optional)]
+
        verdict: Option<Verdict>,
        #[serde(default, skip_serializing_if = "Vec::is_empty")]
        #[ts(as = "Option<Vec<String>>", optional)]
        labels: Vec<cob::Label>,
modified crates/radicle-types/src/traits/patch.rs
@@ -161,7 +161,7 @@ pub trait PatchesMut: Profile {
                verdict,
                labels,
            } => {
-
                patch.review_edit(review, verdict, summary, labels, &signer)?;
+
                patch.review_edit(review, verdict.map(|v| v.into()), summary, labels, &signer)?;
            }
            cobs::patch::Action::Review {
                revision,
@@ -169,7 +169,13 @@ pub trait PatchesMut: Profile {
                verdict,
                labels,
            } => {
-
                patch.review(revision, verdict, summary, labels, &signer)?;
+
                patch.review(
+
                    revision,
+
                    verdict.map(|v| v.into()),
+
                    summary,
+
                    labels,
+
                    &signer,
+
                )?;
            }
            cobs::patch::Action::ReviewRedact { review } => {
                patch.redact_review(review, &signer)?;
@@ -329,7 +335,7 @@ pub trait PatchesMut: Profile {
        let mut patch = patches.get_mut(&cob_id.into())?;
        patch.review_edit(
            edit.review_id,
-
            edit.verdict,
+
            edit.verdict.map(|v| v.into()),
            edit.summary,
            edit.labels,
            &signer,
modified src/components/PatchTimeline.svelte
@@ -258,7 +258,7 @@
              {formatTimestamp(op.timestamp)}
            </div>
          </div>
-
        {:else}
+
        {:else if op.verdict === "reject"}
          <div class="icon" style:color="var(--color-foreground-red)">
            <Icon name="comment-cross" />
          </div>