From 3ddec3dd7dc3dcf74ef826024f54c3023ad1e0b9 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Wed, 26 Jul 2023 12:32:20 +0200 Subject: [PATCH] cob: Stabilize formats > I'm going to be making a set of breaking changes to COBs in order to stabilize the data formats. This is hopefully a one-time change that bundles various breaking changes. All COBs have been reworked: issue, patch, id. The changes included are: * Revise the assign and tag actions to take a single list of assignees/tags to set, instead of an "add" and a "remove" list. This makes API usage simpler when editing issues, and simplifies the apply function * Rename "tags" to "labels", and the tag action to label. This is because tag is confusing in the context of git, as it could mean a git tag. Using label removes that confusion. * Use DIDs instead of PublicKeys for assignees -- this is more future-proof * Modify the manifest file format in the COB tree. Mainly, remove the `history_type` key which is redundant, and use camelCase for keys * Flatten the `Thread` actions into the parent action type * Ensure that operations on redacted objects do not fail, since redactions could have happened concurrently * Use a consistent naming scheme for actions, using `.` as separator * Consolidate comment types and remove `CodeComment`, by adding an optional `location` field to `Comment` * Add many placeholder actions that are not yet implemented To preserve backwards compatibility, a `legacy` module is created with the old `apply` function. When loading the manifest, we check whether it is a legacy COB or a "stable" COB, and in the legacy case, use the legacy code to materialize the state and then convert the object into the stable type. Eventually, we'll delete the legacy code. --- radicle-httpd/src/api/error.rs | 13 +- radicle-httpd/src/api/json.rs | 6 +- radicle-httpd/src/api/v1/projects.rs | 214 ++++++++++++--------------- radicle-httpd/src/test.rs | 15 +- 4 files changed, 115 insertions(+), 133 deletions(-) diff --git a/radicle-httpd/src/api/error.rs b/radicle-httpd/src/api/error.rs index f1763e266..6ecfacaf8 100644 --- a/radicle-httpd/src/api/error.rs +++ b/radicle-httpd/src/api/error.rs @@ -77,20 +77,29 @@ pub enum Error { /// Routing store error. #[error(transparent)] RoutingStore(#[from] radicle::node::routing::Error), + + /// Invalid update to issue or patch. + #[error("{0}")] + BadRequest(String), } impl IntoResponse for Error { fn into_response(self) -> Response { - let (status, msg) = match &self { + let message = self.to_string(); + let (status, msg) = match self { Error::NotFound => (StatusCode::NOT_FOUND, None), + Error::CobStore(radicle::cob::store::Error::NotFound(_, _)) => { + (StatusCode::NOT_FOUND, None) + } Error::Auth(msg) => (StatusCode::BAD_REQUEST, Some(msg.to_string())), Error::Crypto(msg) => (StatusCode::BAD_REQUEST, Some(msg.to_string())), Error::Git2(e) => ( StatusCode::INTERNAL_SERVER_ERROR, Some(e.message().to_owned()), ), + Error::BadRequest(msg) => (StatusCode::BAD_REQUEST, Some(msg)), other => { - tracing::error!("Error: {:?}", &self); + tracing::error!("Error: {message}"); if cfg!(debug_assertions) { ( diff --git a/radicle-httpd/src/api/json.rs b/radicle-httpd/src/api/json.rs index d3b9183da..88507adfb 100644 --- a/radicle-httpd/src/api/json.rs +++ b/radicle-httpd/src/api/json.rs @@ -108,7 +108,7 @@ pub(crate) fn issue(id: IssueId, issue: Issue, aliases: &impl AliasStore) -> Val .comments() .map(|(id, comment)| Comment::new(id, comment, aliases)) .collect::>(), - "tags": issue.tags().collect::>(), + "labels": issue.labels().collect::>(), }) } @@ -125,9 +125,9 @@ pub(crate) fn patch( "title": patch.title(), "state": patch.state(), "target": patch.target(), - "tags": patch.tags().collect::>(), + "labels": patch.labels().collect::>(), "merges": patch.merges().map(|(nid, m)| merge(m, nid, aliases.alias(nid))).collect::>(), - "reviewers": patch.reviewers().collect::>(), + "assignees": patch.assignees().collect::>(), "revisions": patch.revisions().map(|(id, rev)| { json!({ "id": id, diff --git a/radicle-httpd/src/api/v1/projects.rs b/radicle-httpd/src/api/v1/projects.rs index fd3d7c3ce..e2212ccd0 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -12,8 +12,8 @@ use serde::{Deserialize, Serialize}; use serde_json::json; use tower_http::set_header::SetResponseHeaderLayer; -use radicle::cob::{issue, patch, thread, ActorId, Tag}; -use radicle::identity::Id; +use radicle::cob::{issue, patch, Label}; +use radicle::identity::{Did, Id}; use radicle::node::routing::Store; use radicle::node::AliasStore; use radicle::node::NodeId; @@ -481,8 +481,8 @@ async fn issues_handler( pub struct IssueCreate { pub title: String, pub description: String, - pub tags: Vec, - pub assignees: Vec, + pub labels: Vec