-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tauri commands for single repo and cobs
- Loading branch information
1 parent
0a059da
commit 560891d
Showing
14 changed files
with
282 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. | ||
|
||
export type Author = { did: string; alias?: string }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. | ||
import type { Author } from "./Author"; | ||
|
||
export type Issue = { | ||
id: string; | ||
author: Author; | ||
title: string; | ||
state: { status: "closed"; reason: "other" | "solved" } | { status: "open" }; | ||
assignees: Array<Author>; | ||
labels: Array<string>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. | ||
import type { Author } from "./Author"; | ||
|
||
export type Patch = { | ||
id: string; | ||
author: Author; | ||
title: string; | ||
state: | ||
| { | ||
status: "draft"; | ||
} | ||
| { | ||
status: "open"; | ||
conflicts: [string, string][]; | ||
} | ||
| { | ||
status: "archived"; | ||
} | ||
| { | ||
status: "merged"; | ||
revision: string; | ||
commit: string; | ||
}; | ||
assignees: Array<Author>; | ||
labels: Array<string>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod auth; | ||
pub mod cobs; | ||
pub mod profile; | ||
pub mod repos; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
use radicle::identity::RepoId; | ||
use radicle::issue::cache::Issues; | ||
use radicle::patch::cache::Patches; | ||
|
||
use crate::error::Error; | ||
use crate::types::cobs; | ||
use crate::AppState; | ||
|
||
#[tauri::command] | ||
pub fn list_issues( | ||
ctx: tauri::State<AppState>, | ||
rid: RepoId, | ||
status: query::IssueStatus, | ||
) -> Result<Vec<cobs::Issue>, Error> { | ||
let (repo, _) = ctx.repo(rid)?; | ||
let issues = ctx.profile.issues(&repo)?; | ||
let mut issues: Vec<_> = issues | ||
.list()? | ||
.filter_map(|r| { | ||
let (id, issue) = r.ok()?; | ||
(status.matches(issue.state())).then_some((id, issue)) | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
issues.sort_by(|(_, a), (_, b)| b.timestamp().cmp(&a.timestamp())); | ||
let aliases = &ctx.profile.aliases(); | ||
let issues = issues | ||
.into_iter() | ||
.map(|(id, issue)| cobs::Issue::new(id, issue, aliases)) | ||
.collect::<Vec<_>>(); | ||
|
||
Ok::<_, Error>(issues) | ||
} | ||
|
||
#[tauri::command] | ||
pub fn list_patches( | ||
ctx: tauri::State<AppState>, | ||
rid: RepoId, | ||
status: query::PatchStatus, | ||
) -> Result<Vec<cobs::Patch>, Error> { | ||
let (repo, _) = ctx.repo(rid)?; | ||
let patches = ctx.profile.patches(&repo)?; | ||
let mut patches: Vec<_> = patches | ||
.list()? | ||
.filter_map(|r| { | ||
let (id, patch) = r.ok()?; | ||
(status.matches(patch.state())).then_some((id, patch)) | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
patches.sort_by(|(_, a), (_, b)| b.timestamp().cmp(&a.timestamp())); | ||
let aliases = &ctx.profile.aliases(); | ||
let patches = patches | ||
.into_iter() | ||
.map(|(id, patch)| cobs::Patch::new(id, patch, aliases)) | ||
.collect::<Vec<_>>(); | ||
|
||
Ok::<_, Error>(patches) | ||
} | ||
|
||
mod query { | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use radicle::issue; | ||
use radicle::patch; | ||
|
||
#[derive(Default, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub enum IssueStatus { | ||
Closed, | ||
#[default] | ||
Open, | ||
All, | ||
} | ||
|
||
impl IssueStatus { | ||
pub fn matches(&self, issue: &issue::State) -> bool { | ||
match self { | ||
Self::Open => matches!(issue, issue::State::Open), | ||
Self::Closed => matches!(issue, issue::State::Closed { .. }), | ||
Self::All => true, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Default, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub enum PatchStatus { | ||
#[default] | ||
Open, | ||
Draft, | ||
Archived, | ||
Merged, | ||
All, | ||
} | ||
|
||
impl PatchStatus { | ||
pub fn matches(&self, patch: &patch::State) -> bool { | ||
match self { | ||
Self::Open => matches!(patch, patch::State::Open { .. }), | ||
Self::Draft => matches!(patch, patch::State::Draft), | ||
Self::Archived => matches!(patch, patch::State::Archived), | ||
Self::Merged => matches!(patch, patch::State::Merged { .. }), | ||
Self::All => true, | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
use radicle::cob::Label; | ||
use radicle::identity; | ||
use radicle::issue; | ||
use radicle::node::{Alias, AliasStore}; | ||
use radicle::patch; | ||
use serde::Serialize; | ||
use ts_rs::TS; | ||
|
||
#[derive(Serialize, TS)] | ||
pub(crate) struct Author { | ||
#[ts(as = "String")] | ||
did: identity::Did, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
#[ts(as = "Option<String>")] | ||
#[ts(optional)] | ||
alias: Option<Alias>, | ||
} | ||
|
||
impl Author { | ||
pub fn new(did: identity::Did, aliases: &impl AliasStore) -> Self { | ||
Self { | ||
did, | ||
alias: aliases.alias(&did), | ||
} | ||
} | ||
} | ||
|
||
#[derive(TS, Serialize)] | ||
#[ts(export)] | ||
pub struct Issue { | ||
#[ts(as = "String")] | ||
id: String, | ||
author: Author, | ||
title: String, | ||
#[ts(type = "{ status: 'closed', reason: 'other' | 'solved' } | { status: 'open' } ")] | ||
state: issue::State, | ||
assignees: Vec<Author>, | ||
#[ts(as = "Vec<String>")] | ||
labels: Vec<Label>, | ||
} | ||
|
||
impl Issue { | ||
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), | ||
title: issue.title().to_string(), | ||
state: *issue.state(), | ||
assignees: issue | ||
.assignees() | ||
.map(|did| Author::new(*did, aliases)) | ||
.collect::<Vec<_>>(), | ||
labels: issue.labels().cloned().collect::<Vec<_>>(), | ||
} | ||
} | ||
} | ||
|
||
#[derive(TS, Serialize)] | ||
#[ts(export)] | ||
pub struct Patch { | ||
#[ts(as = "String")] | ||
id: String, | ||
author: Author, | ||
title: String, | ||
#[ts(type = r#"{ | ||
status: 'draft' | ||
} | { | ||
status: 'open', | ||
conflicts: [string, string][] | ||
} | { | ||
status: 'archived' | ||
} | { | ||
status: 'merged', revision: string, commit: string | ||
} "#)] | ||
state: patch::State, | ||
assignees: Vec<Author>, | ||
#[ts(as = "Vec<String>")] | ||
labels: Vec<Label>, | ||
} | ||
|
||
impl Patch { | ||
pub fn new(id: patch::PatchId, patch: patch::Patch, aliases: &impl AliasStore) -> Self { | ||
Self { | ||
id: id.to_string(), | ||
author: Author::new(*patch.author().id(), aliases), | ||
title: patch.title().to_string(), | ||
state: patch.state().clone(), | ||
assignees: patch | ||
.assignees() | ||
.map(|did| Author::new(did, aliases)) | ||
.collect::<Vec<_>>(), | ||
labels: patch.labels().cloned().collect::<Vec<_>>(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod cobs; | ||
pub mod config; | ||
pub mod repo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters