-
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
list_repo
command and repo listing
- Loading branch information
1 parent
8c8d2ae
commit ccfb54c
Showing
22 changed files
with
540 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,15 @@ | ||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. | ||
import type { JsonValue } from "./serde_json/JsonValue"; | ||
import type { SupportedPayloads } from "./SupportedPayloads"; | ||
|
||
/** | ||
* Repos info. | ||
*/ | ||
export type RepoInfo = { | ||
payloads: SupportedPayloads; | ||
delegates: Array<JsonValue>; | ||
threshold: number; | ||
visibility: { type: "public" } | { type: "private"; allow?: string[] }; | ||
rid: string; | ||
seeding: number; | ||
}; |
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,25 @@ | ||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. | ||
|
||
export type SupportedPayloads = { | ||
"xyz.radicle.project"?: { | ||
data: { | ||
defaultBranch: string; | ||
description: string; | ||
name: string; | ||
}; | ||
meta: { | ||
head: string; | ||
issues: { | ||
open: number; | ||
closed: number; | ||
}; | ||
patches: { | ||
open: number; | ||
draft: number; | ||
archived: number; | ||
merged: number; | ||
}; | ||
lastCommit: number; | ||
}; | ||
}; | ||
}; |
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,7 @@ | ||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. | ||
|
||
export type JsonValue = | ||
| number | ||
| string | ||
| Array<JsonValue> | ||
| { [key: string]: JsonValue }; |
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,2 @@ | ||
pub mod auth; | ||
pub mod repos; |
File renamed without changes.
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,30 @@ | ||
use radicle::storage::ReadStorage; | ||
|
||
use crate::error::Error; | ||
use crate::types; | ||
use crate::AppState; | ||
|
||
/// List all repos. | ||
#[tauri::command] | ||
pub fn list_repos(ctx: tauri::State<AppState>) -> Result<Vec<types::repo::RepoInfo>, Error> { | ||
let storage = &ctx.profile.storage; | ||
let policies = ctx.profile.policies()?; | ||
|
||
let mut repos = storage.repositories()?.into_iter().collect::<Vec<_>>(); | ||
repos.sort_by_key(|p| p.rid); | ||
|
||
let infos = repos | ||
.into_iter() | ||
.filter_map(|info| { | ||
if !policies.is_seeding(&info.rid).unwrap_or_default() { | ||
return None; | ||
} | ||
let (repo, doc) = ctx.repo(info.rid).ok()?; | ||
let repo_info = ctx.repo_info(&repo, doc).ok()?; | ||
|
||
Some(repo_info) | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
Ok::<_, Error>(infos) | ||
} |
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,19 @@ | ||
use serde_json::{json, Value}; | ||
|
||
use radicle::identity; | ||
use radicle::node::AliasStore; | ||
|
||
pub(crate) struct Author<'a>(&'a identity::Did); | ||
|
||
impl<'a> Author<'a> { | ||
pub fn new(did: &'a identity::Did) -> Self { | ||
Self(did) | ||
} | ||
|
||
pub fn as_json(&self, aliases: &impl AliasStore) -> Value { | ||
aliases.alias(self.0).map_or( | ||
json!({ "id": self.0 }), | ||
|alias| json!({ "id": self.0, "alias": alias, }), | ||
) | ||
} | ||
} |
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 @@ | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use serde::Serialize; | ||
use serde_json::Value; | ||
use ts_rs::TS; | ||
|
||
use radicle::identity::RepoId; | ||
|
||
/// Repos info. | ||
#[derive(Serialize, TS)] | ||
#[ts(export)] | ||
pub struct RepoInfo { | ||
pub payloads: SupportedPayloads, | ||
pub delegates: Vec<Value>, | ||
pub threshold: usize, | ||
#[ts(type = "{ type: 'public' } | { type: 'private', allow?: string[] }")] | ||
pub visibility: radicle::identity::Visibility, | ||
#[ts(as = "String")] | ||
pub rid: RepoId, | ||
pub seeding: usize, | ||
} | ||
|
||
#[derive(Serialize, TS)] | ||
#[ts(export)] | ||
pub struct SupportedPayloads { | ||
#[serde(rename = "xyz.radicle.project")] | ||
#[serde(default, skip_serializing_if = "Option::is_none")] | ||
#[ts(optional)] | ||
#[ts(type = r#"{ | ||
data: { | ||
defaultBranch: string, | ||
description: string, | ||
name: string, | ||
}, | ||
meta: { | ||
head: string, | ||
issues: { | ||
open: number, | ||
closed: number, | ||
}, | ||
patches: { | ||
open: number, | ||
draft: number, | ||
archived: number, | ||
merged: number, | ||
} | ||
lastCommit: number, | ||
} | ||
}"#)] | ||
pub project: Option<Value>, | ||
} |
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
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
Oops, something went wrong.