httpd: Add edits field to revision json

This commit is contained in:
Sebastian Martinez 2023-12-18 12:42:11 +01:00 committed by cloudhead
parent ee3dcfacf0
commit 1bb400c278
No known key found for this signature in database
4 changed files with 153 additions and 31 deletions

View File

@ -40,7 +40,7 @@ pub fn run(
let target = patch.target();
let embeds = patch
.embeds()
.into_iter()
.iter()
.filter_map(|embed| resolve_embed(repository, embed.clone()))
.collect::<Vec<_>>();

View File

@ -9,7 +9,7 @@ use serde_json::{json, Value};
use radicle::cob::issue::{Issue, IssueId};
use radicle::cob::patch::{Merge, Patch, PatchId, Review};
use radicle::cob::thread::{Comment, CommentId};
use radicle::cob::thread::{Comment, CommentId, Edit};
use radicle::cob::{ActorId, Author};
use radicle::git::RefString;
use radicle::node::{Alias, AliasStore};
@ -129,6 +129,7 @@ pub(crate) fn patch(
"id": id,
"author": author(rev.author(), aliases.alias(rev.author().id())),
"description": rev.description(),
"edits": rev.edits().map(|e| edit(e, aliases)).collect::<Vec<_>>(),
"base": rev.base(),
"oid": rev.head(),
"refs": get_refs(repo, patch.author().id(), &rev.head()).unwrap_or_default(),
@ -172,20 +173,23 @@ fn review(nid: &NodeId, review: &Review, aliases: &impl AliasStore) -> Value {
})
}
/// Returns JSON for an `Edit`.
fn edit(edit: &Edit, aliases: &impl AliasStore) -> Value {
json!({
"author": author(&Author::from(edit.author), aliases.alias(&edit.author)),
"body": edit.body,
"timestamp": edit.timestamp.as_secs(),
"embeds": edit.embeds,
})
}
/// Returns JSON for a Issue `Comment`.
fn issue_comment(id: &CommentId, comment: &Comment, aliases: &impl AliasStore) -> Value {
json!({
"id": *id,
"author": author(&Author::from(comment.author()), aliases.alias(&comment.author())),
"body": comment.body(),
"edits": comment.edits().map(|edit| {
json!({
"author": author(&Author::from(edit.author), aliases.alias(&edit.author)),
"body": edit.body,
"timestamp": edit.timestamp.as_secs(),
"embeds": edit.embeds,
})
}).collect::<Vec<_>>(),
"edits": comment.edits().map(|e| edit(e, aliases)).collect::<Vec<_>>(),
"embeds": comment.embeds().to_vec(),
"reactions": comment.reactions().collect::<Vec<_>>(),
"timestamp": comment.timestamp().as_secs(),
@ -204,14 +208,7 @@ fn patch_comment(
"id": *id,
"author": author(&Author::from(comment.author()), aliases.alias(&comment.author())),
"body": comment.body(),
"edits": comment.edits().map(|edit| {
json!({
"author": author(&Author::from(edit.author), aliases.alias(&edit.author)),
"body": edit.body,
"timestamp": edit.timestamp.as_secs(),
"embeds": edit.embeds,
})
}).collect::<Vec<_>>(),
"edits": comment.edits().map(|e| edit(e, aliases)).collect::<Vec<_>>(),
"embeds": comment.embeds().to_vec(),
"reactions": comment.reactions().collect::<Vec<_>>(),
"timestamp": comment.timestamp().as_secs(),
@ -231,14 +228,7 @@ fn review_comment(
"id": *id,
"author": author(&Author::from(comment.author()), aliases.alias(&comment.author())),
"body": comment.body(),
"edits": comment.edits().map(|edit| {
json!({
"author": author(&Author::from(edit.author), aliases.alias(&edit.author)),
"body": edit.body,
"timestamp": edit.timestamp.as_secs(),
"embeds": edit.embeds,
})
}).collect::<Vec<_>>(),
"edits": comment.edits().map(|e| edit(e, aliases)).collect::<Vec<_>>(),
"embeds": comment.embeds().to_vec(),
"reactions": comment.reactions().collect::<Vec<_>>(),
"timestamp": comment.timestamp().as_secs(),

View File

@ -2417,10 +2417,20 @@ mod routes {
"revisions": [
{
"id": CONTRIBUTOR_PATCH_ID,
"description": "change `hello world` in README to something else",
"author": {
"id": CONTRIBUTOR_DID,
},
"description": "change `hello world` in README to something else",
"edits": [
{
"author": {
"id": CONTRIBUTOR_DID,
},
"body": "change `hello world` in README to something else",
"timestamp": TIMESTAMP,
"embeds": [],
},
],
"base": PARENT,
"oid": HEAD,
"refs": [
@ -2459,10 +2469,20 @@ mod routes {
"revisions": [
{
"id": CONTRIBUTOR_PATCH_ID,
"description": "change `hello world` in README to something else",
"author": {
"id": CONTRIBUTOR_DID,
},
"description": "change `hello world` in README to something else",
"edits": [
{
"author": {
"id": CONTRIBUTOR_DID,
},
"body": "change `hello world` in README to something else",
"timestamp": TIMESTAMP,
"embeds": [],
},
],
"base": PARENT,
"oid": HEAD,
"refs": [
@ -2540,10 +2560,20 @@ mod routes {
"revisions": [
{
"id": CREATED_PATCH_ID,
"description": "Do some changes to README",
"author": {
"id": CONTRIBUTOR_DID,
},
"description": "Do some changes to README",
"edits": [
{
"author": {
"id": CONTRIBUTOR_DID,
},
"body": "Do some changes to README",
"timestamp": TIMESTAMP,
"embeds": [],
},
],
"base": INITIAL_COMMIT,
"oid": HEAD,
"refs": [
@ -2606,6 +2636,16 @@ mod routes {
"id": CONTRIBUTOR_DID,
},
"description": "change `hello world` in README to something else",
"edits": [
{
"author": {
"id": CONTRIBUTOR_DID,
},
"body": "change `hello world` in README to something else",
"timestamp": TIMESTAMP,
"embeds": [],
},
],
"base": PARENT,
"oid": HEAD,
"refs": [
@ -2666,10 +2706,20 @@ mod routes {
"revisions": [
{
"id": CONTRIBUTOR_PATCH_ID,
"description": "change `hello world` in README to something else",
"author": {
"id": CONTRIBUTOR_DID,
},
"description": "change `hello world` in README to something else",
"edits": [
{
"author": {
"id": CONTRIBUTOR_DID,
},
"body": "change `hello world` in README to something else",
"timestamp": TIMESTAMP,
"embeds": [],
},
],
"base": PARENT,
"oid": HEAD,
"refs": [
@ -2733,6 +2783,16 @@ mod routes {
"id": CONTRIBUTOR_DID,
},
"description": "change `hello world` in README to something else",
"edits": [
{
"author": {
"id": CONTRIBUTOR_DID,
},
"body": "change `hello world` in README to something else",
"timestamp": TIMESTAMP,
"embeds": [],
},
],
"base": PARENT,
"oid": HEAD,
"refs": [
@ -2748,6 +2808,16 @@ mod routes {
"id": CONTRIBUTOR_DID,
},
"description": "This is a new revision",
"edits": [
{
"author": {
"id": CONTRIBUTOR_DID,
},
"body": "This is a new revision",
"timestamp": TIMESTAMP,
"embeds": [],
},
],
"base": PARENT,
"oid": HEAD,
"refs": [
@ -2807,10 +2877,20 @@ mod routes {
"revisions": [
{
"id": CONTRIBUTOR_PATCH_ID,
"description": "change `hello world` in README to something else",
"author": {
"id": CONTRIBUTOR_DID,
},
"description": "change `hello world` in README to something else",
"edits": [
{
"author": {
"id": CONTRIBUTOR_DID,
},
"body": "change `hello world` in README to something else",
"timestamp": TIMESTAMP,
"embeds": [],
},
],
"base": PARENT,
"oid": HEAD,
"refs": [
@ -2873,6 +2953,24 @@ mod routes {
"id": CONTRIBUTOR_DID,
},
"description": "Let's change the description a bit",
"edits": [
{
"author": {
"id": CONTRIBUTOR_DID,
},
"body": "change `hello world` in README to something else",
"timestamp": TIMESTAMP,
"embeds": [],
},
{
"author": {
"id": CONTRIBUTOR_DID,
},
"body": "Let's change the description a bit",
"timestamp": TIMESTAMP,
"embeds": [],
},
],
"base": PARENT,
"oid": HEAD,
"refs": [
@ -2999,6 +3097,16 @@ mod routes {
"id": CONTRIBUTOR_DID,
},
"description": "change `hello world` in README to something else",
"edits": [
{
"author": {
"id": CONTRIBUTOR_DID,
},
"body": "change `hello world` in README to something else",
"timestamp": TIMESTAMP,
"embeds": [],
},
],
"base": PARENT,
"oid": HEAD,
"refs": [
@ -3216,6 +3324,16 @@ mod routes {
"id": CONTRIBUTOR_DID,
},
"description": "change `hello world` in README to something else",
"edits": [
{
"author": {
"id": CONTRIBUTOR_DID,
},
"body": "change `hello world` in README to something else",
"timestamp": TIMESTAMP,
"embeds": [],
},
],
"base": PARENT,
"oid": HEAD,
"refs": [
@ -3362,6 +3480,16 @@ mod routes {
"id": CONTRIBUTOR_DID,
},
"description": "change `hello world` in README to something else",
"edits": [
{
"author": {
"id": CONTRIBUTOR_DID,
},
"body": "change `hello world` in README to something else",
"timestamp": TIMESTAMP,
"embeds": [],
},
],
"base": PARENT,
"oid": HEAD,
"refs": [

View File

@ -1308,6 +1308,10 @@ impl Revision {
self.description.last().body.as_str()
}
pub fn edits(&self) -> impl Iterator<Item = &Edit> {
self.description.iter()
}
pub fn embeds(&self) -> &Vec<Embed<Uri>> {
&self.description.last().embeds
}