Radish alpha
r
rad:z4D5UCArafTzTQpDZNQRuqswh3ury
Radicle desktop app
Radicle
Git
Fix creation of draft review in tauri command
Merged did:key:z6MkkfM3...sVz5 opened 1 year ago
  • Fix function param for creating reviews
3 files changed +20 -26 6da4ffe3 62bdbc37
modified crates/radicle-tauri/src/commands/cob/patch.rs
@@ -97,7 +97,7 @@ pub fn get_draft_review(
    rid: identity::RepoId,
    cob_id: git::Oid,
    revision_id: patch::RevisionId,
-
) -> Option<patch::Review> {
+
) -> Option<types::cobs::patch::Review> {
    ctx.get_draft_review(rid, cob_id, revision_id)
}

modified crates/radicle-types/src/cobs/patch.rs
@@ -151,7 +151,7 @@ impl Revision {
            head: value.head(),
            reviews: value
                .reviews()
-
                .map(|(id, r)| Review::new(*id, r.clone(), aliases))
+
                .map(|(_, r)| Review::new(r.clone(), aliases))
                .collect::<Vec<_>>(),
            timestamp: value.timestamp(),
            discussion: value
@@ -230,7 +230,7 @@ impl Edit {
#[ts(export_to = "cob/patch/")]
pub struct Review {
    #[ts(as = "String")]
-
    id: identity::PublicKey,
+
    id: cob::patch::ReviewId,
    author: cobs::Author,
    #[ts(type = "'accept' | 'reject'")]
    #[ts(optional)]
@@ -244,13 +244,9 @@ pub struct Review {
}

impl Review {
-
    pub fn new(
-
        id: identity::PublicKey,
-
        review: cob::patch::Review,
-
        aliases: &impl AliasStore,
-
    ) -> Self {
+
    pub fn new(review: cob::patch::Review, aliases: &impl AliasStore) -> Self {
        Self {
-
            id,
+
            id: review.id(),
            author: cobs::Author::new(&review.author().id, aliases),
            verdict: review.verdict(),
            summary: review.summary().map(|s| s.to_string()),
modified crates/radicle-types/src/traits/patch.rs
@@ -296,8 +296,9 @@ pub trait PatchesMut: Profile {
        rid: identity::RepoId,
        cob_id: git::Oid,
        revision_id: patch::RevisionId,
-
    ) -> Option<patch::Review> {
+
    ) -> Option<cobs::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());
@@ -305,9 +306,10 @@ pub trait PatchesMut: Profile {

        let patch = patches.get(&cob_id.into()).ok()?;
        let revision = patch.and_then(|p| p.revision(&revision_id).cloned());
-
        let review = revision.and_then(|rev| rev.review_by(signer.public_key()).cloned());
+
        let review: Option<patch::Review> =
+
            revision.and_then(|rev| rev.review_by(signer.public_key()).cloned());

-
        review
+
        review.map(|r| cobs::patch::Review::new(r, &aliases))
    }

    /// Edits a draft review for a specific patch revision in a repository.
@@ -365,20 +367,16 @@ pub trait PatchesMut: Profile {
                hint: "Not able to find the specified patch revision.",
            })?;

-
        revision
-
            .review_by(signer.public_key())
-
            .ok_or(Error::WithHint {
-
                err: anyhow::anyhow!("duplicate patch review found"),
-
                hint: "Found an existing draft patch review on this patch revision and repo.",
-
            })?;
-

-
        let review_id = patch.review(
-
            revision.id(),
-
            Some(cob::patch::Verdict::Reject),
-
            None,
-
            labels,
-
            &signer,
-
        )?;
+
        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())?;