Radish alpha
r
Radicle desktop app
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add `edit_issue` command
Sebastian Martinez committed 1 year ago
commit 6ea83dec47b9bb0f01edcfbee5a308d395135b38
parent 05fc9ec46c4ca177d5242d86967fb7297a481ffc
4 files changed +179 -0
added crates/radicle-tauri/bindings/IssueAction.ts
@@ -0,0 +1,46 @@
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
+

+
export type IssueAction =
+
  | { type: "assign"; assignees: Array<string> }
+
  | { type: "edit"; title: string }
+
  | {
+
      type: "lifecycle";
+
      state:
+
        | { status: "closed"; reason: "other" | "solved" }
+
        | { status: "open" };
+
    }
+
  | { type: "label"; labels: Array<string> }
+
  | {
+
      type: "comment";
+
      /**
+
       * Comment body.
+
       */
+
      body: string;
+
      /**
+
       * Comment this is a reply to.
+
       * Should be [`None` | `null`] if it's the top-level comment.
+
       * Should be the root [`CommentId`] if it's a top-level comment.
+
       */
+
      replyTo: string | null;
+
      /**
+
       * Embeded content.
+
       */
+
      embeds: Array<string>;
+
    }
+
  | {
+
      type: "comment.edit";
+
      /**
+
       * Comment being edited.
+
       */
+
      id: string;
+
      /**
+
       * New value for the comment body.
+
       */
+
      body: string;
+
      /**
+
       * New value for the embeds list.
+
       */
+
      embeds: Array<string>;
+
    }
+
  | { type: "comment.redact"; id: string }
+
  | { type: "comment.react"; id: string; reaction: string; active: boolean };
modified crates/radicle-tauri/src/commands/cob/issue.rs
@@ -39,6 +39,59 @@ pub fn create_issue(
}

#[tauri::command]
+
pub fn edit_issue(
+
    ctx: tauri::State<AppState>,
+
    rid: RepoId,
+
    cob_id: git::Oid,
+
    action: cobs::IssueAction,
+
    opts: cobs::CobOptions,
+
) -> Result<cobs::Issue, Error> {
+
    let mut node = Node::new(ctx.profile.socket());
+
    let repo = ctx.profile.storage.repository(rid)?;
+
    let signer = ctx.profile.signer()?;
+
    let aliases = ctx.profile.aliases();
+
    let mut issues = ctx.profile.issues_mut(&repo)?;
+
    let mut issue = issues.get_mut(&cob_id.into())?;
+

+
    match action {
+
        cobs::IssueAction::Lifecycle { state } => {
+
            issue.lifecycle(state, &signer)?;
+
        }
+
        cobs::IssueAction::Assign { assignees } => {
+
            issue.assign(assignees, &signer)?;
+
        }
+
        cobs::IssueAction::Label { labels } => {
+
            issue.label(labels, &signer)?;
+
        }
+
        cobs::IssueAction::CommentReact {
+
            id,
+
            reaction,
+
            active,
+
        } => {
+
            issue.react(id, reaction, active, &signer)?;
+
        }
+
        cobs::IssueAction::CommentRedact { id } => {
+
            issue.redact_comment(id, &signer)?;
+
        }
+
        cobs::IssueAction::Comment { .. } => {
+
            unimplemented!("Create of issue comment not yet implemented")
+
        }
+
        cobs::IssueAction::CommentEdit { .. } => {
+
            unimplemented!("Edit of issue comment not yet implemented")
+
        }
+
        cobs::IssueAction::Edit { title } => {
+
            issue.edit(title, &signer)?;
+
        }
+
    }
+

+
    if opts.announce() {
+
        node.announce_refs(rid)?;
+
    }
+

+
    Ok::<_, Error>(cobs::Issue::new(issue.id(), &issue, &aliases))
+
}
+

+
#[tauri::command]
pub fn list_issues(
    ctx: tauri::State<AppState>,
    rid: RepoId,
modified crates/radicle-tauri/src/lib.rs
@@ -80,6 +80,7 @@ pub fn run() {
            cob::issue::list_issues,
            cob::issue::issue_by_id,
            cob::issue::create_issue,
+
            cob::issue::edit_issue,
            cob::patch::list_patches,
            cob::patch::patch_by_id,
            cob::patch::revisions_by_patch,
modified crates/radicle-tauri/src/types/cobs.rs
@@ -1,4 +1,5 @@
use std::collections::BTreeMap;
+
use std::collections::BTreeSet;

use serde::{Deserialize, Serialize};
use ts_rs::TS;
@@ -352,3 +353,81 @@ impl Stats {
        }
    }
}
+

+
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, TS)]
+
#[serde(tag = "type", rename_all = "camelCase")]
+
#[ts(export)]
+
pub enum IssueAction {
+
    /// Assign issue to an actor.
+
    #[serde(rename = "assign")]
+
    Assign {
+
        #[ts(as = "Vec<String>")]
+
        assignees: BTreeSet<identity::Did>,
+
    },
+

+
    /// Edit issue title.
+
    #[serde(rename = "edit")]
+
    Edit { title: String },
+

+
    /// Transition to a different state.
+
    #[serde(rename = "lifecycle")]
+
    Lifecycle {
+
        #[ts(type = "{ status: 'closed', reason: 'other' | 'solved' } | { status: 'open' } ")]
+
        state: issue::State,
+
    },
+

+
    /// Modify issue labels.
+
    #[serde(rename = "label")]
+
    Label {
+
        #[ts(as = "Vec<String>")]
+
        labels: BTreeSet<cob::Label>,
+
    },
+

+
    /// Comment on a thread.
+
    #[serde(rename_all = "camelCase")]
+
    #[serde(rename = "comment")]
+
    Comment {
+
        /// Comment body.
+
        body: String,
+
        /// Comment this is a reply to.
+
        /// Should be [`None` | `null`] if it's the top-level comment.
+
        /// Should be the root [`CommentId`] if it's a top-level comment.
+
        #[serde(default, skip_serializing_if = "Option::is_none")]
+
        #[ts(as = "Option<String>")]
+
        reply_to: Option<cob::thread::CommentId>,
+
        /// Embeded content.
+
        #[serde(default, skip_serializing_if = "Vec::is_empty")]
+
        #[ts(as = "Vec<String>")]
+
        embeds: Vec<cob::Embed<cob::Uri>>,
+
    },
+

+
    /// Edit a comment.
+
    #[serde(rename = "comment.edit")]
+
    CommentEdit {
+
        /// Comment being edited.
+
        #[ts(as = "String")]
+
        id: cob::thread::CommentId,
+
        /// New value for the comment body.
+
        body: String,
+
        /// New value for the embeds list.
+
        #[ts(as = "Vec<String>")]
+
        embeds: Vec<cob::Embed<cob::Uri>>,
+
    },
+

+
    /// Redact a change. Not all changes can be redacted.
+
    #[serde(rename = "comment.redact")]
+
    CommentRedact {
+
        #[ts(as = "String")]
+
        id: cob::thread::CommentId,
+
    },
+

+
    /// React to a comment.
+
    #[serde(rename = "comment.react")]
+
    CommentReact {
+
        #[ts(as = "String")]
+
        id: cob::thread::CommentId,
+
        #[ts(as = "String")]
+
        reaction: cob::Reaction,
+
        active: bool,
+
    },
+
}