Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
httpd: Add author information to patch and issue assignees
Merged did:key:z6MkkfM3...sVz5 opened 2 years ago
2 files changed +81 -3 a48081f2 501b6ba9
modified radicle-httpd/src/api/json.rs
@@ -104,7 +104,9 @@ pub(crate) fn issue(id: IssueId, issue: Issue, aliases: &impl AliasStore) -> Val
        "author": author(&issue.author(), aliases.alias(issue.author().id())),
        "title": issue.title(),
        "state": issue.state(),
-
        "assignees": issue.assignees().collect::<Vec<_>>(),
+
        "assignees": issue.assignees().map(|assignee|
+
            author(&Author::from(*assignee.as_key()), aliases.alias(assignee))
+
        ).collect::<Vec<_>>(),
        "discussion": issue.comments().map(|(id, c)| issue_comment(id, c, aliases)).collect::<Vec<_>>(),
        "labels": issue.labels().collect::<Vec<_>>(),
    })
@@ -125,7 +127,9 @@ pub(crate) fn patch(
        "target": patch.target(),
        "labels": patch.labels().collect::<Vec<_>>(),
        "merges": patch.merges().map(|(nid, m)| merge(nid, m, aliases)).collect::<Vec<_>>(),
-
        "assignees": patch.assignees().collect::<Vec<_>>(),
+
        "assignees": patch.assignees().map(|assignee|
+
            author(&Author::from(*assignee), aliases.alias(&*assignee))
+
        ).collect::<Vec<_>>(),
        "revisions": patch.revisions().map(|(id, rev)| {
            json!({
                "id": id,
modified radicle-httpd/src/api/v1/projects.rs
@@ -2311,6 +2311,78 @@ mod routes {
    }

    #[tokio::test]
+
    async fn test_projects_issues_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}/issues/{ISSUE_DISCUSSION_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}/issues/{ISSUE_DISCUSSION_ID}"),
+
        )
+
        .await;
+

+
        assert_eq!(
+
            response.json().await,
+
            json!({
+
              "id": ISSUE_DISCUSSION_ID,
+
              "author": {
+
                "id": CONTRIBUTOR_DID,
+
              },
+
              "title": "Issue #1",
+
              "state": {
+
                "status": "open",
+
              },
+
              "assignees": [
+
                { "id": CONTRIBUTOR_DID }
+
              ],
+
              "discussion": [
+
                {
+
                  "id": ISSUE_DISCUSSION_ID,
+
                  "author": {
+
                    "id": CONTRIBUTOR_DID,
+
                  },
+
                  "body": "Change 'hello world' to 'hello everyone'",
+
                  "edits": [
+
                    {
+
                      "author": {
+
                        "id": CONTRIBUTOR_DID,
+
                      },
+
                      "body": "Change 'hello world' to 'hello everyone'",
+
                      "timestamp": TIMESTAMP,
+
                      "embeds": [],
+
                    },
+
                  ],
+
                  "embeds": [],
+
                  "reactions": [],
+
                  "timestamp": TIMESTAMP,
+
                  "replyTo": null,
+
                  "resolved": false,
+
                },
+
              ],
+
              "labels": [],
+
            })
+
        );
+
    }
+

+
    #[tokio::test]
    async fn test_projects_issues_reply() {
        let tmp = tempfile::tempdir().unwrap();
        let ctx = contributor(tmp.path());
@@ -2661,7 +2733,9 @@ mod routes {
              "target": "delegates",
              "labels": [],
              "merges": [],
-
              "assignees": [CONTRIBUTOR_DID],
+
              "assignees": [
+
                { "id": CONTRIBUTOR_DID }
+
              ],
              "revisions": [
                {
                  "id": CONTRIBUTOR_PATCH_ID,