httpd: Add missing COB actions

Handles missing issue and patch actions. Adds embeds to patch comments.

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
Sebastian Martinez
2023-10-11 13:36:48 +02:00
committed by cloudhead
parent 7f51ba8488
commit c97f693e1a
4 changed files with 335 additions and 59 deletions
+2
View File
@@ -247,6 +247,7 @@ struct Comment<'a> {
#[serde(with = "radicle::serde_ext::localtime::time")]
timestamp: Timestamp,
reply_to: Option<CommentId>,
resolved: bool,
}
impl<'a> Comment<'a> {
@@ -260,6 +261,7 @@ impl<'a> Comment<'a> {
reactions: comment.reactions().collect::<Vec<_>>(),
timestamp: comment.timestamp(),
reply_to: comment.reply_to(),
resolved: comment.resolved(),
}
}
}
+329 -56
View File
@@ -732,11 +732,21 @@ async fn issue_update_handler(
} => {
issue.react(id, reaction, active, &signer)?;
}
issue::Action::CommentEdit { .. } => {
todo!();
issue::Action::CommentEdit { id, body, embeds } => {
let embeds: Vec<Embed> = embeds
.into_iter()
.filter_map(|embed| {
let content = TryInto::<DataUri>::try_into(&embed.content).ok()?;
Some(Embed {
name: embed.name,
content: content.into(),
})
})
.collect();
issue.edit_comment(id, body, embeds, &signer)?;
}
issue::Action::CommentRedact { .. } => {
todo!();
issue::Action::CommentRedact { id } => {
issue.redact_comment(id, &signer)?;
}
};
@@ -824,11 +834,26 @@ async fn patch_update_handler(
patch::Action::Edit { title, target } => {
patch.edit(title, target, &signer)?;
}
patch::Action::RevisionEdit {
patch::Action::Label { labels } => {
patch.label(labels, &signer)?;
}
patch::Action::Lifecycle { state } => {
patch.lifecycle(state, &signer)?;
}
patch::Action::Assign { assignees } => {
patch.assign(assignees, &signer)?;
}
patch::Action::Merge { revision, commit } => {
// TODO: We should cleanup the stored copy at least.
let _ = patch.merge(revision, commit, &signer)?;
}
patch::Action::Review {
revision,
description,
summary,
verdict,
labels,
} => {
patch.edit_revision(revision, description, &signer)?;
patch.review(revision, verdict, summary, labels, &signer)?;
}
patch::Action::ReviewEdit {
review,
@@ -837,20 +862,45 @@ async fn patch_update_handler(
} => {
patch.edit_review(review, summary, verdict, &signer)?;
}
patch::Action::ReviewRedact { review } => {
patch.redact_review(review, &signer)?;
}
patch::Action::ReviewComment {
review,
body,
reply_to,
..
location,
embeds,
} => {
patch.review_comment(review, body, None, reply_to, &signer)?;
let embeds: Vec<Embed> = embeds
.into_iter()
.filter_map(|embed| {
let content = TryInto::<DataUri>::try_into(&embed.content).ok()?;
Some(Embed {
name: embed.name,
content: content.into(),
})
})
.collect();
patch.review_comment(review, body, location, reply_to, embeds, &signer)?;
}
patch::Action::ReviewCommentEdit {
review,
comment,
body,
embeds,
} => {
patch.edit_review_comment(review, comment, body, &signer)?;
let embeds: Vec<Embed> = embeds
.into_iter()
.filter_map(|embed| {
let content = TryInto::<DataUri>::try_into(&embed.content).ok()?;
Some(Embed {
name: embed.name,
content: content.into(),
})
})
.collect();
patch.edit_review_comment(review, comment, body, embeds, &signer)?;
}
patch::Action::ReviewCommentReact {
review,
@@ -863,8 +913,11 @@ async fn patch_update_handler(
patch::Action::ReviewCommentRedact { review, comment } => {
patch.redact_review_comment(review, comment, &signer)?;
}
patch::Action::Label { labels } => {
patch.label(labels, &signer)?;
patch::Action::ReviewCommentResolve { review, comment } => {
patch.resolve_review_comment(review, comment, &signer)?;
}
patch::Action::ReviewCommentUnresolve { review, comment } => {
patch.unresolve_review_comment(review, comment, &signer)?;
}
patch::Action::Revision {
description,
@@ -874,35 +927,51 @@ async fn patch_update_handler(
} => {
patch.update(description, base, oid, &signer)?;
}
patch::Action::Lifecycle { state } => {
patch.lifecycle(state, &signer)?;
}
patch::Action::Review {
patch::Action::RevisionEdit {
revision,
summary,
verdict,
labels,
description,
} => {
patch.review(revision, verdict, summary, labels, &signer)?;
patch.edit_revision(revision, description, &signer)?;
}
patch::Action::Merge { revision, commit } => {
// TODO: We should cleanup the stored copy at least.
let _ = patch.merge(revision, commit, &signer)?;
patch::Action::RevisionRedact { revision } => {
patch.redact(revision, &signer)?;
}
patch::Action::RevisionComment {
revision,
body,
reply_to,
..
location,
embeds,
} => {
patch.comment(revision, body, reply_to, &signer)?;
let embeds: Vec<Embed> = embeds
.into_iter()
.filter_map(|embed| {
let content = TryInto::<DataUri>::try_into(&embed.content).ok()?;
Some(Embed {
name: embed.name,
content: content.into(),
})
})
.collect();
patch.comment(revision, body, reply_to, location, embeds, &signer)?;
}
patch::Action::RevisionCommentEdit {
revision,
comment,
body,
embeds,
} => {
patch.comment_edit(revision, comment, body, &signer)?;
let embeds: Vec<Embed> = embeds
.into_iter()
.filter_map(|embed| {
let content = TryInto::<DataUri>::try_into(&embed.content).ok()?;
Some(Embed {
name: embed.name,
content: content.into(),
})
})
.collect();
patch.comment_edit(revision, comment, body, embeds, &signer)?;
}
patch::Action::RevisionCommentReact {
revision,
@@ -1937,7 +2006,8 @@ mod routes {
"embeds": [],
"reactions": [],
"timestamp": TIMESTAMP,
"replyTo": null
"replyTo": null,
"resolved": false,
}
],
"labels": []
@@ -2017,6 +2087,7 @@ mod routes {
"reactions": [],
"timestamp": TIMESTAMP,
"replyTo": null,
"resolved": false,
}],
"labels": [
"bug",
@@ -2059,7 +2130,7 @@ mod routes {
let body = serde_json::to_vec(&json!({
"type": "comment.react",
"id": "6fe9fdec2ec9f6436f2875dbcbedb95dd215b863",
"id": ISSUE_DISCUSSION_ID,
"reaction": "🚀",
"active": true,
}))
@@ -2072,6 +2143,40 @@ mod routes {
)
.await;
let body = serde_json::to_vec(&json!({
"type": "comment.edit",
"id": ISSUE_DISCUSSION_ID,
"body": "EDIT: Change 'hello world' to 'hello anyone'",
"embeds": []
}))
.unwrap();
let response = patch(
&app,
format!("/projects/{CONTRIBUTOR_RID}/issues/{CONTRIBUTOR_ISSUE_ID}"),
Some(Body::from(body)),
Some(SESSION_ID.to_string()),
)
.await;
assert_eq!(response.json().await, json!({ "success": true }));
let body = serde_json::to_vec(&json!({
"type": "comment.redact",
"id": "6fe9fdec2ec9f6436f2875dbcbedb95dd215b863",
}))
.unwrap();
let response = patch(
&app,
format!("/projects/{CONTRIBUTOR_RID}/issues/{CONTRIBUTOR_ISSUE_ID}"),
Some(Body::from(body)),
Some(SESSION_ID.to_string()),
)
.await;
assert_eq!(response.json().await, json!({ "success": true }));
let response = get(
&app,
format!("/projects/{CONTRIBUTOR_RID}/issues/{CONTRIBUTOR_ISSUE_ID}"),
@@ -2096,32 +2201,17 @@ mod routes {
"author": {
"id": CONTRIBUTOR_DID,
},
"body": "Change 'hello world' to 'hello everyone'",
"body": "EDIT: Change 'hello world' to 'hello anyone'",
"embeds": [],
"reactions": [],
"timestamp": TIMESTAMP,
"replyTo": null,
},
{
"id": "6fe9fdec2ec9f6436f2875dbcbedb95dd215b863",
"author": {
"id": CONTRIBUTOR_DID,
},
"body": "This is first-level comment",
"embeds": [
{
"name": "image.jpg",
"content": "git:94381b429d7f7fe87e1bade52d893ab348ae29cc",
},
],
"reactions": [
[
"z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8",
"🚀",
"z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8",
"🚀",
],
],
"timestamp": TIMESTAMP,
"replyTo": CONTRIBUTOR_ISSUE_ID,
"replyTo": null,
"resolved": false,
},
],
"labels": [],
@@ -2185,6 +2275,7 @@ mod routes {
"reactions": [],
"timestamp": TIMESTAMP,
"replyTo": null,
"resolved": false,
},
{
"id": ISSUE_COMMENT_ID,
@@ -2196,6 +2287,7 @@ mod routes {
"reactions": [],
"timestamp": TIMESTAMP,
"replyTo": ISSUE_DISCUSSION_ID,
"resolved": false,
},
],
"labels": [],
@@ -2371,7 +2463,68 @@ mod routes {
}
#[tokio::test]
async fn test_projects_patches_tag() {
async fn test_projects_patches_assign() {
let tmp = tempfile::tempdir().unwrap();
let ctx = contributor(tmp.path());
let app = super::router(ctx.to_owned());
create_session(ctx).await;
let body = serde_json::to_vec(&json!({
"type": "assign",
"assignees": [CONTRIBUTOR_DID]
}))
.unwrap();
let response = patch(
&app,
format!("/projects/{CONTRIBUTOR_RID}/patches/{CONTRIBUTOR_PATCH_ID}"),
Some(Body::from(body)),
Some(SESSION_ID.to_string()),
)
.await;
assert_eq!(response.status(), StatusCode::OK);
let response = get(
&app,
format!("/projects/{CONTRIBUTOR_RID}/patches/{CONTRIBUTOR_PATCH_ID}"),
)
.await;
assert_eq!(
response.json().await,
json!({
"id": CONTRIBUTOR_PATCH_ID,
"author": {
"id": CONTRIBUTOR_DID,
},
"title": "A new `hello world`",
"state": { "status": "open" },
"target": "delegates",
"labels": [],
"merges": [],
"assignees": [CONTRIBUTOR_DID],
"revisions": [
{
"id": CONTRIBUTOR_PATCH_ID,
"author": {
"id": CONTRIBUTOR_DID,
},
"description": "change `hello world` in README to something else",
"base": PARENT,
"oid": HEAD,
"refs": [
"refs/heads/master",
],
"discussions": [],
"timestamp": TIMESTAMP,
"reviews": [],
},
],
})
);
}
#[tokio::test]
async fn test_projects_patches_label() {
let tmp = tempfile::tempdir().unwrap();
let ctx = contributor(tmp.path());
let app = super::router(ctx.to_owned());
@@ -2575,6 +2728,68 @@ mod routes {
);
}
#[tokio::test]
async fn test_projects_patches_revisions_edit() {
let tmp = tempfile::tempdir().unwrap();
let ctx = contributor(tmp.path());
let app = super::router(ctx.to_owned());
create_session(ctx).await;
let body = serde_json::to_vec(&json!({
"type": "revision.edit",
"revision": CONTRIBUTOR_PATCH_ID,
"description": "Let's change the description a bit",
}))
.unwrap();
let response = patch(
&app,
format!("/projects/{CONTRIBUTOR_RID}/patches/{CONTRIBUTOR_PATCH_ID}"),
Some(Body::from(body)),
Some(SESSION_ID.to_string()),
)
.await;
assert_eq!(response.status(), StatusCode::OK);
let response = get(
&app,
format!("/projects/{CONTRIBUTOR_RID}/patches/{CONTRIBUTOR_PATCH_ID}"),
)
.await;
assert_eq!(
response.json().await,
json!({
"id": CONTRIBUTOR_PATCH_ID,
"author": {
"id": CONTRIBUTOR_DID,
},
"title": "A new `hello world`",
"state": { "status": "open" },
"target": "delegates",
"labels": [],
"merges": [],
"assignees": [],
"revisions": [
{
"id": CONTRIBUTOR_PATCH_ID,
"author": {
"id": CONTRIBUTOR_DID,
},
"description": "Let's change the description a bit",
"base": PARENT,
"oid": HEAD,
"refs": [
"refs/heads/master",
],
"discussions": [],
"timestamp": TIMESTAMP,
"reviews": [],
},
],
})
);
}
#[tokio::test]
async fn test_projects_patches_discussions() {
let tmp = tempfile::tempdir().unwrap();
@@ -2584,7 +2799,13 @@ mod routes {
let thread_body = serde_json::to_vec(&json!({
"type": "revision.comment",
"revision": CONTRIBUTOR_PATCH_ID,
"body": "This is a root level comment"
"body": "This is a root level comment",
"embeds": [
{
"name": "image.jpg",
"content": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGP4//8/AAX+Av4N70a4AAAAAElFTkSuQmCC"
}
],
}))
.unwrap();
let response = patch(
@@ -2616,7 +2837,13 @@ mod routes {
"type": "revision.comment.edit",
"revision": CONTRIBUTOR_PATCH_ID,
"comment": CONTRIBUTOR_COMMENT_1,
"body": "EDIT: This is a root level comment"
"body": "EDIT: This is a root level comment",
"embeds": [
{
"name": "image.jpg",
"content": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGP4//8/AAX+Av4N70a4AAAAAElFTkSuQmCC"
}
],
}))
.unwrap();
let response = patch(
@@ -2633,6 +2860,7 @@ mod routes {
"revision": CONTRIBUTOR_PATCH_ID,
"body": "This is a root level comment",
"replyTo": CONTRIBUTOR_COMMENT_1,
"embeds": [],
}))
.unwrap();
let response = patch(
@@ -2683,10 +2911,16 @@ mod routes {
"id": CONTRIBUTOR_DID,
},
"body": "EDIT: This is a root level comment",
"embeds": [],
"embeds": [
{
"name": "image.jpg",
"content": "git:94381b429d7f7fe87e1bade52d893ab348ae29cc",
}
],
"reactions": [["z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8","🚀"]],
"timestamp": TIMESTAMP,
"replyTo": null,
"resolved": false,
},
{
"id": CONTRIBUTOR_COMMENT_2,
@@ -2698,6 +2932,7 @@ mod routes {
"reactions": [],
"timestamp": TIMESTAMP,
"replyTo": CONTRIBUTOR_COMMENT_1,
"resolved": false,
},
],
"timestamp": TIMESTAMP,
@@ -2734,7 +2969,18 @@ mod routes {
let review_comment_body = serde_json::to_vec(&json!({
"type": "review.comment",
"review": CONTRIBUTOR_PATCH_REVIEW,
"body": "This is a comment on a review"
"body": "This is a comment on a review",
"embeds": [],
"location": {
"path": "README.md",
"new": {
"type": "lines",
"range": {
"start": 2,
"end": 4
}
}
}
}))
.unwrap();
patch(
@@ -2749,7 +2995,8 @@ mod routes {
"type": "review.comment.edit",
"review": CONTRIBUTOR_PATCH_REVIEW,
"comment": CONTRIBUTOR_COMMENT_3,
"body": "EDIT: This is a comment on a review"
"embeds": [],
"body": "EDIT: This is a comment on a review",
}))
.unwrap();
patch(
@@ -2776,6 +3023,20 @@ mod routes {
)
.await;
let review_resolve_body = serde_json::to_vec(&json!({
"type": "review.comment.resolve",
"review": CONTRIBUTOR_PATCH_REVIEW,
"comment": CONTRIBUTOR_COMMENT_3,
}))
.unwrap();
patch(
&app,
format!("/projects/{CONTRIBUTOR_RID}/patches/{CONTRIBUTOR_PATCH_ID}"),
Some(Body::from(review_resolve_body)),
Some(SESSION_ID.to_string()),
)
.await;
let response = get(
&app,
format!("/projects/{CONTRIBUTOR_RID}/patches/{CONTRIBUTOR_PATCH_ID}"),
@@ -2817,15 +3078,27 @@ mod routes {
"verdict": "accept",
"summary": "A small review",
"comments": [[
"dd9743bb964ba22399548c86a3c1765020d58f48",
CONTRIBUTOR_COMMENT_3,
{
"author": "z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8",
"author": CONTRIBUTOR_NID,
"location": {
"path": "README.md",
"old": null,
"new": {
"type": "lines",
"range": {
"start": 2,
"end": 4,
}
}
},
"reactions": [
[
"z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8",
"🚀",
],
],
"resolved": true,
"body": "EDIT: This is a comment on a review",
},
]],
+1
View File
@@ -1,5 +1,6 @@
#![allow(clippy::type_complexity)]
#![allow(clippy::too_many_arguments)]
#![recursion_limit = "256"]
pub mod error;
use std::collections::HashMap;
+3 -3
View File
@@ -45,9 +45,9 @@ pub const CONTRIBUTOR_NID: &str = "z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJm
pub const CONTRIBUTOR_ISSUE_ID: &str = "7466975f0bef37b459887824a9655f3e78262522";
pub const CONTRIBUTOR_PATCH_ID: &str = "e651ae5869a2c1ac8ad4f6deae4cc835656ffa25";
pub const CONTRIBUTOR_PATCH_REVIEW: &str = "ee3eeba95f4ec418b3d0714e18e0d1ff605dc0e6";
pub const CONTRIBUTOR_COMMENT_1: &str = "d0bb75b2c72ab8b5486d39f6cf5f41f104b63cb1";
pub const CONTRIBUTOR_COMMENT_2: &str = "227947fa41420e363752357b2edd54d3ccadf7b3";
pub const CONTRIBUTOR_COMMENT_3: &str = "dd9743bb964ba22399548c86a3c1765020d58f48";
pub const CONTRIBUTOR_COMMENT_1: &str = "d8ff07edbc8d2229e54e70f2f5bc31614287f0dc";
pub const CONTRIBUTOR_COMMENT_2: &str = "f3fca0add53f85bc51a85198efed3273fe13b88e";
pub const CONTRIBUTOR_COMMENT_3: &str = "06990ff59faa12463f693dae7a98eb33d75afd2e";
/// Create a new profile.
pub fn profile(home: &Path, seed: [u8; 32]) -> radicle::Profile {