mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 14:20:42 +08:00
Remove usage of DraftStore
@fintan: The API of the DraftStore needs some improvement and it can be easy to do the wrong thing when trying to publish the changes to the published cob reference Based on this PSA we should apply any changes to the patch revisions directly, instead of using the `DraftStore`
This commit is contained in:
@@ -12,7 +12,6 @@ use tauri_plugin_dialog::DialogExt;
|
||||
|
||||
use crate::AppState;
|
||||
|
||||
pub mod draft;
|
||||
pub mod issue;
|
||||
pub mod patch;
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
use radicle::cob;
|
||||
use radicle::git;
|
||||
use radicle::identity;
|
||||
|
||||
use radicle_types::error::Error;
|
||||
use radicle_types::traits::cobs::Cobs;
|
||||
|
||||
use crate::AppState;
|
||||
|
||||
/// Puts a draft of a Collaborative Object (COB) out of the draft state by updating the reference to the new object ID (OID).
|
||||
///
|
||||
/// The function updates the reference for the provided `type_name` (e.g., patch, issue) to point to the
|
||||
/// new object ID (OID) associated with the finalized draft, removing it from the draft store.
|
||||
#[tauri::command]
|
||||
pub fn publish_draft(
|
||||
ctx: tauri::State<AppState>,
|
||||
rid: identity::RepoId,
|
||||
cob_id: git::Oid,
|
||||
type_name: cob::TypeName,
|
||||
) -> Result<(), Error> {
|
||||
ctx.publish_draft(rid, cob_id, type_name)
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
use radicle::cob;
|
||||
use radicle::git;
|
||||
use radicle::identity;
|
||||
use radicle::patch;
|
||||
use radicle::patch::{Action, TYPENAME};
|
||||
|
||||
use radicle_types as types;
|
||||
@@ -81,56 +79,6 @@ pub fn revision_by_patch_and_id(
|
||||
ctx.revision_by_id(rid, id, revision_id)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn create_draft_review(
|
||||
ctx: tauri::State<AppState>,
|
||||
rid: identity::RepoId,
|
||||
revision_id: cob::patch::RevisionId,
|
||||
cob_id: git::Oid,
|
||||
labels: Vec<cob::Label>,
|
||||
) -> Result<patch::ReviewId, Error> {
|
||||
ctx.create_draft_review(rid, revision_id, cob_id, labels)
|
||||
}
|
||||
|
||||
/// Creates a new review comment on a draft review for a specific patch.
|
||||
///
|
||||
/// This Tauri command is used to add a comment to an existing draft review in a repository.
|
||||
/// It allows users to comment on a specific location in the code or leave general feedback
|
||||
/// on a review that belongs to a specific patch.
|
||||
#[tauri::command]
|
||||
pub fn create_draft_review_comment(
|
||||
ctx: tauri::State<AppState>,
|
||||
rid: identity::RepoId,
|
||||
cob_id: git::Oid,
|
||||
new: types::cobs::thread::CreateReviewComment,
|
||||
) -> Result<(), Error> {
|
||||
ctx.create_draft_review_comment(rid, cob_id, new)
|
||||
}
|
||||
|
||||
/// Edits a draft review for a specific patch revision in a repository.
|
||||
///
|
||||
/// This Tauri command allows users to edit a draft review for a specific patch review.
|
||||
/// The draft is associated with the user (signer) and the provided patch revision within the repository.
|
||||
#[tauri::command]
|
||||
pub fn edit_draft_review(
|
||||
ctx: tauri::State<AppState>,
|
||||
rid: identity::RepoId,
|
||||
cob_id: git::Oid,
|
||||
edit: models::patch::ReviewEdit,
|
||||
) -> Result<(), Error> {
|
||||
ctx.edit_draft_review(rid, cob_id, edit)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_draft_review(
|
||||
ctx: tauri::State<AppState>,
|
||||
rid: identity::RepoId,
|
||||
cob_id: git::Oid,
|
||||
revision_id: patch::RevisionId,
|
||||
) -> Option<models::patch::Review> {
|
||||
ctx.get_draft_review(rid, cob_id, revision_id)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn edit_patch(
|
||||
ctx: tauri::State<AppState>,
|
||||
|
||||
@@ -110,11 +110,6 @@ pub fn run() {
|
||||
cob::patch::edit_patch,
|
||||
cob::patch::revisions_by_patch,
|
||||
cob::patch::revision_by_patch_and_id,
|
||||
cob::patch::create_draft_review,
|
||||
cob::patch::create_draft_review_comment,
|
||||
cob::patch::get_draft_review,
|
||||
cob::patch::edit_draft_review,
|
||||
cob::draft::publish_draft,
|
||||
thread::create_issue_comment,
|
||||
thread::create_patch_comment,
|
||||
profile::config,
|
||||
|
||||
@@ -7,7 +7,6 @@ use radicle::node::{Alias, AliasStore};
|
||||
|
||||
pub mod diff;
|
||||
pub mod issue;
|
||||
pub mod patch;
|
||||
pub mod stream;
|
||||
pub mod thread;
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use radicle::cob::object::Storage;
|
||||
use radicle::storage::refs::draft;
|
||||
use radicle::storage::{self, ReadStorage};
|
||||
use radicle::storage::ReadStorage;
|
||||
use radicle::{cob, git, identity};
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
@@ -39,37 +37,4 @@ pub trait Cobs: Profile {
|
||||
|
||||
Ok::<_, Error>(ops)
|
||||
}
|
||||
|
||||
fn publish_draft(
|
||||
&self,
|
||||
rid: identity::RepoId,
|
||||
cob_id: git::Oid,
|
||||
type_name: cob::TypeName,
|
||||
) -> Result<(), Error> {
|
||||
let profile = self.profile();
|
||||
let signer = profile.signer()?;
|
||||
let repo = profile.storage.repository(rid)?;
|
||||
let draft_oid = repo.backend.refname_to_id(&draft::cob(
|
||||
signer.public_key(),
|
||||
&type_name,
|
||||
&cob_id.into(),
|
||||
))?;
|
||||
repo.update(
|
||||
signer.public_key(),
|
||||
&type_name,
|
||||
&cob_id.into(),
|
||||
&draft_oid.into(),
|
||||
)?;
|
||||
|
||||
let mut patches = profile.patches_mut(&repo)?;
|
||||
patches.write(&cob_id.into())?;
|
||||
|
||||
storage::git::cob::DraftStore::new(&repo, *signer.public_key()).remove(
|
||||
signer.public_key(),
|
||||
&type_name,
|
||||
&cob_id.into(),
|
||||
)?;
|
||||
|
||||
Ok::<_, Error>(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use radicle::node::Handle;
|
||||
use radicle::patch::cache::Patches as _;
|
||||
use radicle::storage;
|
||||
use radicle::storage::ReadStorage;
|
||||
use radicle::{cob, git, identity, patch, Node};
|
||||
use radicle::{git, identity, Node};
|
||||
|
||||
use crate::cobs;
|
||||
use crate::domain::patch::models;
|
||||
@@ -253,138 +252,4 @@ pub trait PatchesMut: Profile {
|
||||
|
||||
Ok::<_, Error>(models::patch::Patch::new(*patch.id(), &patch, &aliases))
|
||||
}
|
||||
|
||||
/// Gets the draft review of the local user for a specific patch revision in a repository.
|
||||
///
|
||||
/// This Tauri command is used to retrieve a patch review draft for the local user
|
||||
/// on a given patch revision from a repository.
|
||||
/// It looks up the repository using the provided repository ID (`rid`) and patch object ID (`cob_id`),
|
||||
/// and gets the patch review of the local user associated with a specific revision (`revision_id`), if it exists.
|
||||
fn get_draft_review(
|
||||
&self,
|
||||
rid: identity::RepoId,
|
||||
cob_id: git::Oid,
|
||||
revision_id: patch::RevisionId,
|
||||
) -> Option<models::patch::Review> {
|
||||
let profile = self.profile();
|
||||
let aliases = profile.aliases();
|
||||
let repo = profile.storage.repository(rid).ok()?;
|
||||
let signer = profile.signer().ok()?;
|
||||
let drafts = storage::git::cob::DraftStore::new(&repo, *signer.public_key());
|
||||
let patches = cob::patch::Cache::no_cache(&drafts).ok()?;
|
||||
|
||||
let patch = patches.get(&cob_id.into()).ok()?;
|
||||
let revision = patch.and_then(|p| p.revision(&revision_id).cloned());
|
||||
let review: Option<patch::Review> =
|
||||
revision.and_then(|rev| rev.review_by(signer.public_key()).cloned());
|
||||
|
||||
review.map(|r| models::patch::Review::new(r, &aliases))
|
||||
}
|
||||
|
||||
/// Edits a draft review for a specific patch revision in a repository.
|
||||
///
|
||||
/// This Tauri command allows users to edit a draft review for a specific patch review.
|
||||
/// The draft is associated with the user (signer) and the provided patch revision within the repository.
|
||||
fn edit_draft_review(
|
||||
&self,
|
||||
rid: identity::RepoId,
|
||||
cob_id: git::Oid,
|
||||
edit: models::patch::ReviewEdit,
|
||||
) -> Result<(), Error> {
|
||||
let profile = self.profile();
|
||||
let repo = profile.storage.repository(rid)?;
|
||||
let signer = profile.signer()?;
|
||||
let drafts = storage::git::cob::DraftStore::new(&repo, *signer.public_key());
|
||||
|
||||
let mut patches = cob::patch::Cache::no_cache(&drafts)?;
|
||||
let mut patch = patches.get_mut(&cob_id.into())?;
|
||||
patch.review_edit(
|
||||
edit.review_id,
|
||||
edit.verdict.map(|v| v.into()),
|
||||
edit.summary,
|
||||
edit.labels,
|
||||
&signer,
|
||||
)?;
|
||||
|
||||
patches.write(&cob_id.into())?;
|
||||
|
||||
Ok::<_, Error>(())
|
||||
}
|
||||
|
||||
/// Creates a draft review for a specific patch revision.
|
||||
///
|
||||
/// This Tauri command allows users to create a new draft review for a specific patch revision.
|
||||
/// The draft is associated with the user (signer) and the provided patch revision within the repository.
|
||||
fn create_draft_review(
|
||||
&self,
|
||||
rid: identity::RepoId,
|
||||
revision_id: cob::patch::RevisionId,
|
||||
cob_id: git::Oid,
|
||||
labels: Vec<cob::Label>,
|
||||
) -> Result<patch::ReviewId, Error> {
|
||||
let profile = self.profile();
|
||||
let repo = profile.storage.repository(rid)?;
|
||||
let signer = profile.signer()?;
|
||||
let drafts = storage::git::cob::DraftStore::new(&repo, *signer.public_key());
|
||||
|
||||
let mut patches = cob::patch::Cache::no_cache(&drafts)?;
|
||||
let mut patch = patches.get_mut(&cob_id.into())?;
|
||||
let revision = patch
|
||||
.revision(&revision_id)
|
||||
.ok_or_else(|| Error::WithHint {
|
||||
err: anyhow::anyhow!("patch revision not found"),
|
||||
hint: "Not able to find the specified patch revision.",
|
||||
})?;
|
||||
|
||||
let review_id = match revision.review_by(signer.public_key()) {
|
||||
Some(review) => review.id(),
|
||||
None => patch.review(
|
||||
revision.id(),
|
||||
Some(cob::patch::Verdict::Reject),
|
||||
None,
|
||||
labels,
|
||||
&signer,
|
||||
)?,
|
||||
};
|
||||
|
||||
patches.write(&cob_id.into())?;
|
||||
|
||||
Ok::<_, Error>(review_id)
|
||||
}
|
||||
|
||||
/// Creates a new review comment on a draft review for a specific patch.
|
||||
///
|
||||
/// This Tauri command is used to add a comment to an existing draft review in a repository.
|
||||
/// It allows users to comment on a specific location in the code or leave general feedback
|
||||
/// on a review that belongs to a specific patch.
|
||||
fn create_draft_review_comment(
|
||||
&self,
|
||||
rid: identity::RepoId,
|
||||
cob_id: git::Oid,
|
||||
new: cobs::thread::CreateReviewComment,
|
||||
) -> Result<(), Error> {
|
||||
let profile = self.profile();
|
||||
let repo = profile.storage.repository(rid)?;
|
||||
let signer = profile.signer()?;
|
||||
let drafts = storage::git::cob::DraftStore::new(&repo, *signer.public_key());
|
||||
|
||||
let mut patches = cob::patch::Cache::no_cache(&drafts)?;
|
||||
let mut patch = patches.get_mut(&cob_id.into())?;
|
||||
|
||||
patch.transaction("Review comments", &signer, |tx| {
|
||||
tx.review_comment(
|
||||
new.review_id,
|
||||
new.body,
|
||||
new.location.map(|l| l.into()),
|
||||
new.reply_to,
|
||||
new.embeds.into_iter().map(Into::into).collect::<Vec<_>>(),
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
patches.write(&cob_id.into())?;
|
||||
|
||||
Ok::<_, Error>(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user