From 38f602835e75020cad9e066d23b346506dc5ae39 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Thu, 26 Sep 2024 10:54:23 +0200 Subject: [PATCH] Add `new_issue` tauri command --- src-tauri/bindings/NewIssue.ts | 9 +++++++++ src-tauri/src/commands/cob/issue.rs | 26 ++++++++++++++++++++++++-- src-tauri/src/lib.rs | 1 + src-tauri/src/types/cobs.rs | 16 +++++++++++++++- 4 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 src-tauri/bindings/NewIssue.ts diff --git a/src-tauri/bindings/NewIssue.ts b/src-tauri/bindings/NewIssue.ts new file mode 100644 index 0000000..e4190e0 --- /dev/null +++ b/src-tauri/bindings/NewIssue.ts @@ -0,0 +1,9 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type NewIssue = { + title: string; + description: string; + labels: Array; + assignees: Array; + embeds: { name: string; content: string }[]; +}; diff --git a/src-tauri/src/commands/cob/issue.rs b/src-tauri/src/commands/cob/issue.rs index edaf2cc..733b414 100644 --- a/src-tauri/src/commands/cob/issue.rs +++ b/src-tauri/src/commands/cob/issue.rs @@ -7,6 +7,28 @@ use crate::error::Error; use crate::types::cobs; use crate::AppState; +#[tauri::command] +pub fn new_issue( + ctx: tauri::State, + rid: RepoId, + new: cobs::NewIssue, +) -> Result { + let (repo, _) = ctx.repo(rid)?; + let signer = ctx.profile.signer()?; + let aliases = ctx.profile.aliases(); + let mut issues = ctx.profile.issues_mut(&repo)?; + let issue = issues.create( + new.title, + new.description, + &new.labels, + &new.assignees, + new.embeds, + &signer, + )?; + + Ok::<_, Error>(cobs::Issue::new(issue.id(), &issue, &aliases)) +} + #[tauri::command] pub fn list_issues( ctx: tauri::State, @@ -27,7 +49,7 @@ pub fn list_issues( let aliases = &ctx.profile.aliases(); let issues = issues .into_iter() - .map(|(id, issue)| cobs::Issue::new(id, issue, aliases)) + .map(|(id, issue)| cobs::Issue::new(&id, &issue, aliases)) .collect::>(); Ok::<_, Error>(issues) @@ -44,7 +66,7 @@ pub fn issue_by_id( let issue = issues.get(&id.into())?; let aliases = &ctx.profile.aliases(); - let issue = issue.map(|issue| cobs::Issue::new(id.into(), issue, aliases)); + let issue = issue.map(|issue| cobs::Issue::new(&id.into(), &issue, aliases)); Ok::<_, Error>(issue) } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 2282bc1..42593fb 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -143,6 +143,7 @@ pub fn run() { repo::diff_stats, cob::issue::list_issues, cob::issue::issue_by_id, + cob::issue::new_issue, cob::patch::list_patches, cob::patch::patch_by_id, cob::patch::revisions_by_patch, diff --git a/src-tauri/src/types/cobs.rs b/src-tauri/src/types/cobs.rs index 9bd3985..cef0782 100644 --- a/src-tauri/src/types/cobs.rs +++ b/src-tauri/src/types/cobs.rs @@ -50,7 +50,7 @@ pub struct Issue { } impl Issue { - pub fn new(id: issue::IssueId, issue: issue::Issue, aliases: &impl AliasStore) -> Self { + pub fn new(id: &issue::IssueId, issue: &issue::Issue, aliases: &impl AliasStore) -> Self { Self { id: id.to_string(), author: Author::new(*issue.author().id(), aliases), @@ -360,6 +360,20 @@ pub struct NewPatchComment { pub embeds: Vec, } +#[derive(TS, Serialize, Deserialize)] +#[ts(export)] +#[serde(rename_all = "camelCase")] +pub struct NewIssue { + pub title: String, + pub description: String, + #[ts(as = "Vec")] + pub labels: Vec, + #[ts(as = "Vec")] + pub assignees: Vec, + #[ts(type = "{ name: string, content: string }[]")] + pub embeds: Vec, +} + #[derive(TS, Serialize, Deserialize)] #[ts(export)] #[serde(rename_all = "camelCase")]