Skip to content

[FIL-196] Add endpoint to check if repository apllication is installed #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fplus-http-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 13 additions & 3 deletions fplus-http-server/src/router/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/**
Expand Down Expand Up @@ -126,3 +126,13 @@ pub async fn get_installation_ids() -> actix_web::Result<impl Responder> {
})?;
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<GithubQueryParams>,
) -> actix_web::Result<impl Responder> {
check_if_repo_app_installed(&query.owner, &query.repo)
.await
.map_err(ErrorInternalServerError)?;
Ok(HttpResponse::Ok().json("Application is installed"))
}
15 changes: 15 additions & 0 deletions fplus-lib/src/core/allocator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,3 +664,18 @@ pub async fn create_allocator_from_file(files_changed: Vec<String>) -> 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(())
}