Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
httpd: Return `alias` field on `merges` of a patch
xphoniex committed 2 years ago
commit 273a527cd7cf27b6e33f0cad19e79ec0030b3b87
parent c7357832469f8b8cbf245a93353d564cf74c9e7a
2 files changed +78 -32
modified radicle-httpd/src/api/json.rs
@@ -7,12 +7,15 @@ use serde::Serialize;
use serde_json::{json, Value};

use radicle::cob::issue::{Issue, IssueId};
+
use radicle::cob::patch::Merge;
+
use radicle::cob::patch::Review;
use radicle::cob::patch::{Patch, PatchId};
use radicle::cob::thread;
use radicle::cob::thread::{CommentId, Thread};
use radicle::cob::{ActorId, Author, Reaction, Timestamp};
use radicle::git::RefString;
use radicle::node::tracking::store as TrackingStore;
+
use radicle::prelude::NodeId;
use radicle::storage::{git, refs, ReadRepository};
use radicle_surf::blob::Blob;
use radicle_surf::tree::Tree;
@@ -122,14 +125,7 @@ pub(crate) fn patch(
        "state": patch.state(),
        "target": patch.target(),
        "tags": patch.tags().collect::<Vec<_>>(),
-
        "merges": patch.merges().map(|(a, m)| {
-
            json!({
-
                "author": a,
-
                "revision": m.revision,
-
                "commit": m.commit,
-
                "timestamp": m.timestamp
-
            })
-
        }).collect::<Vec<_>>(),
+
        "merges": patch.merges().map(|(nid, m)| merge(m, nid, aliases.alias(nid))).collect::<Vec<_>>(),
        "reviewers": patch.reviewers().collect::<Vec<_>>(),
        "revisions": patch.revisions().map(|(id, rev)| {
            json!({
@@ -143,7 +139,7 @@ pub(crate) fn patch(
                  .map(|(id, comment)| Comment::new(id, comment, rev.discussion(), aliases))
                  .collect::<Vec<_>>(),
                "timestamp": rev.timestamp(),
-
                "reviews": rev.reviews().collect::<Vec<_>>(),
+
                "reviews": rev.reviews().map(|(nid, _review)| review(nid, aliases.alias(nid), _review)).collect::<Vec<_>>(),
            })
        }).collect::<Vec<_>>(),
    })
@@ -160,6 +156,54 @@ fn author(author: &Author, alias: Option<String>) -> Value {
    }
}

+
/// Returns JSON for a patch `Merge` and fills in `alias` when present.
+
fn merge(merge: &Merge, nid: &NodeId, alias: Option<String>) -> Value {
+
    match alias {
+
        Some(alias) => json!({
+
            "author": {
+
                "id": nid,
+
                "alias": alias,
+
            },
+
            "commit": merge.commit,
+
            "timestamp": merge.timestamp,
+
            "revision": merge.revision,
+
        }),
+
        None => json!({
+
            "author": {
+
                "id": nid,
+
            },
+
            "commit": merge.commit,
+
            "timestamp": merge.timestamp,
+
            "revision": merge.revision,
+
        }),
+
    }
+
}
+

+
/// Returns JSON for a patch `Review` and fills in `alias` when present.
+
fn review(nid: &NodeId, alias: Option<String>, review: &Review) -> Value {
+
    match alias {
+
        Some(alias) => json!({
+
            "author": {
+
                "id": nid,
+
                "alias": alias,
+
            },
+
            "verdict": review.verdict(),
+
            "comment": review.comment(),
+
            "inline": review.inline().collect::<Vec<_>>(),
+
            "timestamp": review.timestamp(),
+
        }),
+
        None => json!({
+
            "author": {
+
                "id": nid,
+
            },
+
            "verdict": review.verdict(),
+
            "comment": review.comment(),
+
            "inline": review.inline().collect::<Vec<_>>(),
+
            "timestamp": review.timestamp(),
+
        }),
+
    }
+
}
+

/// Returns the name part of a path string.
fn name_in_path(path: &str) -> &str {
    match path.rsplit('/').next() {
modified radicle-httpd/src/api/v1/projects.rs
@@ -2271,29 +2271,29 @@ mod routes {
                  "discussions": [],
                  "timestamp": TIMESTAMP,
                  "reviews": [
-
                    [
-
                      CONTRIBUTOR_NID,
-
                      {
-
                        "verdict": "accept",
-
                        "comment": "A small review",
-
                        "inline": [
-
                          {
-
                            "location": {
-
                              "blob": "82eb77880c693655bce074e3dbbd9fa711dc018b",
-
                              "path": "./README.md",
-
                              "commit": HEAD,
-
                              "lines": {
-
                                "start": 1,
-
                                "end": 3,
-
                              },
-
                            },
-
                            "comment": "This is a comment on line 1",
-
                            "timestamp": TIMESTAMP,
-
                          }
-
                        ],
-
                        "timestamp": TIMESTAMP,
+
                    {
+
                      "author": {
+
                          "id": CONTRIBUTOR_NID,
                      },
-
                    ],
+
                      "verdict": "accept",
+
                      "comment": "A small review",
+
                      "inline": [
+
                        {
+
                          "location": {
+
                            "blob": "82eb77880c693655bce074e3dbbd9fa711dc018b",
+
                            "path": "./README.md",
+
                            "commit": HEAD,
+
                            "lines": {
+
                              "start": 1,
+
                              "end": 3,
+
                            },
+
                          },
+
                          "comment": "This is a comment on line 1",
+
                          "timestamp": TIMESTAMP,
+
                        }
+
                      ],
+
                      "timestamp": TIMESTAMP,
+
                    },
                  ],
                },
              ],
@@ -2345,7 +2345,9 @@ mod routes {
              "target": "delegates",
              "tags": [],
              "merges": [{
-
                  "author": CONTRIBUTOR_NID,
+
                  "author": {
+
                    "id": CONTRIBUTOR_NID,
+
                  },
                  "revision": CONTRIBUTOR_PATCH_ID,
                  "commit": PARENT,
                  "timestamp": TIMESTAMP,