chore: replace CreateForge.import with starchart_url for marking forge

instances with Starchart instances
This commit is contained in:
Aravinth Manivannan 2023-02-28 15:59:50 +05:30
parent 8cf21c3ce6
commit 38fee3daf3
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
5 changed files with 22 additions and 22 deletions

View file

@ -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<String>,
/// url of the forge
pub url: String,
/// type of the forge
pub forge_type: ForgeImplementation,
/// last crawl
pub last_crawl_on: Option<i64>,
/// 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<Vec<Repository>>;
/// Add Starchart instance to introducer
async fn add_starchart_to_introducer(&self, url: &Url) -> DBResult<()>;
}
/// Trait to clone SCDatabase

View file

@ -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

View file

@ -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 {

View file

@ -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;

View file

@ -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();
}