@@ -2,7 +2,9 @@ use crate::helpers::process_amount;
2
2
use fplus_database:: database:: allocation_amounts:: {
3
3
create_allocation_amount, delete_allocation_amounts_by_allocator_id,
4
4
} ;
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
+ } ;
6
8
use fplus_database:: models:: allocators:: Model ;
7
9
use octocrab:: auth:: create_jwt;
8
10
use octocrab:: models:: repos:: { Content , ContentItems } ;
@@ -365,40 +367,34 @@ pub async fn fetch_repositories_for_installation_id(
365
367
Ok ( repositories)
366
368
}
367
369
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 > {
369
373
let installation_id = installation. installation_id ;
370
374
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 ( ) ,
376
378
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 ,
388
379
)
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
+ } ) ?;
390
389
}
390
+ Ok ( ( ) )
391
391
}
392
392
393
- pub async fn update_installation_ids_logic ( ) {
393
+ pub async fn update_installation_ids_logic ( ) -> Result < ( ) , LDNError > {
394
394
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) ) ) ?;
402
398
403
399
let installation_ids_result = fetch_installation_ids ( & client, & jwt) . await ;
404
400
let mut results: Vec < InstallationRepositories > = Vec :: new ( ) ;
@@ -415,8 +411,9 @@ pub async fn update_installation_ids_logic() {
415
411
}
416
412
417
413
for installation in results. iter ( ) {
418
- update_installation_ids_in_db ( installation. clone ( ) ) . await ;
414
+ update_installation_ids_in_db ( installation. clone ( ) ) . await ? ;
419
415
}
416
+ Ok ( ( ) )
420
417
}
421
418
422
419
pub async fn force_update_allocators (
0 commit comments