Skip to content

Commit

Permalink
Add new_issue tauri command
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastinez authored and rudolfs committed Sep 26, 2024
1 parent ddf44ce commit 38f6028
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src-tauri/bindings/NewIssue.ts
Original file line number Diff line number Diff line change
@@ -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<string>;
assignees: Array<string>;
embeds: { name: string; content: string }[];
};
26 changes: 24 additions & 2 deletions src-tauri/src/commands/cob/issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@ use crate::error::Error;
use crate::types::cobs;
use crate::AppState;

#[tauri::command]
pub fn new_issue(
ctx: tauri::State<AppState>,
rid: RepoId,
new: cobs::NewIssue,
) -> Result<cobs::Issue, Error> {
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<AppState>,
Expand All @@ -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::<Vec<_>>();

Ok::<_, Error>(issues)
Expand All @@ -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)
}
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 15 additions & 1 deletion src-tauri/src/types/cobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -360,6 +360,20 @@ pub struct NewPatchComment {
pub embeds: Vec<cob::Embed>,
}

#[derive(TS, Serialize, Deserialize)]
#[ts(export)]
#[serde(rename_all = "camelCase")]
pub struct NewIssue {
pub title: String,
pub description: String,
#[ts(as = "Vec<String>")]
pub labels: Vec<cob::Label>,
#[ts(as = "Vec<String>")]
pub assignees: Vec<identity::Did>,
#[ts(type = "{ name: string, content: string }[]")]
pub embeds: Vec<cob::Embed>,
}

#[derive(TS, Serialize, Deserialize)]
#[ts(export)]
#[serde(rename_all = "camelCase")]
Expand Down

0 comments on commit 38f6028

Please sign in to comment.