diff --git a/radicle-httpd/src/api/json.rs b/radicle-httpd/src/api/json.rs index a150f30e..011ad99f 100644 --- a/radicle-httpd/src/api/json.rs +++ b/radicle-httpd/src/api/json.rs @@ -7,12 +7,15 @@ use serde::Serialize; use serde_json::{json, Value}; use radicle::cob::issue::{Issue, IssueId}; +use radicle::cob::patch::Merge; +use radicle::cob::patch::Review; use radicle::cob::patch::{Patch, PatchId}; use radicle::cob::thread; use radicle::cob::thread::{CommentId, Thread}; use radicle::cob::{ActorId, Author, Reaction, Timestamp}; use radicle::git::RefString; use radicle::node::tracking::store as TrackingStore; +use radicle::prelude::NodeId; use radicle::storage::{git, refs, ReadRepository}; use radicle_surf::blob::Blob; use radicle_surf::tree::Tree; @@ -122,14 +125,7 @@ pub(crate) fn patch( "state": patch.state(), "target": patch.target(), "tags": patch.tags().collect::>(), - "merges": patch.merges().map(|(a, m)| { - json!({ - "author": a, - "revision": m.revision, - "commit": m.commit, - "timestamp": m.timestamp - }) - }).collect::>(), + "merges": patch.merges().map(|(nid, m)| merge(m, nid, aliases.alias(nid))).collect::>(), "reviewers": patch.reviewers().collect::>(), "revisions": patch.revisions().map(|(id, rev)| { json!({ @@ -143,7 +139,7 @@ pub(crate) fn patch( .map(|(id, comment)| Comment::new(id, comment, rev.discussion(), aliases)) .collect::>(), "timestamp": rev.timestamp(), - "reviews": rev.reviews().collect::>(), + "reviews": rev.reviews().map(|(nid, _review)| review(nid, aliases.alias(nid), _review)).collect::>(), }) }).collect::>(), }) @@ -160,6 +156,54 @@ fn author(author: &Author, alias: Option) -> Value { } } +/// Returns JSON for a patch `Merge` and fills in `alias` when present. +fn merge(merge: &Merge, nid: &NodeId, alias: Option) -> Value { + match alias { + Some(alias) => json!({ + "author": { + "id": nid, + "alias": alias, + }, + "commit": merge.commit, + "timestamp": merge.timestamp, + "revision": merge.revision, + }), + None => json!({ + "author": { + "id": nid, + }, + "commit": merge.commit, + "timestamp": merge.timestamp, + "revision": merge.revision, + }), + } +} + +/// Returns JSON for a patch `Review` and fills in `alias` when present. +fn review(nid: &NodeId, alias: Option, review: &Review) -> Value { + match alias { + Some(alias) => json!({ + "author": { + "id": nid, + "alias": alias, + }, + "verdict": review.verdict(), + "comment": review.comment(), + "inline": review.inline().collect::>(), + "timestamp": review.timestamp(), + }), + None => json!({ + "author": { + "id": nid, + }, + "verdict": review.verdict(), + "comment": review.comment(), + "inline": review.inline().collect::>(), + "timestamp": review.timestamp(), + }), + } +} + /// Returns the name part of a path string. fn name_in_path(path: &str) -> &str { match path.rsplit('/').next() { diff --git a/radicle-httpd/src/api/v1/projects.rs b/radicle-httpd/src/api/v1/projects.rs index c18c68b2..55fccb3a 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -2271,29 +2271,29 @@ mod routes { "discussions": [], "timestamp": TIMESTAMP, "reviews": [ - [ - CONTRIBUTOR_NID, - { - "verdict": "accept", - "comment": "A small review", - "inline": [ - { - "location": { - "blob": "82eb77880c693655bce074e3dbbd9fa711dc018b", - "path": "./README.md", - "commit": HEAD, - "lines": { - "start": 1, - "end": 3, - }, - }, - "comment": "This is a comment on line 1", - "timestamp": TIMESTAMP, - } - ], - "timestamp": TIMESTAMP, + { + "author": { + "id": CONTRIBUTOR_NID, }, - ], + "verdict": "accept", + "comment": "A small review", + "inline": [ + { + "location": { + "blob": "82eb77880c693655bce074e3dbbd9fa711dc018b", + "path": "./README.md", + "commit": HEAD, + "lines": { + "start": 1, + "end": 3, + }, + }, + "comment": "This is a comment on line 1", + "timestamp": TIMESTAMP, + } + ], + "timestamp": TIMESTAMP, + }, ], }, ], @@ -2345,7 +2345,9 @@ mod routes { "target": "delegates", "tags": [], "merges": [{ - "author": CONTRIBUTOR_NID, + "author": { + "id": CONTRIBUTOR_NID, + }, "revision": CONTRIBUTOR_PATCH_ID, "commit": PARENT, "timestamp": TIMESTAMP,