diff --git a/fplus-http-server/src/main.rs b/fplus-http-server/src/main.rs index 140dcdf..99e39bf 100644 --- a/fplus-http-server/src/main.rs +++ b/fplus-http-server/src/main.rs @@ -116,6 +116,7 @@ async fn main() -> std::io::Result<()> { .service(router::allocator::delete) .service(router::allocator::create_allocator_from_json) .service(router::allocator::update_allocator_force) + .service(router::allocator::check_if_repository_application_is_installed) .service(router::autoallocator::last_client_allocation) .service(router::autoallocator::trigger_autoallocation) .service(router::autoallocator::check_if_allowance_is_sufficient) diff --git a/fplus-http-server/src/router/allocator.rs b/fplus-http-server/src/router/allocator.rs index 7338b7a..8d55464 100644 --- a/fplus-http-server/src/router/allocator.rs +++ b/fplus-http-server/src/router/allocator.rs @@ -6,10 +6,10 @@ use actix_web::{ use fplus_database::database::allocators as allocators_db; use fplus_lib::core::{ allocator::{ - create_allocator_from_file, fetch_installation_ids, force_update_allocators, - generate_github_app_jwt, + check_if_repo_app_installed, create_allocator_from_file, fetch_installation_ids, + force_update_allocators, generate_github_app_jwt, }, - AllocatorUpdateForceInfo, ChangedAllocators, + AllocatorUpdateForceInfo, ChangedAllocators, GithubQueryParams, }; use reqwest::Client; /** @@ -126,3 +126,13 @@ pub async fn get_installation_ids() -> actix_web::Result { })?; Ok(HttpResponse::Ok().json(ids)) } + +#[get("/allocator/check_if_repository_application_is_installed")] +pub async fn check_if_repository_application_is_installed( + query: web::Query, +) -> actix_web::Result { + check_if_repo_app_installed(&query.owner, &query.repo) + .await + .map_err(ErrorInternalServerError)?; + Ok(HttpResponse::Ok().json("Application is installed")) +} diff --git a/fplus-lib/src/core/allocator/mod.rs b/fplus-lib/src/core/allocator/mod.rs index f84c731..7eebd5d 100644 --- a/fplus-lib/src/core/allocator/mod.rs +++ b/fplus-lib/src/core/allocator/mod.rs @@ -664,3 +664,18 @@ pub async fn create_allocator_from_file(files_changed: Vec) -> Result<() } Ok(()) } + +pub async fn check_if_repo_app_installed(owner: &str, repo: &str) -> Result<(), LDNError> { + let gh = GithubWrapper::new(owner.to_string(), repo.to_string(), None)?; + gh.inner + .apps() + .get_repository_installation(owner.to_string(), repo.to_string()) + .await + .map(|installation| installation.id.0) + .map_err(|e| { + LDNError::New(format!( + "Installation Id not found for a repo: {repo} /// {e}" + )) + })?; + Ok(()) +}