mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 10:10:30 +08:00
Strongly type patch review verdict
Instead of typing a review verdict as `string | null` we should do `"accept" | "reject" | null`
This commit is contained in:
@@ -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 }
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
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>>;
|
||||
timestamp: number;
|
||||
|
||||
@@ -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>;
|
||||
};
|
||||
|
||||
@@ -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";
|
||||
@@ -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,9 +234,10 @@ 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)]
|
||||
@@ -252,7 +255,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 +272,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 +341,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 +355,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>,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user