mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-10-28 16:00:45 +08:00
Add edit_issue command
This commit is contained in:
@@ -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 };
|
||||
@@ -38,6 +38,59 @@ pub fn create_issue(
|
||||
Ok::<_, Error>(cobs::Issue::new(issue.id(), &issue, &aliases))
|
||||
}
|
||||
|
||||
#[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>,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user