From 38fee3daf3044da2ca0dd8de81e6b2b313554854 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Tue, 28 Feb 2023 15:59:50 +0530 Subject: [PATCH] chore: replace CreateForge.import with starchart_url for marking forge instances with Starchart instances --- db/db-core/src/lib.rs | 17 ++++++++++++----- db/db-core/src/tests.rs | 19 ++++++------------- db/db-sqlx-sqlite/src/tests.rs | 2 +- src/api.rs | 2 +- src/spider.rs | 4 ++-- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/db/db-core/src/lib.rs b/db/db-core/src/lib.rs index c813b94..1a102bc 100644 --- a/db/db-core/src/lib.rs +++ b/db/db-core/src/lib.rs @@ -60,13 +60,15 @@ pub mod dev { #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] /// create a new forge on the database -pub struct CreateForge { +pub struct CreateForge<'a> { + /// url of the Starchart instance + /// None = local instance + /// Some(&'a str) = foreign instance + pub starchart_url: Option<&'a str>, /// url of the forge instance: with scheme but remove trailing slash pub url: Url, /// forge type: which software is the instance running? pub forge_type: ForgeImplementation, - /// is this forge an import - pub import: bool, } /// Get url from URL @@ -136,14 +138,16 @@ pub struct AddRepository<'a> { #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] /// data representing a forge instance pub struct Forge { + /// url of the Starchart instance + /// None = local instance + /// Some(&'a str) = foreign instance + pub starchart_url: Option, /// url of the forge pub url: String, /// type of the forge pub forge_type: ForgeImplementation, /// last crawl pub last_crawl_on: Option, - /// is this forge an import - pub import: bool, } #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -225,6 +229,9 @@ pub trait SCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase { /// Search all repositories async fn search_repository(&self, query: &str) -> DBResult>; + + /// Add Starchart instance to introducer + async fn add_starchart_to_introducer(&self, url: &Url) -> DBResult<()>; } /// Trait to clone SCDatabase diff --git a/db/db-core/src/tests.rs b/db/db-core/src/tests.rs index 039f189..c2b6cf0 100644 --- a/db/db-core/src/tests.rs +++ b/db/db-core/src/tests.rs @@ -21,7 +21,7 @@ use crate::prelude::*; /// adding forge works pub async fn adding_forge_works<'a, T: SCDatabase>( db: &T, - create_forge_msg: CreateForge, + create_forge_msg: CreateForge<'a>, add_user_msg: AddUser<'a>, add_user_msg2: AddUser<'a>, add_repo_msg: AddRepository<'a>, @@ -35,20 +35,13 @@ pub async fn adding_forge_works<'a, T: SCDatabase>( { let forge = db.get_forge(&create_forge_msg.url).await.unwrap(); - let forges = db.get_all_forges(true, 0, 10).await.unwrap(); - assert_eq!(forges.len(), 1); + let forges = db.get_all_forges(true, 0, 100).await.unwrap(); + assert!(forges + .iter() + .any(|f| f.url == create_forge_msg.url.to_string())); - assert_eq!( - forges.get(0).as_ref().unwrap().forge_type, - create_forge_msg.forge_type - ); - assert_eq!( - forges.get(0).as_ref().unwrap().url, - crate::clean_url(&create_forge_msg.url) - ); - - assert_eq!(forge.url, crate::clean_url(&create_forge_msg.url)); assert_eq!(forge.forge_type, create_forge_msg.forge_type); + assert_eq!(forge.url, crate::clean_url(&create_forge_msg.url)); } // add user diff --git a/db/db-sqlx-sqlite/src/tests.rs b/db/db-sqlx-sqlite/src/tests.rs index 0997abb..6874a16 100644 --- a/db/db-sqlx-sqlite/src/tests.rs +++ b/db/db-sqlx-sqlite/src/tests.rs @@ -40,7 +40,7 @@ async fn everything_works() { let create_forge_msg = CreateForge { url: url.clone(), forge_type: ForgeImplementation::Gitea, - import: false, + starchart_url: None, }; let add_user_msg = AddUser { diff --git a/src/api.rs b/src/api.rs index f94c5f7..40fe255 100644 --- a/src/api.rs +++ b/src/api.rs @@ -80,7 +80,7 @@ mod tests { let create_forge_msg = CreateForge { url: url.clone(), forge_type: ForgeImplementation::Gitea, - import: false, + starchart_url: None, }; let _ = db.delete_forge_instance(&create_forge_msg.url).await; diff --git a/src/spider.rs b/src/spider.rs index 17e27f5..6dd7a8e 100644 --- a/src/spider.rs +++ b/src/spider.rs @@ -48,7 +48,7 @@ impl Ctx { let msg = CreateForge { url: url.clone(), forge_type: forge.forge_type(), - import: false, + starchart_url: None, }; db.create_forge_instance(&msg).await.unwrap(); @@ -57,7 +57,7 @@ impl Ctx { let msg = CreateForge { url: url.clone(), forge_type: forge.forge_type, - import: false, + starchart_url: None, }; federate.create_forge_instance(&msg).await.unwrap(); }