mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-10-25 14:50:30 +08:00
Add list_repos_summary Tauri command
This commit is contained in:
@@ -22,6 +22,13 @@ pub fn list_repos(
|
||||
ctx.list_repos(show)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn list_repos_summary(
|
||||
ctx: tauri::State<AppState>,
|
||||
) -> Result<Vec<types::repo::RepoSummary>, Error> {
|
||||
ctx.list_repos_summary()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn repo_count(ctx: tauri::State<AppState>) -> Result<types::repo::RepoCount, Error> {
|
||||
ctx.repo_count()
|
||||
|
||||
@@ -58,6 +58,7 @@ pub fn run() {
|
||||
repo::diff_stats,
|
||||
repo::list_commits,
|
||||
repo::list_repos,
|
||||
repo::list_repos_summary,
|
||||
repo::repo_by_id,
|
||||
repo::repo_count,
|
||||
repo::repo_readme,
|
||||
|
||||
@@ -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 RepoSummary = { rid: string; name: string };
|
||||
@@ -9,6 +9,16 @@ use radicle::{git, identity, issue, patch};
|
||||
use crate::cobs::Author;
|
||||
use crate::error;
|
||||
|
||||
#[derive(Serialize, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export)]
|
||||
#[ts(export_to = "repo/")]
|
||||
pub struct RepoSummary {
|
||||
#[ts(as = "String")]
|
||||
pub rid: identity::RepoId,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export)]
|
||||
|
||||
@@ -73,6 +73,31 @@ pub trait Repo: Profile {
|
||||
Ok::<_, Error>(entries)
|
||||
}
|
||||
|
||||
fn list_repos_summary(&self) -> Result<Vec<repo::RepoSummary>, Error> {
|
||||
let profile = self.profile();
|
||||
let storage = &profile.storage;
|
||||
let repos = storage.repositories()?;
|
||||
let mut entries = Vec::new();
|
||||
|
||||
for RepositoryInfo { rid, doc, .. } in repos {
|
||||
let Some(data) = doc
|
||||
.payload()
|
||||
.get(&doc::PayloadId::project())
|
||||
.and_then(|payload| repo::ProjectPayloadData::try_from((*payload).clone()).ok())
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
entries.push(repo::RepoSummary {
|
||||
rid,
|
||||
name: data.name,
|
||||
});
|
||||
}
|
||||
|
||||
entries.sort_by_key(|r| r.name.to_lowercase());
|
||||
|
||||
Ok::<_, Error>(entries)
|
||||
}
|
||||
|
||||
fn repo_count(&self) -> Result<repo::RepoCount, Error> {
|
||||
let profile = self.profile();
|
||||
let storage = &profile.storage;
|
||||
|
||||
@@ -63,6 +63,7 @@ pub fn router(ctx: Context) -> Router {
|
||||
.route("/authenticate", post(auth_handler))
|
||||
.route("/repo_count", post(repo_count_handler))
|
||||
.route("/list_repos", post(repo_root_handler))
|
||||
.route("/list_repos_summary", post(list_repos_summary_handler))
|
||||
.route("/repo_by_id", post(repo_handler))
|
||||
.route("/version", post(version_handler))
|
||||
.route("/diff_stats", post(diff_stats_handler))
|
||||
@@ -131,6 +132,11 @@ async fn repo_count_handler(State(ctx): State<Context>) -> impl IntoResponse {
|
||||
Ok::<_, Error>(Json(repos))
|
||||
}
|
||||
|
||||
async fn list_repos_summary_handler(State(ctx): State<Context>) -> impl IntoResponse {
|
||||
let repos = ctx.list_repos_summary()?;
|
||||
Ok::<_, Error>(Json(repos))
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct RepoBody {
|
||||
pub rid: identity::RepoId,
|
||||
|
||||
Reference in New Issue
Block a user