httpd: Add review ids to review json

This commit is contained in:
Sebastian Martinez 2024-02-01 17:01:26 +01:00 committed by cloudhead
parent 0a3da17fad
commit db6cb55d6c
No known key found for this signature in database
3 changed files with 28 additions and 5 deletions

View File

@ -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::<Vec<_>>()
}).collect::<Vec<_>>(),
"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_of(id).map(move |(id, r)| {
review(id, r, aliases)
}).collect::<Vec<_>>(),
})
}).collect::<Vec<_>>(),
})
@ -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::<Vec<_>>(),

View File

@ -3446,6 +3446,7 @@ mod routes {
"timestamp": TIMESTAMP,
"reviews": [
{
"id": "37ed60b8a11949d5db32bce3dd5ab117d3a82841",
"author": {
"id": CONTRIBUTOR_DID,
},

View File

@ -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<Item = (&ReviewId, &Review)> {
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<Item = Did> + '_ {
self.assignees.iter().map(Did::from)