@@ -32,7 +32,7 @@ pub async fn process_allocator_file(file_name: &str) -> Result<AllocatorModel, L
32
32
let repo = get_env_var_or_default ( "ALLOCATOR_GOVERNANCE_REPO" ) ;
33
33
let installation_id = get_env_var_or_default ( "GITHUB_INSTALLATION_ID" )
34
34
. parse :: < i64 > ( )
35
- . map_err ( |e| LDNError :: New ( format ! ( "Parse installation_id to i64 failed: {}" , e ) ) ) ?;
35
+ . map_err ( |e| LDNError :: New ( format ! ( "Parse installation_id to i64 failed: {e}" ) ) ) ?;
36
36
let branch = "main" ;
37
37
let path = file_name. to_string ( ) ;
38
38
@@ -108,8 +108,7 @@ pub async fn is_allocator_repo_initialized(gh: &GithubWrapper) -> Result<bool, L
108
108
let applications_directory = "applications" ;
109
109
let all_files_result = gh. get_files ( applications_directory) . await . map_err ( |e| {
110
110
LDNError :: Load ( format ! (
111
- "Failed to retrieve all files from GitHub. Reason: {}" ,
112
- e
111
+ "Failed to retrieve all files from GitHub. Reason: {e}"
113
112
) )
114
113
} ) ;
115
114
@@ -151,11 +150,11 @@ pub async fn create_file_in_repo(
151
150
)
152
151
. send ( )
153
152
. await
154
- . map_err ( |e| LDNError :: Load ( format ! ( "here {}" , e ) ) ) ?;
153
+ . map_err ( |e| LDNError :: Load ( format ! ( "here {e}" ) ) ) ?;
155
154
let file = file
156
155
. text ( )
157
156
. await
158
- . map_err ( |e| LDNError :: Load ( format ! ( "here1 {}" , e ) ) ) ?;
157
+ . map_err ( |e| LDNError :: Load ( format ! ( "here1 {e}" ) ) ) ?;
159
158
160
159
//Get file from target repo. If file does not exist or fails to retrieve, create it
161
160
let target_file = match gh. get_file ( & file_path, "main" ) . await {
@@ -243,8 +242,7 @@ pub async fn init_allocator_repo(gh: &GithubWrapper) -> Result<(), LDNError> {
243
242
. await
244
243
. map_err ( |e| {
245
244
LDNError :: Load ( format ! (
246
- "Failed to retrieve all files from GitHub. Reason: {}" ,
247
- e
245
+ "Failed to retrieve all files from GitHub. Reason: {e}"
248
246
) )
249
247
} ) ?;
250
248
@@ -264,19 +262,14 @@ pub async fn init_allocator_repo(gh: &GithubWrapper) -> Result<(), LDNError> {
264
262
pub async fn generate_github_app_jwt ( ) -> Result < String , LDNError > {
265
263
let app_id = get_env_var_or_default ( "GITHUB_APP_ID" )
266
264
. parse :: < u64 > ( )
267
- . map_err ( |e| {
268
- LDNError :: New ( format ! (
269
- "Parse days to next allocation to i64 failed: {}" ,
270
- e
271
- ) )
272
- } ) ?;
265
+ . map_err ( |e| LDNError :: New ( format ! ( "Parse days to next allocation to i64 failed: {e}" ) ) ) ?;
273
266
let pem = get_env_var_or_default ( "GH_PRIVATE_KEY" ) ;
274
267
275
268
let key = EncodingKey :: from_rsa_pem ( pem. to_string ( ) . as_bytes ( ) )
276
- . map_err ( |e| LDNError :: Load ( format ! ( "Failed to load RSA PEM: {}" , e ) ) ) ?;
269
+ . map_err ( |e| LDNError :: Load ( format ! ( "Failed to load RSA PEM: {e}" ) ) ) ?;
277
270
278
271
let token = create_jwt ( octocrab:: models:: AppId ( app_id) , & key)
279
- . map_err ( |e| LDNError :: Load ( format ! ( "Failed to create JWT: {}" , e ) ) ) ?;
272
+ . map_err ( |e| LDNError :: Load ( format ! ( "Failed to create JWT: {e}" ) ) ) ?;
280
273
281
274
Ok ( token)
282
275
}
@@ -285,13 +278,13 @@ pub async fn fetch_installation_ids(client: &Client, jwt: &str) -> Result<Vec<u6
285
278
let req_url = "https://api.github.com/app/installations" ;
286
279
let response = client
287
280
. get ( req_url)
288
- . header ( header:: AUTHORIZATION , format ! ( "Bearer {}" , jwt ) )
281
+ . header ( header:: AUTHORIZATION , format ! ( "Bearer {jwt}" ) )
289
282
. header ( header:: ACCEPT , "application/vnd.github+json" )
290
283
. header ( "X-GitHub-Api-Version" , "2022-11-28" )
291
284
. header ( header:: USER_AGENT , "YourApp" )
292
285
. send ( )
293
286
. await
294
- . map_err ( |e| LDNError :: Load ( format ! ( "Failed to send request: {}" , e ) ) ) ?;
287
+ . map_err ( |e| LDNError :: Load ( format ! ( "Failed to send request: {e}" ) ) ) ?;
295
288
296
289
if !response. status ( ) . is_success ( ) {
297
290
log:: error!( "Request failed with status: {}" , response. status( ) ) ;
@@ -300,12 +293,12 @@ pub async fn fetch_installation_ids(client: &Client, jwt: &str) -> Result<Vec<u6
300
293
let text = response
301
294
. text ( )
302
295
. await
303
- . map_err ( |e| LDNError :: Load ( format ! ( "Failed to decode response: {}" , e ) ) ) ?;
296
+ . map_err ( |e| LDNError :: Load ( format ! ( "Failed to decode response: {e}" ) ) ) ?;
304
297
305
298
log:: debug!( "Response body: {}" , text) ;
306
299
307
300
let installations: Vec < Installation > = serde_json:: from_str ( & text)
308
- . map_err ( |e| LDNError :: Load ( format ! ( "Failed to parse response as JSON: {}" , e ) ) ) ?;
301
+ . map_err ( |e| LDNError :: Load ( format ! ( "Failed to parse response as JSON: {e}" ) ) ) ?;
309
302
310
303
Ok ( installations. into_iter ( ) . map ( |i| i. id ) . collect ( ) )
311
304
}
@@ -315,13 +308,11 @@ pub async fn fetch_access_token(
315
308
jwt : & str ,
316
309
installation_id : u64 ,
317
310
) -> Result < String > {
318
- let req_url = format ! (
319
- "https://api.github.com/app/installations/{}/access_tokens" ,
320
- installation_id
321
- ) ;
311
+ let req_url =
312
+ format ! ( "https://api.github.com/app/installations/{installation_id}/access_tokens" ) ;
322
313
let res: AccessTokenResponse = client
323
314
. post ( req_url)
324
- . header ( header:: AUTHORIZATION , format ! ( "Bearer {}" , jwt ) )
315
+ . header ( header:: AUTHORIZATION , format ! ( "Bearer {jwt}" ) )
325
316
. header ( header:: USER_AGENT , "YourApp" )
326
317
. send ( )
327
318
. await ?
@@ -334,7 +325,7 @@ pub async fn fetch_repositories(client: &Client, token: &str) -> Result<Vec<Repo
334
325
let req_url = "https://api.github.com/installation/repositories" ;
335
326
let res: RepositoriesResponse = client
336
327
. get ( req_url)
337
- . header ( header:: AUTHORIZATION , format ! ( "Bearer {}" , token ) )
328
+ . header ( header:: AUTHORIZATION , format ! ( "Bearer {token}" ) )
338
329
. header ( header:: USER_AGENT , "YourApp" )
339
330
. send ( )
340
331
. await ?
@@ -366,7 +357,7 @@ pub async fn update_installation_ids_in_db(
366
357
let installation_id: i64 = installation
367
358
. installation_id
368
359
. try_into ( )
369
- . map_err ( |e| LDNError :: Load ( format ! ( "Failed to pasre installation id to i64: {}" , e ) ) ) ?;
360
+ . map_err ( |e| LDNError :: Load ( format ! ( "Failed to pasre installation id to i64: {e}" ) ) ) ?;
370
361
for repo in installation. repositories . iter ( ) {
371
362
update_allocator_installation_ids (
372
363
repo. owner . clone ( ) ,
@@ -390,7 +381,7 @@ pub async fn update_installation_ids_logic() -> Result<(), LDNError> {
390
381
let client = Client :: new ( ) ;
391
382
let jwt = generate_github_app_jwt ( )
392
383
. await
393
- . map_err ( |e| LDNError :: Load ( format ! ( "Failed to generate GitHub App JWT: {}" , e ) ) ) ?;
384
+ . map_err ( |e| LDNError :: Load ( format ! ( "Failed to generate GitHub App JWT: {e}" ) ) ) ?;
394
385
395
386
let installation_ids_result = fetch_installation_ids ( & client, & jwt) . await ;
396
387
let mut results: Vec < InstallationRepositories > = Vec :: new ( ) ;
@@ -401,8 +392,7 @@ pub async fn update_installation_ids_logic() -> Result<(), LDNError> {
401
392
. await
402
393
. map_err ( |e| {
403
394
LDNError :: Load ( format ! (
404
- "Failed to fetch repositories for installation id: {}" ,
405
- e
395
+ "Failed to fetch repositories for installation id: {e}"
406
396
) )
407
397
} ) ?;
408
398
results. push ( InstallationRepositories {
@@ -486,7 +476,7 @@ pub async fn force_update_allocators(
486
476
Some ( file) ,
487
477
)
488
478
. await
489
- . map_err ( |e| LDNError :: Load ( format ! ( "Failed to get files: {}" , e ) ) ) ?;
479
+ . map_err ( |e| LDNError :: Load ( format ! ( "Failed to get files: {e}" ) ) ) ?;
490
480
create_file_in_repo ( & gh, & content. items [ 0 ] , true ) . await ?;
491
481
}
492
482
}
@@ -508,7 +498,7 @@ pub fn validate_amount_type_and_options(
508
498
pub fn validate_fixed_amount_options ( amount_options : & [ String ] ) -> Result < ( ) , String > {
509
499
for option in amount_options {
510
500
if !is_valid_fixed_option ( option) {
511
- return Err ( format ! ( "Invalid fixed amount option: {}" , option ) ) ;
501
+ return Err ( format ! ( "Invalid fixed amount option: {option}" ) ) ;
512
502
}
513
503
}
514
504
Ok ( ( ) )
@@ -518,7 +508,7 @@ pub fn validate_percentage_amount_options(amount_options: &[String]) -> Result<(
518
508
for option in amount_options {
519
509
let no_percentage_option = option. replace ( '%' , "" ) ;
520
510
if no_percentage_option. parse :: < i32 > ( ) . is_err ( ) {
521
- return Err ( format ! ( "Invalid percentage amount option: {}" , option ) ) ;
511
+ return Err ( format ! ( "Invalid percentage amount option: {option}" ) ) ;
522
512
}
523
513
}
524
514
Ok ( ( ) )
@@ -601,8 +591,7 @@ pub async fn create_allocator_from_file(files_changed: Vec<String>) -> Result<()
601
591
} )
602
592
. map_err ( |e| {
603
593
LDNError :: New ( format ! (
604
- "Installation Id not found for a repo: {} /// {}" ,
605
- repo, e
594
+ "Installation Id not found for a repo: {repo} /// {e}"
606
595
) )
607
596
} ) ?;
608
597
@@ -611,12 +600,11 @@ pub async fn create_allocator_from_file(files_changed: Vec<String>) -> Result<()
611
600
match is_allocator_repo_initialized ( & gh) . await {
612
601
Ok ( true ) => ( ) ,
613
602
Ok ( false ) => init_allocator_repo ( & gh) . await . map_err ( |e| {
614
- LDNError :: New ( format ! ( "Initializing the allocator repo failed: {}" , e ) )
603
+ LDNError :: New ( format ! ( "Initializing the allocator repo failed: {e}" ) )
615
604
} ) ?,
616
605
Err ( e) => {
617
606
return Err ( LDNError :: New ( format ! (
618
- "Checking if the repo is initialized failed: {}" ,
619
- e
607
+ "Checking if the repo is initialized failed: {e}"
620
608
) ) ) ;
621
609
}
622
610
}
@@ -642,7 +630,7 @@ pub async fn create_allocator_from_file(files_changed: Vec<String>) -> Result<()
642
630
model. ma_address ,
643
631
)
644
632
. await
645
- . map_err ( |e| LDNError :: New ( format ! ( "Create or update allocator failed: {}" , e ) ) ) ?;
633
+ . map_err ( |e| LDNError :: New ( format ! ( "Create or update allocator failed: {e}" ) ) ) ?;
646
634
647
635
let allocator_id = allocator_creation_result. id ;
648
636
@@ -651,8 +639,7 @@ pub async fn create_allocator_from_file(files_changed: Vec<String>) -> Result<()
651
639
. await
652
640
. map_err ( |e| {
653
641
LDNError :: New ( format ! (
654
- "Delete all old allocation amounts by allocator id failed: {}" ,
655
- e
642
+ "Delete all old allocation amounts by allocator id failed: {e}"
656
643
) )
657
644
} ) ?;
658
645
@@ -664,8 +651,7 @@ pub async fn create_allocator_from_file(files_changed: Vec<String>) -> Result<()
664
651
. await
665
652
. map_err ( |e| {
666
653
LDNError :: New ( format ! (
667
- "Create allocation amount rows in the database failed: {}" ,
668
- e
654
+ "Create allocation amount rows in the database failed: {e}"
669
655
) )
670
656
} ) ?;
671
657
}
0 commit comments