Skip to content

Commit d3e09bc

Browse files
authored
Add endpoint to check if repository apllication is installed (#281)
1 parent b2ca37f commit d3e09bc

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

fplus-http-server/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ async fn main() -> std::io::Result<()> {
116116
.service(router::allocator::delete)
117117
.service(router::allocator::create_allocator_from_json)
118118
.service(router::allocator::update_allocator_force)
119+
.service(router::allocator::check_if_repository_application_is_installed)
119120
.service(router::autoallocator::last_client_allocation)
120121
.service(router::autoallocator::trigger_autoallocation)
121122
.service(router::autoallocator::check_if_allowance_is_sufficient)

fplus-http-server/src/router/allocator.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use actix_web::{
66
use fplus_database::database::allocators as allocators_db;
77
use fplus_lib::core::{
88
allocator::{
9-
create_allocator_from_file, fetch_installation_ids, force_update_allocators,
10-
generate_github_app_jwt,
9+
check_if_repo_app_installed, create_allocator_from_file, fetch_installation_ids,
10+
force_update_allocators, generate_github_app_jwt,
1111
},
12-
AllocatorUpdateForceInfo, ChangedAllocators,
12+
AllocatorUpdateForceInfo, ChangedAllocators, GithubQueryParams,
1313
};
1414
use reqwest::Client;
1515
/**
@@ -126,3 +126,13 @@ pub async fn get_installation_ids() -> actix_web::Result<impl Responder> {
126126
})?;
127127
Ok(HttpResponse::Ok().json(ids))
128128
}
129+
130+
#[get("/allocator/check_if_repository_application_is_installed")]
131+
pub async fn check_if_repository_application_is_installed(
132+
query: web::Query<GithubQueryParams>,
133+
) -> actix_web::Result<impl Responder> {
134+
check_if_repo_app_installed(&query.owner, &query.repo)
135+
.await
136+
.map_err(ErrorInternalServerError)?;
137+
Ok(HttpResponse::Ok().json("Application is installed"))
138+
}

fplus-lib/src/core/allocator/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,3 +664,18 @@ pub async fn create_allocator_from_file(files_changed: Vec<String>) -> Result<()
664664
}
665665
Ok(())
666666
}
667+
668+
pub async fn check_if_repo_app_installed(owner: &str, repo: &str) -> Result<(), LDNError> {
669+
let gh = GithubWrapper::new(owner.to_string(), repo.to_string(), None)?;
670+
gh.inner
671+
.apps()
672+
.get_repository_installation(owner.to_string(), repo.to_string())
673+
.await
674+
.map(|installation| installation.id.0)
675+
.map_err(|e| {
676+
LDNError::New(format!(
677+
"Installation Id not found for a repo: {repo} /// {e}"
678+
))
679+
})?;
680+
Ok(())
681+
}

0 commit comments

Comments
 (0)