Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
cob: Add ReviewIds to Revision cob
Merged did:key:z6MkkfM3...sVz5 opened 2 years ago
3 files changed +24 -3 0a3da17f db6cb55d
modified radicle-httpd/src/api/json.rs
@@ -6,6 +6,7 @@ use std::str;

use base64::prelude::{Engine, BASE64_STANDARD};
use radicle::cob::{CodeLocation, Reaction};
+
use radicle::patch::ReviewId;
use serde_json::{json, Value};

use radicle::cob::issue::{Issue, IssueId};
@@ -143,9 +144,15 @@ pub(crate) fn patch(
                "base": rev.base(),
                "oid": rev.head(),
                "refs": get_refs(repo, patch.author().id(), &rev.head()).unwrap_or_default(),
-
                "discussions": rev.discussion().comments().map(|(id, c)| patch_comment(id, c,  aliases)).collect::<Vec<_>>(),
+
                "discussions": rev.discussion().comments().map(|(id, c)| {
+
                    patch_comment(id, c,  aliases)
+
                }).collect::<Vec<_>>(),
                "timestamp": rev.timestamp().as_secs(),
-
                "reviews": rev.reviews().map(|(nid, r)| review(nid, r, aliases)).collect::<Vec<_>>(),
+
                "reviews": patch.reviews_by(id).flat_map(move |(review_id, pk)| {
+
                    rev.review(&pk).map(|r| {
+
                        review(&pk, review_id, r, aliases)
+
                    })
+
                }).collect::<Vec<_>>(),
            })
        }).collect::<Vec<_>>(),
    })
@@ -173,8 +180,9 @@ fn merge(nid: &NodeId, merge: &Merge, aliases: &impl AliasStore) -> Value {
}

/// Returns JSON for a patch `Review` and fills in `alias` when present.
-
fn review(nid: &NodeId, review: &Review, aliases: &impl AliasStore) -> Value {
+
fn review(nid: &NodeId, id: &ReviewId, review: &Review, aliases: &impl AliasStore) -> Value {
    json!({
+
        "id": id,
        "author": author(&Author::from(*nid), aliases.alias(nid)),
        "verdict": review.verdict(),
        "summary": review.summary(),
modified radicle-httpd/src/api/v1/projects.rs
@@ -3446,6 +3446,7 @@ mod routes {
                  "timestamp": TIMESTAMP,
                  "reviews": [
                    {
+
                      "id": "37ed60b8a11949d5db32bce3dd5ab117d3a82841",
                      "author": {
                          "id": CONTRIBUTOR_DID,
                      },
modified radicle/src/cob/patch.rs
@@ -497,6 +497,18 @@ impl Patch {
            .filter(move |(_, r)| (r.author.public_key() == author))
    }

+
    /// List of all patch reviews.
+
    pub fn reviews(&self) -> impl Iterator<Item = (&ReviewId, &Option<(RevisionId, PublicKey)>)> {
+
        self.reviews.iter()
+
    }
+

+
    /// List of patch reviews by the given revision.
+
    pub fn reviews_by(&self, rev: RevisionId) -> impl Iterator<Item = (&ReviewId, PublicKey)> {
+
        self.reviews().filter_map(move |(review_id, t)| {
+
            t.and_then(|(rev_id, pk)| (rev == rev_id).then_some((review_id, pk)))
+
        })
+
    }
+

    /// List of patch assignees.
    pub fn assignees(&self) -> impl Iterator<Item = Did> + '_ {
        self.assignees.iter().map(Did::from)