Skip to content

Commit 037ac39

Browse files
committed
Add issues_by_id, patches_by_id, revisions_by_patch, revisions_by_id
Also provides all the types related to it and a new npm script that allows generating those types quickly.
1 parent 9334ffb commit 037ac39

File tree

12 files changed

+410
-5
lines changed

12 files changed

+410
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"check-js": "scripts/check-js",
1313
"check-rs": "scripts/check-rs",
1414
"format": "npx prettier '**/*.@(ts|js|svelte|json|css|html|yml)' --write",
15+
"generate-types": "cargo test --manifest-path ./src-tauri/Cargo.toml && npx prettier ./src-tauri/bindings --write",
1516
"tauri": "npx tauri"
1617
},
1718
"engines": {

src-tauri/bindings/Comment.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2+
import type { Author } from "./Author";
3+
import type { Edit } from "./Edit";
4+
import type { Never } from "./Never";
5+
6+
export type Comment<T = Never> = {
7+
id: string;
8+
author: Author;
9+
edits: Array<Edit>;
10+
reactions: string;
11+
replyTo?: string;
12+
location?: T;
13+
resolved: boolean;
14+
};

src-tauri/bindings/Edit.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2+
import type { Author } from "./Author";
3+
4+
export type Edit = {
5+
author: Author;
6+
timestamp: bigint;
7+
body: string;
8+
embeds: { name: string; content: string };
9+
};

src-tauri/bindings/Issue.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
22
import type { Author } from "./Author";
3+
import type { Comment } from "./Comment";
4+
import type { Never } from "./Never";
35

46
export type Issue = {
57
id: string;
68
author: Author;
79
title: string;
810
state: { status: "closed"; reason: "other" | "solved" } | { status: "open" };
911
assignees: Array<Author>;
12+
discussion: Array<Comment<Never>>;
1013
labels: Array<string>;
1114
timestamp: number;
1215
};

src-tauri/bindings/Never.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2+
3+
/**
4+
* The `Infallible` type does not have a `Serialize`/`Deserialize`
5+
* implementation. The `Never` type imitates `Infallible` and
6+
* provides the derived implementations.
7+
*/
8+
export type Never = never;

src-tauri/bindings/Reaction.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2+
import type { Author } from "./Author";
3+
import type { CodeLocation } from "./CodeLocation";
4+
5+
export type Reaction = {
6+
emoji: string;
7+
authors: Array<Author>;
8+
location?: CodeLocation;
9+
};

src-tauri/bindings/Review.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2+
import type { Author } from "./Author";
3+
import type { CodeLocation } from "./CodeLocation";
4+
import type { Comment } from "./Comment";
5+
6+
export type Review = {
7+
id: string;
8+
author: Author;
9+
verdict?: "accept" | "reject";
10+
summary: string | null;
11+
comments: Array<Comment<CodeLocation>>;
12+
timestamp: bigint;
13+
};

src-tauri/bindings/Revision.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2+
import type { Author } from "./Author";
3+
import type { CodeLocation } from "./CodeLocation";
4+
import type { Comment } from "./Comment";
5+
import type { Edit } from "./Edit";
6+
import type { Reaction } from "./Reaction";
7+
import type { Review } from "./Review";
8+
9+
export type Revision = {
10+
author: Author;
11+
description: Array<Edit>;
12+
base: string;
13+
oid: string;
14+
reviews: Array<Review>;
15+
timestamp: bigint;
16+
discussion: Array<Comment<CodeLocation>>;
17+
reactions: Array<Reaction>;
18+
};

src-tauri/src/commands/auth.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use anyhow::anyhow;
2+
23
use radicle::crypto::ssh;
34

45
use crate::{error::Error, AppState};

src-tauri/src/commands/cobs.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
use std::str::FromStr;
2+
3+
use radicle::cob::ObjectId;
4+
use radicle::git::Oid;
15
use radicle::identity::RepoId;
26
use radicle::issue::cache::Issues;
7+
use radicle::issue::IssueId;
38
use radicle::patch::cache::Patches;
49

510
use crate::error::Error;
@@ -32,6 +37,22 @@ pub fn list_issues(
3237
Ok::<_, Error>(issues)
3338
}
3439

40+
#[tauri::command]
41+
pub fn issues_by_id(
42+
ctx: tauri::State<AppState>,
43+
rid: RepoId,
44+
id: IssueId,
45+
) -> Result<Option<cobs::Issue>, Error> {
46+
let (repo, _) = ctx.repo(rid)?;
47+
let issues = ctx.profile.issues(&repo)?;
48+
let issue = issues.get(&id)?;
49+
50+
let aliases = &ctx.profile.aliases();
51+
let issue = issue.map(|issue| cobs::Issue::new(id, issue, aliases));
52+
53+
Ok::<_, Error>(issue)
54+
}
55+
3556
#[tauri::command]
3657
pub fn list_patches(
3758
ctx: tauri::State<AppState>,
@@ -58,6 +79,66 @@ pub fn list_patches(
5879
Ok::<_, Error>(patches)
5980
}
6081

82+
#[tauri::command]
83+
pub fn patches_by_id(
84+
ctx: tauri::State<AppState>,
85+
rid: RepoId,
86+
id: String,
87+
) -> Result<Option<cobs::Patch>, Error> {
88+
let id = ObjectId::from_str(&id)?;
89+
let (repo, _) = ctx.repo(rid)?;
90+
let patches = ctx.profile.patches(&repo)?;
91+
let patch = patches.get(&id)?;
92+
93+
let aliases = &ctx.profile.aliases();
94+
let patches = patch.map(|patch| cobs::Patch::new(id, patch, aliases));
95+
96+
Ok::<_, Error>(patches)
97+
}
98+
99+
#[tauri::command]
100+
pub fn revisions_by_patch(
101+
ctx: tauri::State<AppState>,
102+
rid: RepoId,
103+
id: String,
104+
) -> Result<Option<Vec<cobs::Revision>>, Error> {
105+
let id = ObjectId::from_str(&id)?;
106+
let (repo, _) = ctx.repo(rid)?;
107+
let patches = ctx.profile.patches(&repo)?;
108+
109+
let revisions = patches.get(&id)?.map(|patch| {
110+
let aliases = &ctx.profile.aliases();
111+
112+
patch
113+
.revisions()
114+
.map(|(_, r)| cobs::Revision::new(r.clone(), aliases))
115+
.collect::<Vec<_>>()
116+
});
117+
118+
Ok::<_, Error>(revisions)
119+
}
120+
121+
#[tauri::command]
122+
pub fn revisions_by_id(
123+
ctx: tauri::State<AppState>,
124+
rid: RepoId,
125+
id: String,
126+
revision_id: String,
127+
) -> Result<Option<cobs::Revision>, Error> {
128+
let id = ObjectId::from_str(&id)?;
129+
let (repo, _) = ctx.repo(rid)?;
130+
let patches = ctx.profile.patches(&repo)?;
131+
let revision = patches.get(&id)?.and_then(|patch| {
132+
let revision_id = Oid::from_str(&revision_id).ok()?;
133+
let aliases = &ctx.profile.aliases();
134+
135+
patch
136+
.revision(&revision_id.into())
137+
.map(|r| cobs::Revision::new(r.clone(), aliases))
138+
});
139+
Ok::<_, Error>(revision)
140+
}
141+
61142
mod query {
62143
use serde::{Deserialize, Serialize};
63144

src-tauri/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,13 @@ pub fn run() {
141141
repos::list_repos,
142142
repos::repo_by_id,
143143
cobs::list_issues,
144+
cobs::issues_by_id,
144145
cobs::list_patches,
145146
thread::create_issue_comment,
146147
thread::create_patch_comment,
148+
cobs::patches_by_id,
149+
cobs::revisions_by_patch,
150+
cobs::revisions_by_id,
147151
profile::config,
148152
])
149153
.run(tauri::generate_context!())

0 commit comments

Comments
 (0)