From b1169319c3413781074e299f8a47bb2e5ac08f8a Mon Sep 17 00:00:00 2001 From: xphoniex Date: Sat, 27 May 2023 13:46:39 +0000 Subject: [PATCH] radicle: Create `Aliases` and use it in `httpd` Signed-off-by: xphoniex --- radicle-httpd/src/api/v1/projects.rs | 24 ++++++++++-------------- radicle-httpd/src/test.rs | 4 ++++ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/radicle-httpd/src/api/v1/projects.rs b/radicle-httpd/src/api/v1/projects.rs index 41487f1e9..bb97dedca 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -324,7 +324,7 @@ async fn remotes_handler(State(ctx): State, Path(project): Path) -> let storage = &ctx.profile.storage; let repo = storage.repository(project)?; let delegates = repo.delegates()?; - let tracking_store = &ctx.profile.tracking()?; + let aliases = &ctx.profile.aliases()?; let remotes = repo .remotes()? .filter_map(|r| r.map(|r| r.1).ok()) @@ -339,7 +339,7 @@ async fn remotes_handler(State(ctx): State, Path(project): Path) -> }) .collect::>(); - match tracking_store.alias(&remote.id) { + match aliases.alias(&remote.id) { Some(alias) => json!({ "id": remote.id, "alias": alias, @@ -454,10 +454,10 @@ async fn issues_handler( .collect::>(); issues.sort_by(|(_, a, _), (_, b, _)| b.timestamp().cmp(&a.timestamp())); - let tracking_store = &ctx.profile.tracking()?; + let aliases = &ctx.profile.aliases()?; let issues = issues .into_iter() - .map(|(id, issue, _)| api::json::issue(id, issue, &tracking_store)) + .map(|(id, issue, _)| api::json::issue(id, issue, &aliases)) .skip(page * per_page) .take(per_page) .collect::>(); @@ -574,13 +574,9 @@ async fn issue_handler( let issue = issue::Issues::open(&repo)? .get(&issue_id.into())? .ok_or(Error::NotFound)?; - let tracking_store = &ctx.profile.tracking()?; + let aliases = &ctx.profile.aliases()?; - Ok::<_, Error>(Json(api::json::issue( - issue_id.into(), - issue, - &tracking_store, - ))) + Ok::<_, Error>(Json(api::json::issue(issue_id.into(), issue, &aliases))) } #[derive(Deserialize, Serialize)] @@ -738,10 +734,10 @@ async fn patches_handler( }) .collect::>(); patches.sort_by(|(_, a, _), (_, b, _)| b.timestamp().cmp(&a.timestamp())); - let tracking_store = &ctx.profile.tracking()?; + let aliases = &ctx.profile.aliases()?; let patches = patches .into_iter() - .map(|(id, patch, _)| api::json::patch(id, patch, &repo, &tracking_store)) + .map(|(id, patch, _)| api::json::patch(id, patch, &repo, &aliases)) .skip(page * per_page) .take(per_page) .collect::>(); @@ -760,13 +756,13 @@ async fn patch_handler( let patch = patch::Patches::open(&repo)? .get(&patch_id.into())? .ok_or(Error::NotFound)?; - let tracking_store = &ctx.profile.tracking()?; + let aliases = &ctx.profile.aliases()?; Ok::<_, Error>(Json(api::json::patch( patch_id.into(), patch, &repo, - &tracking_store, + &aliases, ))) } diff --git a/radicle-httpd/src/test.rs b/radicle-httpd/src/test.rs index 14a922bc9..aad3054d0 100644 --- a/radicle-httpd/src/test.rs +++ b/radicle-httpd/src/test.rs @@ -16,6 +16,7 @@ use radicle::crypto::ssh::keystore::MemorySigner; use radicle::crypto::ssh::Keystore; use radicle::crypto::{KeyPair, Seed, Signer}; use radicle::git::{raw as git2, RefString}; +use radicle::node::address as AddressStore; use radicle::node::routing as RoutingStore; use radicle::node::tracking::store as TrackingStore; use radicle::profile::Home; @@ -87,8 +88,11 @@ pub fn contributor(dir: &Path) -> Context { fn seed_with_signer(dir: &Path, profile: radicle::Profile, signer: &G) -> Context { let tracking_db = dir.join("radicle").join("node").join("tracking.db"); let routing_db = dir.join("radicle").join("node").join("routing.db"); + let addresses_db = dir.join("radicle").join("node").join("addresses.db"); + TrackingStore::Config::open(tracking_db).unwrap(); RoutingStore::Table::open(routing_db).unwrap(); + AddressStore::Book::open(addresses_db).unwrap(); let workdir = dir.join("hello-world");