httpd: Add edits field to revision json
This commit is contained in:
parent
ee3dcfacf0
commit
1bb400c278
|
|
@ -40,7 +40,7 @@ pub fn run(
|
||||||
let target = patch.target();
|
let target = patch.target();
|
||||||
let embeds = patch
|
let embeds = patch
|
||||||
.embeds()
|
.embeds()
|
||||||
.into_iter()
|
.iter()
|
||||||
.filter_map(|embed| resolve_embed(repository, embed.clone()))
|
.filter_map(|embed| resolve_embed(repository, embed.clone()))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use serde_json::{json, Value};
|
||||||
|
|
||||||
use radicle::cob::issue::{Issue, IssueId};
|
use radicle::cob::issue::{Issue, IssueId};
|
||||||
use radicle::cob::patch::{Merge, Patch, PatchId, Review};
|
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::cob::{ActorId, Author};
|
||||||
use radicle::git::RefString;
|
use radicle::git::RefString;
|
||||||
use radicle::node::{Alias, AliasStore};
|
use radicle::node::{Alias, AliasStore};
|
||||||
|
|
@ -129,6 +129,7 @@ pub(crate) fn patch(
|
||||||
"id": id,
|
"id": id,
|
||||||
"author": author(rev.author(), aliases.alias(rev.author().id())),
|
"author": author(rev.author(), aliases.alias(rev.author().id())),
|
||||||
"description": rev.description(),
|
"description": rev.description(),
|
||||||
|
"edits": rev.edits().map(|e| edit(e, aliases)).collect::<Vec<_>>(),
|
||||||
"base": rev.base(),
|
"base": rev.base(),
|
||||||
"oid": rev.head(),
|
"oid": rev.head(),
|
||||||
"refs": get_refs(repo, patch.author().id(), &rev.head()).unwrap_or_default(),
|
"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 a Issue `Comment`.
|
/// Returns JSON for an `Edit`.
|
||||||
fn issue_comment(id: &CommentId, comment: &Comment, aliases: &impl AliasStore) -> Value {
|
fn edit(edit: &Edit, 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!({
|
json!({
|
||||||
"author": author(&Author::from(edit.author), aliases.alias(&edit.author)),
|
"author": author(&Author::from(edit.author), aliases.alias(&edit.author)),
|
||||||
"body": edit.body,
|
"body": edit.body,
|
||||||
"timestamp": edit.timestamp.as_secs(),
|
"timestamp": edit.timestamp.as_secs(),
|
||||||
"embeds": edit.embeds,
|
"embeds": edit.embeds,
|
||||||
})
|
})
|
||||||
}).collect::<Vec<_>>(),
|
}
|
||||||
|
|
||||||
|
/// 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(|e| edit(e, aliases)).collect::<Vec<_>>(),
|
||||||
"embeds": comment.embeds().to_vec(),
|
"embeds": comment.embeds().to_vec(),
|
||||||
"reactions": comment.reactions().collect::<Vec<_>>(),
|
"reactions": comment.reactions().collect::<Vec<_>>(),
|
||||||
"timestamp": comment.timestamp().as_secs(),
|
"timestamp": comment.timestamp().as_secs(),
|
||||||
|
|
@ -204,14 +208,7 @@ fn patch_comment(
|
||||||
"id": *id,
|
"id": *id,
|
||||||
"author": author(&Author::from(comment.author()), aliases.alias(&comment.author())),
|
"author": author(&Author::from(comment.author()), aliases.alias(&comment.author())),
|
||||||
"body": comment.body(),
|
"body": comment.body(),
|
||||||
"edits": comment.edits().map(|edit| {
|
"edits": comment.edits().map(|e| edit(e, aliases)).collect::<Vec<_>>(),
|
||||||
json!({
|
|
||||||
"author": author(&Author::from(edit.author), aliases.alias(&edit.author)),
|
|
||||||
"body": edit.body,
|
|
||||||
"timestamp": edit.timestamp.as_secs(),
|
|
||||||
"embeds": edit.embeds,
|
|
||||||
})
|
|
||||||
}).collect::<Vec<_>>(),
|
|
||||||
"embeds": comment.embeds().to_vec(),
|
"embeds": comment.embeds().to_vec(),
|
||||||
"reactions": comment.reactions().collect::<Vec<_>>(),
|
"reactions": comment.reactions().collect::<Vec<_>>(),
|
||||||
"timestamp": comment.timestamp().as_secs(),
|
"timestamp": comment.timestamp().as_secs(),
|
||||||
|
|
@ -231,14 +228,7 @@ fn review_comment(
|
||||||
"id": *id,
|
"id": *id,
|
||||||
"author": author(&Author::from(comment.author()), aliases.alias(&comment.author())),
|
"author": author(&Author::from(comment.author()), aliases.alias(&comment.author())),
|
||||||
"body": comment.body(),
|
"body": comment.body(),
|
||||||
"edits": comment.edits().map(|edit| {
|
"edits": comment.edits().map(|e| edit(e, aliases)).collect::<Vec<_>>(),
|
||||||
json!({
|
|
||||||
"author": author(&Author::from(edit.author), aliases.alias(&edit.author)),
|
|
||||||
"body": edit.body,
|
|
||||||
"timestamp": edit.timestamp.as_secs(),
|
|
||||||
"embeds": edit.embeds,
|
|
||||||
})
|
|
||||||
}).collect::<Vec<_>>(),
|
|
||||||
"embeds": comment.embeds().to_vec(),
|
"embeds": comment.embeds().to_vec(),
|
||||||
"reactions": comment.reactions().collect::<Vec<_>>(),
|
"reactions": comment.reactions().collect::<Vec<_>>(),
|
||||||
"timestamp": comment.timestamp().as_secs(),
|
"timestamp": comment.timestamp().as_secs(),
|
||||||
|
|
|
||||||
|
|
@ -2417,10 +2417,20 @@ mod routes {
|
||||||
"revisions": [
|
"revisions": [
|
||||||
{
|
{
|
||||||
"id": CONTRIBUTOR_PATCH_ID,
|
"id": CONTRIBUTOR_PATCH_ID,
|
||||||
"description": "change `hello world` in README to something else",
|
|
||||||
"author": {
|
"author": {
|
||||||
"id": CONTRIBUTOR_DID,
|
"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,
|
"base": PARENT,
|
||||||
"oid": HEAD,
|
"oid": HEAD,
|
||||||
"refs": [
|
"refs": [
|
||||||
|
|
@ -2459,10 +2469,20 @@ mod routes {
|
||||||
"revisions": [
|
"revisions": [
|
||||||
{
|
{
|
||||||
"id": CONTRIBUTOR_PATCH_ID,
|
"id": CONTRIBUTOR_PATCH_ID,
|
||||||
"description": "change `hello world` in README to something else",
|
|
||||||
"author": {
|
"author": {
|
||||||
"id": CONTRIBUTOR_DID,
|
"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,
|
"base": PARENT,
|
||||||
"oid": HEAD,
|
"oid": HEAD,
|
||||||
"refs": [
|
"refs": [
|
||||||
|
|
@ -2540,10 +2560,20 @@ mod routes {
|
||||||
"revisions": [
|
"revisions": [
|
||||||
{
|
{
|
||||||
"id": CREATED_PATCH_ID,
|
"id": CREATED_PATCH_ID,
|
||||||
"description": "Do some changes to README",
|
|
||||||
"author": {
|
"author": {
|
||||||
"id": CONTRIBUTOR_DID,
|
"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,
|
"base": INITIAL_COMMIT,
|
||||||
"oid": HEAD,
|
"oid": HEAD,
|
||||||
"refs": [
|
"refs": [
|
||||||
|
|
@ -2606,6 +2636,16 @@ mod routes {
|
||||||
"id": CONTRIBUTOR_DID,
|
"id": CONTRIBUTOR_DID,
|
||||||
},
|
},
|
||||||
"description": "change `hello world` in README to something else",
|
"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,
|
"base": PARENT,
|
||||||
"oid": HEAD,
|
"oid": HEAD,
|
||||||
"refs": [
|
"refs": [
|
||||||
|
|
@ -2666,10 +2706,20 @@ mod routes {
|
||||||
"revisions": [
|
"revisions": [
|
||||||
{
|
{
|
||||||
"id": CONTRIBUTOR_PATCH_ID,
|
"id": CONTRIBUTOR_PATCH_ID,
|
||||||
"description": "change `hello world` in README to something else",
|
|
||||||
"author": {
|
"author": {
|
||||||
"id": CONTRIBUTOR_DID,
|
"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,
|
"base": PARENT,
|
||||||
"oid": HEAD,
|
"oid": HEAD,
|
||||||
"refs": [
|
"refs": [
|
||||||
|
|
@ -2733,6 +2783,16 @@ mod routes {
|
||||||
"id": CONTRIBUTOR_DID,
|
"id": CONTRIBUTOR_DID,
|
||||||
},
|
},
|
||||||
"description": "change `hello world` in README to something else",
|
"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,
|
"base": PARENT,
|
||||||
"oid": HEAD,
|
"oid": HEAD,
|
||||||
"refs": [
|
"refs": [
|
||||||
|
|
@ -2748,6 +2808,16 @@ mod routes {
|
||||||
"id": CONTRIBUTOR_DID,
|
"id": CONTRIBUTOR_DID,
|
||||||
},
|
},
|
||||||
"description": "This is a new revision",
|
"description": "This is a new revision",
|
||||||
|
"edits": [
|
||||||
|
{
|
||||||
|
"author": {
|
||||||
|
"id": CONTRIBUTOR_DID,
|
||||||
|
},
|
||||||
|
"body": "This is a new revision",
|
||||||
|
"timestamp": TIMESTAMP,
|
||||||
|
"embeds": [],
|
||||||
|
},
|
||||||
|
],
|
||||||
"base": PARENT,
|
"base": PARENT,
|
||||||
"oid": HEAD,
|
"oid": HEAD,
|
||||||
"refs": [
|
"refs": [
|
||||||
|
|
@ -2807,10 +2877,20 @@ mod routes {
|
||||||
"revisions": [
|
"revisions": [
|
||||||
{
|
{
|
||||||
"id": CONTRIBUTOR_PATCH_ID,
|
"id": CONTRIBUTOR_PATCH_ID,
|
||||||
"description": "change `hello world` in README to something else",
|
|
||||||
"author": {
|
"author": {
|
||||||
"id": CONTRIBUTOR_DID,
|
"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,
|
"base": PARENT,
|
||||||
"oid": HEAD,
|
"oid": HEAD,
|
||||||
"refs": [
|
"refs": [
|
||||||
|
|
@ -2873,6 +2953,24 @@ mod routes {
|
||||||
"id": CONTRIBUTOR_DID,
|
"id": CONTRIBUTOR_DID,
|
||||||
},
|
},
|
||||||
"description": "Let's change the description a bit",
|
"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,
|
"base": PARENT,
|
||||||
"oid": HEAD,
|
"oid": HEAD,
|
||||||
"refs": [
|
"refs": [
|
||||||
|
|
@ -2999,6 +3097,16 @@ mod routes {
|
||||||
"id": CONTRIBUTOR_DID,
|
"id": CONTRIBUTOR_DID,
|
||||||
},
|
},
|
||||||
"description": "change `hello world` in README to something else",
|
"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,
|
"base": PARENT,
|
||||||
"oid": HEAD,
|
"oid": HEAD,
|
||||||
"refs": [
|
"refs": [
|
||||||
|
|
@ -3216,6 +3324,16 @@ mod routes {
|
||||||
"id": CONTRIBUTOR_DID,
|
"id": CONTRIBUTOR_DID,
|
||||||
},
|
},
|
||||||
"description": "change `hello world` in README to something else",
|
"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,
|
"base": PARENT,
|
||||||
"oid": HEAD,
|
"oid": HEAD,
|
||||||
"refs": [
|
"refs": [
|
||||||
|
|
@ -3362,6 +3480,16 @@ mod routes {
|
||||||
"id": CONTRIBUTOR_DID,
|
"id": CONTRIBUTOR_DID,
|
||||||
},
|
},
|
||||||
"description": "change `hello world` in README to something else",
|
"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,
|
"base": PARENT,
|
||||||
"oid": HEAD,
|
"oid": HEAD,
|
||||||
"refs": [
|
"refs": [
|
||||||
|
|
|
||||||
|
|
@ -1308,6 +1308,10 @@ impl Revision {
|
||||||
self.description.last().body.as_str()
|
self.description.last().body.as_str()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn edits(&self) -> impl Iterator<Item = &Edit> {
|
||||||
|
self.description.iter()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn embeds(&self) -> &Vec<Embed<Uri>> {
|
pub fn embeds(&self) -> &Vec<Embed<Uri>> {
|
||||||
&self.description.last().embeds
|
&self.description.last().embeds
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue