diff --git a/radicle-httpd/src/api/json.rs b/radicle-httpd/src/api/json.rs index 562d71fd..0902cdae 100644 --- a/radicle-httpd/src/api/json.rs +++ b/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}; @@ -137,15 +138,19 @@ pub(crate) fn patch( acc }); reactions.iter().map(|(emoji, authors)| - json!({"location": location, "emoji": emoji, "authors": authors }) + json!({ "location": location, "emoji": emoji, "authors": authors }) ).collect::>() }).collect::>(), "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::>(), + "discussions": rev.discussion().comments().map(|(id, c)| { + patch_comment(id, c, aliases) + }).collect::>(), "timestamp": rev.timestamp().as_secs(), - "reviews": rev.reviews().map(|(nid, r)| review(nid, r, aliases)).collect::>(), + "reviews": patch.reviews_of(id).map(move |(id, r)| { + review(id, r, aliases) + }).collect::>(), }) }).collect::>(), }) @@ -173,9 +178,11 @@ 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(id: &ReviewId, review: &Review, aliases: &impl AliasStore) -> Value { + let a = review.author(); json!({ - "author": author(&Author::from(*nid), aliases.alias(nid)), + "id": id, + "author": author(a, aliases.alias(a.id())), "verdict": review.verdict(), "summary": review.summary(), "comments": review.comments().map(|(id, c)| review_comment(id, c, aliases)).collect::>(), diff --git a/radicle-httpd/src/api/v1/projects.rs b/radicle-httpd/src/api/v1/projects.rs index 35d40294..149b0058 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -3446,6 +3446,7 @@ mod routes { "timestamp": TIMESTAMP, "reviews": [ { + "id": "37ed60b8a11949d5db32bce3dd5ab117d3a82841", "author": { "id": CONTRIBUTOR_DID, }, diff --git a/radicle/src/cob/patch.rs b/radicle/src/cob/patch.rs index 7972cd6c..5263f4f9 100644 --- a/radicle/src/cob/patch.rs +++ b/radicle/src/cob/patch.rs @@ -497,6 +497,21 @@ impl Patch { .filter(move |(_, r)| (r.author.public_key() == author)) } + /// List of patch reviews of the given revision. + pub fn reviews_of(&self, rev: RevisionId) -> impl Iterator { + self.reviews.iter().filter_map(move |(review_id, t)| { + t.and_then(|(rev_id, pk)| { + if rev == rev_id { + self.revision(&rev_id) + .and_then(|r| r.review(&pk)) + .map(|r| (review_id, r)) + } else { + None + } + }) + }) + } + /// List of patch assignees. pub fn assignees(&self) -> impl Iterator + '_ { self.assignees.iter().map(Did::from)