Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cob: Make json serialization consistent
Alexis Sellier committed 3 years ago
commit ca69fdc4fa532aef074b62fb9a765e38d1db298b
parent f9c81ab3829724cf1ebe346d07dc2ccda44c958d
4 files changed +24 -8
modified radicle/src/cob/issue.rs
@@ -36,7 +36,7 @@ pub enum Error {

/// Reason why an issue was closed.
#[derive(Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize)]
-
#[serde(rename_all = "lowercase")]
+
#[serde(rename_all = "camelCase")]
pub enum CloseReason {
    Other,
    Solved,
@@ -44,7 +44,7 @@ pub enum CloseReason {

/// Issue state.
#[derive(Debug, Default, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize)]
-
#[serde(rename_all = "lowercase", tag = "status")]
+
#[serde(rename_all = "camelCase", tag = "status")]
pub enum Status {
    /// The issue is closed.
    Closed { reason: CloseReason },
@@ -74,7 +74,6 @@ impl Status {
/// Issue state. Accumulates [`Action`].
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Issue {
-
    // TODO(cloudhead): Title should bias towards shorter strings.
    title: LWWReg<Max<String>, clock::Lamport>,
    status: LWWReg<Max<Status>, clock::Lamport>,
    tags: LWWSet<Tag>,
@@ -382,6 +381,7 @@ impl<'a> Issues<'a> {

/// Issue operation.
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
+
#[serde(tag = "type", rename_all = "camelCase")]
pub enum Action {
    Title { title: String },
    Lifecycle { status: Status },
modified radicle/src/cob/op.rs
@@ -1,6 +1,5 @@
use std::collections::BTreeMap;

-
use serde::{Deserialize, Serialize};
use thiserror::Error;

use radicle_cob::history::EntryWithClock;
@@ -24,7 +23,7 @@ pub enum OpDecodeError {
///
/// Everything that can be done in the system is represented by an `Op`.
/// Operations are applied to an accumulator to yield a final state.
-
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Op<A> {
    /// The action carried out by this operation.
    pub action: A,
@@ -67,7 +66,7 @@ pub struct Actor<G, A> {
    pub ops: BTreeMap<(Lamport, PublicKey), Op<A>>,
}

-
impl<G: Signer, A: Clone + Serialize> Actor<G, A> {
+
impl<G: Signer, A: Clone> Actor<G, A> {
    pub fn new(signer: G) -> Self {
        Self {
            signer,
modified radicle/src/cob/patch.rs
@@ -66,6 +66,7 @@ pub enum Error {

/// Patch operation.
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
+
#[serde(tag = "type", rename_all = "camelCase")]
pub enum Action {
    Edit {
        title: String,
@@ -379,7 +380,7 @@ impl Revision {
}

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
-
#[serde(rename_all = "lowercase")]
+
#[serde(rename_all = "camelCase")]
pub enum Status {
    #[default]
    Proposed,
@@ -389,6 +390,7 @@ pub enum Status {

/// A merged patch revision.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
+
#[serde(rename_all = "camelCase")]
pub struct Merge {
    /// Owner of repository that this patch was merged into.
    pub node: NodeId,
@@ -400,7 +402,7 @@ pub struct Merge {

/// A patch review verdict.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
-
#[serde(rename_all = "lowercase")]
+
#[serde(rename_all = "camelCase")]
pub enum Verdict {
    /// Accept patch.
    Accept,
@@ -427,6 +429,7 @@ impl fmt::Display for Verdict {

/// Code location, used for attaching comments.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+
#[serde(rename_all = "camelCase")]
pub struct CodeLocation {
    /// File being commented on.
    pub blob: git::Oid,
@@ -455,6 +458,7 @@ impl Ord for CodeLocation {

/// Comment on code.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
+
#[serde(rename_all = "camelCase")]
pub struct CodeComment {
    /// Code location of the comment.
    pub location: CodeLocation,
@@ -934,6 +938,18 @@ mod test {
    }

    #[test]
+
    fn test_json_serialization() {
+
        let edit = Action::Tag {
+
            add: vec![],
+
            remove: vec![],
+
        };
+
        assert_eq!(
+
            serde_json::to_string(&edit).unwrap(),
+
            String::from(r#"{"type":"tag","add":[],"remove":[]}"#)
+
        );
+
    }
+

+
    #[test]
    fn test_patch_create_and_get() {
        let tmp = tempfile::tempdir().unwrap();
        let (_, signer, project) = test::setup::context(&tmp);
modified radicle/src/cob/thread.rs
@@ -60,6 +60,7 @@ impl PartialOrd for Comment {

/// An action that can be carried out in a change.
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
+
#[serde(tag = "type", rename_all = "camelCase")]
pub enum Action {
    /// Comment on a thread.
    Comment {