Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle: Create `Aliases` and use it in `httpd`
xphoniex committed 2 years ago
commit b1169319c3413781074e299f8a47bb2e5ac08f8a
parent 6f20e93c3caa952f304dbaef862ceb60ffcf5253
2 files changed +14 -14
modified radicle-httpd/src/api/v1/projects.rs
@@ -324,7 +324,7 @@ async fn remotes_handler(State(ctx): State<Context>, Path(project): Path<Id>) ->
    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<Context>, Path(project): Path<Id>) ->
                })
                .collect::<BTreeMap<String, &Oid>>();

-
            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::<Vec<_>>();

    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::<Vec<_>>();
@@ -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::<Vec<_>>();
    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::<Vec<_>>();
@@ -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,
    )))
}

modified 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<G: 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");