@@ -47,8 +47,8 @@ use fplus_database::database::{
47
47
use fplus_database:: models:: applications:: Model as ApplicationModel ;
48
48
49
49
use self :: application:: file:: {
50
- AllocationRequest , AllocationRequestType , AppState , ApplicationFile , DeepCompare ,
51
- ValidVerifierList , VerifierInput ,
50
+ AllocationRequest , AllocationRequestType , AppState , ApplicationFile , ApplicationResponse ,
51
+ DeepCompare , ValidVerifierList , VerifierInput ,
52
52
} ;
53
53
54
54
use crate :: core:: application:: file:: Allocation ;
@@ -498,14 +498,14 @@ impl LDNApplication {
498
498
let app = Self :: single_merged ( application_id, owner. clone ( ) , repo. clone ( ) ) . await ?;
499
499
Ok ( Self {
500
500
github : gh,
501
- application_id : app. 1 . id . clone ( ) ,
501
+ application_id : app. 1 . file . id . clone ( ) ,
502
502
file_sha : app. 0 . sha . clone ( ) ,
503
503
file_name : app. 0 . path . clone ( ) ,
504
504
branch_name : "main" . to_string ( ) ,
505
505
} )
506
506
}
507
507
508
- pub async fn all_applications ( ) -> Result < Vec < ( ApplicationFile , String , String ) > , LDNError > {
508
+ pub async fn all_applications ( ) -> Result < Vec < ApplicationResponse > , LDNError > {
509
509
let db_apps = database:: applications:: get_applications ( )
510
510
. await
511
511
. map_err ( |e| {
@@ -514,11 +514,16 @@ impl LDNApplication {
514
514
e
515
515
) )
516
516
} ) ?;
517
- let mut all_apps: Vec < ( ApplicationFile , String , String ) > = Vec :: new ( ) ;
517
+ let mut all_apps: Vec < ApplicationResponse > = Vec :: new ( ) ;
518
518
for app in db_apps {
519
519
if let Some ( application_data) = app. application {
520
520
if let Ok ( app_file) = ApplicationFile :: from_str ( & application_data) {
521
- all_apps. push ( ( app_file, app. owner , app. repo ) ) ;
521
+ all_apps. push ( ApplicationResponse {
522
+ file : app_file,
523
+ issue_reporter_handle : app. issue_reporter_handle ,
524
+ repo : app. repo ,
525
+ owner : app. owner ,
526
+ } ) ;
522
527
}
523
528
}
524
529
}
@@ -529,14 +534,14 @@ impl LDNApplication {
529
534
owner : String ,
530
535
repo : String ,
531
536
filter : Option < String > ,
532
- ) -> Result < Vec < ApplicationFile > , LDNError > {
537
+ ) -> Result < Vec < ApplicationResponse > , LDNError > {
533
538
// Get all active applications from the database.
534
539
let active_apps = database:: applications:: get_active_applications ( Some ( owner) , Some ( repo) )
535
540
. await
536
541
. map_err ( |e| LDNError :: Load ( format ! ( "Failed to get active applications: {}" , e) ) ) ?;
537
542
538
543
// Filter and convert active applications.
539
- let mut apps: Vec < ApplicationFile > = Vec :: new ( ) ;
544
+ let mut apps: Vec < ApplicationResponse > = Vec :: new ( ) ;
540
545
for app_model in active_apps {
541
546
// If a filter was provided and it doesn't match the application's id, continue to the next iteration.
542
547
if let Some ( ref filter_id) = filter {
@@ -548,7 +553,14 @@ impl LDNApplication {
548
553
// Try to deserialize the `application` field to `ApplicationFile`.
549
554
if let Some ( app_json) = app_model. application {
550
555
match from_str :: < ApplicationFile > ( & app_json) {
551
- Ok ( app) => apps. push ( app) ,
556
+ Ok ( app) => {
557
+ apps. push ( ApplicationResponse {
558
+ file : app,
559
+ issue_reporter_handle : app_model. issue_reporter_handle ,
560
+ repo : app_model. repo ,
561
+ owner : app_model. owner ,
562
+ } ) ;
563
+ }
552
564
//if error, don't push into apps
553
565
Err ( err) => {
554
566
log:: error!( "Failed to parse application file from DB: {}" , err) ;
@@ -656,7 +668,7 @@ impl LDNApplication {
656
668
pub async fn new_from_issue ( info : CreateApplicationInfo ) -> Result < Self , LDNError > {
657
669
let issue_number = info. issue_number ;
658
670
let gh = github_async_new ( info. owner . to_string ( ) , info. repo . to_string ( ) ) . await ?;
659
- let ( mut parsed_ldn, _ ) = LDNApplication :: parse_application_issue (
671
+ let ( mut parsed_ldn, issue_reporter_handle ) = LDNApplication :: parse_application_issue (
660
672
issue_number. clone ( ) ,
661
673
info. owner . clone ( ) ,
662
674
info. repo . clone ( ) ,
@@ -849,6 +861,7 @@ impl LDNApplication {
849
861
issue_number,
850
862
file_content,
851
863
LDNPullRequest :: application_path ( & app_id) ,
864
+ Some ( issue_reporter_handle) ,
852
865
)
853
866
. await
854
867
. map_err ( |e| {
@@ -1262,6 +1275,7 @@ impl LDNApplication {
1262
1275
) ;
1263
1276
let parsed_app_file = serde_json:: to_string_pretty ( & app_file)
1264
1277
. map_err ( |e| LDNError :: Load ( format ! ( "Failed to pare into string: {}" , e) ) ) ?;
1278
+
1265
1279
LDNPullRequest :: create_pr_for_existing_application (
1266
1280
app_file. id . clone ( ) ,
1267
1281
parsed_app_file,
@@ -1546,10 +1560,10 @@ impl LDNApplication {
1546
1560
let merged = Self :: merged ( owner. clone ( ) , repo. clone ( ) ) . await ?;
1547
1561
let application = merged
1548
1562
. par_iter ( )
1549
- . find_first ( |( _, app) | app. id == application_id) ;
1563
+ . find_first ( |( _, app) | app. file . id == application_id) ;
1550
1564
if let Some ( app) = application {
1551
- if app. 1 . lifecycle . get_state ( ) == AppState :: Granted {
1552
- let app = app. 1 . reached_total_datacap ( ) ;
1565
+ if app. 1 . file . lifecycle . get_state ( ) == AppState :: Granted {
1566
+ let app = app. 1 . file . reached_total_datacap ( ) ;
1553
1567
let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ?;
1554
1568
let ldn_app =
1555
1569
LDNApplication :: load ( application_id. clone ( ) , owner. clone ( ) , repo. clone ( ) )
@@ -1593,7 +1607,7 @@ impl LDNApplication {
1593
1607
} else {
1594
1608
Err ( LDNError :: Load ( format ! (
1595
1609
"Application state is {:?}. Expected Granted" ,
1596
- app. 1 . lifecycle. get_state( )
1610
+ app. 1 . file . lifecycle. get_state( )
1597
1611
) ) )
1598
1612
}
1599
1613
} else {
@@ -1658,11 +1672,11 @@ impl LDNApplication {
1658
1672
application_id : String ,
1659
1673
owner : String ,
1660
1674
repo : String ,
1661
- ) -> Result < ( ApplicationGithubInfo , ApplicationFile ) , LDNError > {
1675
+ ) -> Result < ( ApplicationGithubInfo , ApplicationResponse ) , LDNError > {
1662
1676
LDNApplication :: merged ( owner, repo)
1663
1677
. await ?
1664
1678
. into_iter ( )
1665
- . find ( |( _, app) | app. id == application_id)
1679
+ . find ( |( _, app) | app. file . id == application_id)
1666
1680
. map_or_else (
1667
1681
|| {
1668
1682
Err ( LDNError :: Load ( format ! (
@@ -1710,7 +1724,7 @@ impl LDNApplication {
1710
1724
pub async fn merged (
1711
1725
owner : String ,
1712
1726
repo : String ,
1713
- ) -> Result < Vec < ( ApplicationGithubInfo , ApplicationFile ) > , LDNError > {
1727
+ ) -> Result < Vec < ( ApplicationGithubInfo , ApplicationResponse ) > , LDNError > {
1714
1728
// Retrieve all applications in the main branch from the database.
1715
1729
let merged_app_models = database:: applications:: get_merged_applications (
1716
1730
Some ( owner. clone ( ) ) ,
@@ -1720,7 +1734,7 @@ impl LDNApplication {
1720
1734
. map_err ( |e| LDNError :: Load ( format ! ( "Database error:: {}" , e) ) ) ?;
1721
1735
1722
1736
// Convert applications from the main branch.
1723
- let mut merged_apps: Vec < ( ApplicationGithubInfo , ApplicationFile ) > = Vec :: new ( ) ;
1737
+ let mut merged_apps: Vec < ( ApplicationGithubInfo , ApplicationResponse ) > = Vec :: new ( ) ;
1724
1738
for app_model in merged_app_models {
1725
1739
// Try to deserialize the `application` field to `ApplicationFile`.
1726
1740
if let Some ( app_json) = app_model. application {
@@ -1731,15 +1745,25 @@ impl LDNApplication {
1731
1745
let path = app_model
1732
1746
. path
1733
1747
. ok_or ( LDNError :: Load ( "Failed to get path" . to_string ( ) ) ) ?;
1734
- merged_apps. push ( ( ApplicationGithubInfo { sha, path } , app) ) ;
1748
+ merged_apps. push ( (
1749
+ ApplicationGithubInfo { sha, path } ,
1750
+ ApplicationResponse {
1751
+ file : app,
1752
+ issue_reporter_handle : app_model. issue_reporter_handle ,
1753
+ repo : app_model. repo ,
1754
+ owner : app_model. owner ,
1755
+ } ,
1756
+ ) ) ;
1735
1757
}
1736
1758
}
1737
1759
}
1738
1760
1739
1761
let active_apps = Self :: active ( owner, repo, None ) . await ?;
1740
- let mut apps: Vec < ( ApplicationGithubInfo , ApplicationFile ) > = vec ! [ ] ;
1762
+ let mut apps: Vec < ( ApplicationGithubInfo , ApplicationResponse ) > = vec ! [ ] ;
1741
1763
for app in merged_apps {
1742
- if !active_apps. iter ( ) . any ( |a| a. id == app. 1 . id ) && app. 1 . lifecycle . is_active {
1764
+ if !active_apps. iter ( ) . any ( |a| a. file . id == app. 1 . file . id )
1765
+ && app. 1 . file . lifecycle . is_active
1766
+ {
1743
1767
apps. push ( app) ;
1744
1768
}
1745
1769
}
@@ -1750,7 +1774,9 @@ impl LDNApplication {
1750
1774
async fn refill ( verfier : & str , refill_info : RefillInfo ) -> Result < bool , LDNError > {
1751
1775
let apps =
1752
1776
LDNApplication :: merged ( refill_info. owner . clone ( ) , refill_info. repo . clone ( ) ) . await ?;
1753
- if let Some ( ( content, mut app) ) = apps. into_iter ( ) . find ( |( _, app) | app. id == refill_info. id )
1777
+ if let Some ( ( content, mut app) ) = apps
1778
+ . into_iter ( )
1779
+ . find ( |( _, app) | app. file . id == refill_info. id )
1754
1780
{
1755
1781
let uuid = uuidv4:: uuid:: v4 ( ) ;
1756
1782
let request_id = uuid. clone ( ) ;
@@ -1760,19 +1786,19 @@ impl LDNApplication {
1760
1786
AllocationRequestType :: Refill ( 0 ) ,
1761
1787
format ! ( "{}{}" , refill_info. amount, refill_info. amount_type) ,
1762
1788
) ;
1763
- let app_file = app. start_refill_request ( new_request) ;
1789
+ let app_file = app. file . start_refill_request ( new_request) ;
1764
1790
Self :: issue_refill (
1765
- app. issue_number . clone ( ) ,
1791
+ app. file . issue_number . clone ( ) ,
1766
1792
refill_info. owner . clone ( ) ,
1767
1793
refill_info. repo . clone ( ) ,
1768
1794
)
1769
1795
. await ?;
1770
1796
1771
- let pr_title = format ! ( "Datacap for {}" , app. client. name. clone( ) ) ;
1797
+ let pr_title = format ! ( "Datacap for {}" , app. file . client. name. clone( ) ) ;
1772
1798
let parsed_app_file = serde_json:: to_string_pretty ( & app_file)
1773
1799
. map_err ( |e| LDNError :: Load ( format ! ( "Failed to pare into string: {}" , e) ) ) ?;
1774
1800
LDNPullRequest :: create_pr_for_existing_application (
1775
- app. id . clone ( ) ,
1801
+ app. file . id . clone ( ) ,
1776
1802
parsed_app_file,
1777
1803
content. path . clone ( ) , // filename
1778
1804
request_id. clone ( ) ,
@@ -2557,6 +2583,11 @@ impl LDNApplication {
2557
2583
application_file. issue_number, e
2558
2584
) )
2559
2585
} ) ?;
2586
+ let issue_reporter_handle = gh
2587
+ . get_issue_reporter_handle (
2588
+ & issue_number. try_into ( ) . expect ( "Value must be non-negative" ) ,
2589
+ )
2590
+ . await ?;
2560
2591
database:: applications:: create_application (
2561
2592
application_id,
2562
2593
owner. clone ( ) ,
@@ -2565,6 +2596,7 @@ impl LDNApplication {
2565
2596
issue_number,
2566
2597
file_content. clone ( ) ,
2567
2598
filename. clone ( ) ,
2599
+ Some ( issue_reporter_handle) ,
2568
2600
)
2569
2601
. await
2570
2602
. map_err ( |e| {
@@ -3540,6 +3572,12 @@ _The initial issue can be edited in order to solve the request of the verifier.
3540
3572
let parsed_app_file = serde_json:: to_string_pretty ( & gh_app. application_file )
3541
3573
. map_err ( |e| LDNError :: Load ( format ! ( "Failed to pare into string: {}" , e) ) ) ?;
3542
3574
// Call the create_application function if the GH app is not in DB
3575
+ let gh: GithubWrapper = github_async_new ( owner. clone ( ) , repo. clone ( ) ) . await ?;
3576
+ let issue_reporter_handle = gh
3577
+ . get_issue_reporter_handle (
3578
+ & issue_number. try_into ( ) . expect ( "Value must be non-negative" ) ,
3579
+ )
3580
+ . await ?;
3543
3581
database:: applications:: create_application (
3544
3582
gh_app. application_file . id . clone ( ) ,
3545
3583
owner. clone ( ) ,
@@ -3548,6 +3586,7 @@ _The initial issue can be edited in order to solve the request of the verifier.
3548
3586
issue_number,
3549
3587
parsed_app_file,
3550
3588
gh_app. path ,
3589
+ Some ( issue_reporter_handle) ,
3551
3590
)
3552
3591
. await
3553
3592
. map_err ( |e| {
@@ -3639,6 +3678,12 @@ _The initial issue can be edited in order to solve the request of the verifier.
3639
3678
// Call the create_application function if the GH app is not in DB
3640
3679
let parsed_app_file = serde_json:: to_string_pretty ( & gh_app. application_file )
3641
3680
. map_err ( |e| LDNError :: Load ( format ! ( "Failed to pare into string: {}" , e) ) ) ?;
3681
+ let gh: GithubWrapper = github_async_new ( owner. clone ( ) , repo. clone ( ) ) . await ?;
3682
+ let issue_reporter_handle = gh
3683
+ . get_issue_reporter_handle (
3684
+ & issue_number. try_into ( ) . expect ( "Value must be non-negative" ) ,
3685
+ )
3686
+ . await ?;
3642
3687
database:: applications:: create_application (
3643
3688
gh_app. application_file . id . clone ( ) ,
3644
3689
owner. clone ( ) ,
@@ -3647,6 +3692,7 @@ _The initial issue can be edited in order to solve the request of the verifier.
3647
3692
issue_number,
3648
3693
parsed_app_file,
3649
3694
gh_app. path ,
3695
+ Some ( issue_reporter_handle) ,
3650
3696
)
3651
3697
. await
3652
3698
. map_err ( |e| {
@@ -4427,6 +4473,11 @@ impl LDNPullRequest {
4427
4473
let issue_number = issue_number
4428
4474
. parse :: < i64 > ( )
4429
4475
. map_err ( |e| LDNError :: New ( format ! ( "Parse issue number to i64 failed: {}" , e) ) ) ?;
4476
+ let issue_reporter_handle = gh
4477
+ . get_issue_reporter_handle (
4478
+ & issue_number. try_into ( ) . expect ( "Value must be non-negative" ) ,
4479
+ )
4480
+ . await ?;
4430
4481
database:: applications:: create_application (
4431
4482
application_id. clone ( ) ,
4432
4483
owner,
@@ -4435,6 +4486,7 @@ impl LDNPullRequest {
4435
4486
issue_number,
4436
4487
file_content,
4437
4488
file_name,
4489
+ Some ( issue_reporter_handle) ,
4438
4490
)
4439
4491
. await
4440
4492
. map_err ( |e| {
0 commit comments