@@ -2,7 +2,9 @@ use crate::helpers::process_amount;
22use fplus_database:: database:: allocation_amounts:: {
33 create_allocation_amount, delete_allocation_amounts_by_allocator_id,
44} ;
5- use fplus_database:: database:: allocators:: { create_or_update_allocator, get_allocators} ;
5+ use fplus_database:: database:: allocators:: {
6+ create_or_update_allocator, get_allocators, update_allocator_installation_ids,
7+ } ;
68use fplus_database:: models:: allocators:: Model ;
79use octocrab:: auth:: create_jwt;
810use octocrab:: models:: repos:: { Content , ContentItems } ;
@@ -365,40 +367,34 @@ pub async fn fetch_repositories_for_installation_id(
365367 Ok ( repositories)
366368}
367369
368- pub async fn update_installation_ids_in_db ( installation : InstallationRepositories ) {
370+ pub async fn update_installation_ids_in_db (
371+ installation : InstallationRepositories ,
372+ ) -> Result < ( ) , LDNError > {
369373 let installation_id = installation. installation_id ;
370374 for repo in installation. repositories . iter ( ) {
371- let owner = repo. owner . clone ( ) ;
372- let repo = repo. slug . clone ( ) ;
373- let _ = create_or_update_allocator (
374- owner,
375- repo,
375+ update_allocator_installation_ids (
376+ repo. owner . clone ( ) ,
377+ repo. slug . clone ( ) ,
376378 Some ( installation_id. try_into ( ) . unwrap ( ) ) ,
377- None ,
378- None ,
379- None ,
380- None ,
381- None ,
382- None ,
383- None ,
384- None ,
385- None ,
386- None ,
387- None ,
388379 )
389- . await ;
380+ . await
381+ . map_err ( |e| {
382+ LDNError :: Load ( format ! (
383+ "Failed to update installation id in database for repo: {} {} /// {}" ,
384+ repo. owner. clone( ) ,
385+ repo. slug. clone( ) ,
386+ e
387+ ) )
388+ } ) ?;
390389 }
390+ Ok ( ( ) )
391391}
392392
393- pub async fn update_installation_ids_logic ( ) {
393+ pub async fn update_installation_ids_logic ( ) -> Result < ( ) , LDNError > {
394394 let client = Client :: new ( ) ;
395- let jwt = match generate_github_app_jwt ( ) . await {
396- Ok ( jwt) => jwt,
397- Err ( e) => {
398- log:: error!( "Failed to generate GitHub App JWT: {}" , e) ;
399- return ;
400- }
401- } ;
395+ let jwt = generate_github_app_jwt ( )
396+ . await
397+ . map_err ( |e| LDNError :: Load ( format ! ( "Failed to generate GitHub App JWT: {}" , e) ) ) ?;
402398
403399 let installation_ids_result = fetch_installation_ids ( & client, & jwt) . await ;
404400 let mut results: Vec < InstallationRepositories > = Vec :: new ( ) ;
@@ -415,8 +411,9 @@ pub async fn update_installation_ids_logic() {
415411 }
416412
417413 for installation in results. iter ( ) {
418- update_installation_ids_in_db ( installation. clone ( ) ) . await ;
414+ update_installation_ids_in_db ( installation. clone ( ) ) . await ? ;
419415 }
416+ Ok ( ( ) )
420417}
421418
422419pub async fn force_update_allocators (
0 commit comments