diff --git a/crates/radicle-tauri/src/commands/cob/patch.rs b/crates/radicle-tauri/src/commands/cob/patch.rs index f38ecb574..d015e45ec 100644 --- a/crates/radicle-tauri/src/commands/cob/patch.rs +++ b/crates/radicle-tauri/src/commands/cob/patch.rs @@ -30,9 +30,9 @@ pub async fn list_patches( ) -> Result>, Error> { let profile = ctx.profile(); let aliases = profile.aliases(); - let delegates = Vec::from(profile.storage.repository(rid)?.delegates()?); + let doc = profile.storage.repository(rid)?.identity_doc()?; - Ok(sqlite_service.list_paginated(rid, status, skip, take, &delegates, &aliases)?) + Ok(sqlite_service.list_paginated(rid, status, skip, take, &doc, &aliases)?) } #[tauri::command] diff --git a/crates/radicle-types/bindings/cob/patch/Action.ts b/crates/radicle-types/bindings/cob/patch/Action.ts index 8c57991b9..aa1c8959e 100644 --- a/crates/radicle-types/bindings/cob/patch/Action.ts +++ b/crates/radicle-types/bindings/cob/patch/Action.ts @@ -5,7 +5,7 @@ import type { Embed } from "../thread/Embed"; import type { Verdict } from "./Verdict"; export type Action = - | { "type": "edit"; title: string; target: string } + | { "type": "edit"; title: string; target: "delegates" | { branch: string } } | { "type": "label"; labels: Array } | { "type": "lifecycle"; state: { status: "draft" | "open" | "archived" } } | { "type": "assign"; assignees: Array } diff --git a/crates/radicle-types/bindings/cob/patch/Patch.ts b/crates/radicle-types/bindings/cob/patch/Patch.ts index 42e7fc818..0bd4e3422 100644 --- a/crates/radicle-types/bindings/cob/patch/Patch.ts +++ b/crates/radicle-types/bindings/cob/patch/Patch.ts @@ -10,6 +10,7 @@ export type Patch = { base: string; head: string; state: State; + targetBranch?: string; assignees: Array; labels: Array; timestamp: number; diff --git a/crates/radicle-types/src/domain/patch/models/patch.rs b/crates/radicle-types/src/domain/patch/models/patch.rs index df169de64..832219924 100644 --- a/crates/radicle-types/src/domain/patch/models/patch.rs +++ b/crates/radicle-types/src/domain/patch/models/patch.rs @@ -54,6 +54,9 @@ pub struct Patch { #[ts(as = "String")] head: git::Oid, state: State, + #[serde(default, skip_serializing_if = "Option::is_none")] + #[ts(optional)] + target_branch: Option, assignees: Vec, #[ts(as = "Vec")] labels: Vec, @@ -80,7 +83,7 @@ impl Patch { pub fn new( id: patch::PatchId, patch: &patch::Patch, - delegates: &[radicle::identity::Did], + doc: &radicle::identity::Doc, aliases: &impl AliasStore, ) -> Self { // Every review on every revision, so the patch list can render the same @@ -88,6 +91,7 @@ impl Patch { // tell a review of the current head from one left behind by a later // push — see the outdated handling in `reviewSummary`. It follows // `patch.revisions()`, the timeline order `revision_ids` also uses. + let delegates = doc.delegates(); let reviewers = patch .revisions() .enumerate() @@ -110,6 +114,10 @@ impl Patch { author: cobs::Author::new(patch.author().id(), aliases), title: patch.title().to_string(), state: patch.state().clone().into(), + target_branch: patch + .merge_target_branch(doc) + .map(|branch| branch.to_string()) + .ok(), base: *patch.base(), head: *patch.head(), assignees: patch @@ -373,7 +381,7 @@ pub enum Action { #[serde(rename = "edit")] Edit { title: String, - #[ts(as = "String")] + #[ts(type = "\"delegates\" | { branch: string }")] target: patch::MergeTarget, }, #[serde(rename = "label")] diff --git a/crates/radicle-types/src/domain/patch/traits.rs b/crates/radicle-types/src/domain/patch/traits.rs index 803577d80..2d35590dc 100644 --- a/crates/radicle-types/src/domain/patch/traits.rs +++ b/crates/radicle-types/src/domain/patch/traits.rs @@ -52,7 +52,7 @@ pub trait PatchService { status: Option, skip: Option, take: Option, - delegates: &[identity::Did], + doc: &identity::Doc, aliases: &impl AliasStore, ) -> Result>, models::patch::ListPatchesError> { @@ -60,9 +60,8 @@ pub trait PatchService { None => Box::new(self.list(rid)?), Some(status) => Box::new(self.list_by_status(rid, status.into())?), }; - let summary = |(id, patch): (PatchId, Patch)| { - models::patch::Patch::new(id, &patch, delegates, aliases) - }; + let summary = + |(id, patch): (PatchId, Patch)| models::patch::Patch::new(id, &patch, doc, aliases); match take { None => Ok(cobs::PaginatedQuery { diff --git a/crates/radicle-types/src/traits/patch.rs b/crates/radicle-types/src/traits/patch.rs index b029c24ff..1f064ad08 100644 --- a/crates/radicle-types/src/traits/patch.rs +++ b/crates/radicle-types/src/traits/patch.rs @@ -22,9 +22,9 @@ pub trait Patches: Profile { let patches = profile.patches(&repo)?; let patch = patches.get(&id.into())?; let aliases = &profile.aliases(); - let delegates = Vec::from(repo.delegates()?); + let doc = repo.identity_doc()?; let patches = - patch.map(|patch| models::patch::Patch::new(id.into(), &patch, &delegates, aliases)); + patch.map(|patch| models::patch::Patch::new(id.into(), &patch, &doc, aliases)); Ok::<_, Error>(patches) } @@ -143,7 +143,11 @@ pub trait PatchesMut: Profile { models::patch::Action::ReviewCommentUnresolve { review, comment } => { patch.unresolve_review_comment(review, comment)?; } - models::patch::Action::Edit { title, target } => { + models::patch::Action::Edit { title, target: _ } => { + // Honouring the client's target would retarget a patch + // opened against a non-default branch; `rad patch edit` + // carries it forward too. + let target = patch.target().clone(); patch.edit(Title::try_from(title)?, target)?; } models::patch::Action::ReviewEdit { @@ -281,12 +285,12 @@ pub trait PatchesMut: Profile { log::error!("Not able to announce changes: {}", e) } - let delegates = Vec::from(repo.delegates()?); + let doc = repo.identity_doc()?; Ok::<_, Error>(models::patch::Patch::new( *patch.id(), &patch, - &delegates, + &doc, &aliases, )) } diff --git a/crates/test-http-api/src/api.rs b/crates/test-http-api/src/api.rs index abbdde224..ff4ba24fb 100644 --- a/crates/test-http-api/src/api.rs +++ b/crates/test-http-api/src/api.rs @@ -638,10 +638,10 @@ async fn patches_handler( }): Json, ) -> impl IntoResponse { let aliases = ctx.profile.aliases(); - let delegates = Vec::from(ctx.profile.storage.repository(rid)?.delegates()?); + let doc = ctx.profile.storage.repository(rid)?.identity_doc()?; let page = ctx .patches - .list_paginated(rid, status, skip, take, &delegates, &aliases)?; + .list_paginated(rid, status, skip, take, &doc, &aliases)?; Ok::<_, Error>(Json(page)) }