@@ -12,11 +12,11 @@ use chrono::{DateTime, Utc};
12
12
use serde_json:: from_str;
13
13
14
14
use crate :: {
15
- base64:: { self } ,
15
+ base64,
16
16
config:: get_env_var_or_default,
17
17
error:: LDNError ,
18
18
external_services:: github:: {
19
- CreateMergeRequestData , CreateRefillMergeRequestData , GithubWrapper ,
19
+ github_async_new , CreateMergeRequestData , CreateRefillMergeRequestData , GithubWrapper
20
20
} ,
21
21
parsers:: ParsedIssue ,
22
22
} ;
@@ -155,7 +155,7 @@ pub struct ApplicationGithubInfo {
155
155
impl LDNApplication {
156
156
157
157
pub async fn single_active ( pr_number : u64 , owner : String , repo : String ) -> Result < ApplicationFile , LDNError > {
158
- let gh: GithubWrapper = GithubWrapper :: new ( owner, repo) ;
158
+ let gh = github_async_new ( owner, repo) . await ;
159
159
let ( _, pull_request) = gh. get_pull_request_files ( pr_number) . await . unwrap ( ) ;
160
160
let pull_request = pull_request. get ( 0 ) . unwrap ( ) ;
161
161
let pull_request: Response = reqwest:: Client :: new ( )
@@ -183,7 +183,7 @@ impl LDNApplication {
183
183
owner : String ,
184
184
repo : String
185
185
) -> Result < Option < ( String , String , ApplicationFile , PullRequest ) > , LDNError > {
186
- let gh = GithubWrapper :: new ( owner, repo) ;
186
+ let gh = github_async_new ( owner, repo) . await ;
187
187
let files = match gh. get_pull_request_files ( pr. number ) . await {
188
188
Ok ( files) => files,
189
189
Err ( _) => return Ok ( None ) ,
@@ -250,7 +250,7 @@ impl LDNApplication {
250
250
251
251
pub async fn load ( application_id : String , owner : String , repo : String ) -> Result < Self , LDNError > {
252
252
253
- let gh: GithubWrapper = GithubWrapper :: new ( owner. clone ( ) , repo. clone ( ) ) ;
253
+ let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ;
254
254
let pull_requests = gh. list_pull_requests ( ) . await . unwrap ( ) ;
255
255
let pull_requests = future:: try_join_all (
256
256
pull_requests
@@ -353,7 +353,7 @@ impl LDNApplication {
353
353
}
354
354
355
355
pub async fn active_apps_with_last_update ( owner : String , repo : String , filter : Option < String > ) -> Result < Vec < ApplicationFileWithDate > , LDNError > {
356
- let gh: GithubWrapper = GithubWrapper :: new ( owner. clone ( ) , repo. clone ( ) ) ;
356
+ let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ;
357
357
let mut apps: Vec < ApplicationFileWithDate > = Vec :: new ( ) ;
358
358
let pull_requests = gh. list_pull_requests ( ) . await . unwrap ( ) ;
359
359
let pull_requests = future:: try_join_all (
@@ -385,8 +385,8 @@ impl LDNApplication {
385
385
}
386
386
387
387
pub async fn merged_apps_with_last_update ( owner : String , repo : String , filter : Option < String > ) -> Result < Vec < ApplicationFileWithDate > , LDNError > {
388
-
389
- let gh = Arc :: new ( GithubWrapper :: new ( owner . clone ( ) , repo . clone ( ) ) ) ;
388
+ let gh = Arc :: new ( github_async_new ( owner . to_string ( ) , repo . to_string ( ) ) . await ) ;
389
+
390
390
let applications_path = "applications" ;
391
391
let mut all_files_result = gh. get_files ( applications_path) . await . map_err ( |e| {
392
392
LDNError :: Load ( format ! ( "Failed to retrieve all files from GitHub. Reason: {}" , e) )
@@ -428,7 +428,7 @@ impl LDNApplication {
428
428
/// Create New Application
429
429
pub async fn new_from_issue ( info : CreateApplicationInfo ) -> Result < Self , LDNError > {
430
430
let issue_number = info. issue_number ;
431
- let gh: GithubWrapper = GithubWrapper :: new ( info. owner . clone ( ) , info. repo . clone ( ) ) ;
431
+ let gh = github_async_new ( info. owner . to_string ( ) , info. repo . to_string ( ) ) . await ;
432
432
let ( parsed_ldn, _) = LDNApplication :: parse_application_issue (
433
433
issue_number. clone ( ) ,
434
434
info. owner . clone ( ) ,
@@ -762,7 +762,7 @@ impl LDNApplication {
762
762
owner : String ,
763
763
repo : String ,
764
764
) -> Result < ( ParsedIssue , String ) , LDNError > {
765
- let gh: GithubWrapper = GithubWrapper :: new ( owner, repo) ;
765
+ let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ;
766
766
let issue = gh
767
767
. list_issue ( issue_number. parse ( ) . unwrap ( ) )
768
768
. await
@@ -796,7 +796,7 @@ impl LDNApplication {
796
796
. find_first ( |( _, app) | app. id == application_id) ;
797
797
if app. is_some ( ) && app. unwrap ( ) . 1 . lifecycle . get_state ( ) == AppState :: Granted {
798
798
let app = app. unwrap ( ) . 1 . reached_total_datacap ( ) ;
799
- let gh: GithubWrapper = GithubWrapper :: new ( owner. clone ( ) , repo. clone ( ) ) ;
799
+ let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ;
800
800
let ldn_app = LDNApplication :: load ( application_id. clone ( ) , owner. clone ( ) , repo. clone ( ) ) . await ?;
801
801
let ContentItems { items } = gh. get_file ( & ldn_app. file_name , "main" ) . await . unwrap ( ) ;
802
802
Self :: issue_full_dc ( app. issue_number . clone ( ) , owner. clone ( ) , repo. clone ( ) ) . await ?;
@@ -1037,7 +1037,7 @@ impl LDNApplication {
1037
1037
}
1038
1038
1039
1039
pub async fn merge_application ( pr_number : u64 , owner : String , repo : String ) -> Result < bool , LDNError > {
1040
- let gh = GithubWrapper :: new ( owner. clone ( ) , repo. clone ( ) ) ;
1040
+ let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ;
1041
1041
1042
1042
gh. merge_pull_request ( pr_number) . await . map_err ( |e| {
1043
1043
LDNError :: Load ( format ! (
@@ -1064,7 +1064,7 @@ impl LDNApplication {
1064
1064
actor
1065
1065
) ;
1066
1066
1067
- let gh = GithubWrapper :: new ( owner, repo) ;
1067
+ let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ;
1068
1068
let author = match gh. get_last_commit_author ( pr_number) . await {
1069
1069
Ok ( author) => {
1070
1070
log:: info!( "- Last commit author: {}" , author) ;
@@ -1325,7 +1325,7 @@ impl LDNApplication {
1325
1325
. await
1326
1326
{
1327
1327
Some ( ( ) ) => {
1328
- let gh = GithubWrapper :: new ( owner. clone ( ) , repo. clone ( ) ) ;
1328
+ let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ;
1329
1329
match gh. get_pull_request_by_head ( & ldn_application. branch_name ) . await {
1330
1330
Ok ( prs) => {
1331
1331
if let Some ( pr) = prs. get ( 0 ) {
@@ -1495,7 +1495,7 @@ impl LDNApplication {
1495
1495
}
1496
1496
1497
1497
async fn issue_waiting_for_gov_review ( issue_number : String , owner : String , repo : String ) -> Result < bool , LDNError > {
1498
- let gh = GithubWrapper :: new ( owner, repo) ;
1498
+ let gh = github_async_new ( owner, repo) . await ;
1499
1499
gh. add_comment_to_issue (
1500
1500
issue_number. parse ( ) . unwrap ( ) ,
1501
1501
"Application is waiting for governance review" ,
@@ -1512,7 +1512,7 @@ impl LDNApplication {
1512
1512
}
1513
1513
1514
1514
async fn issue_datacap_request_trigger ( application_file : ApplicationFile , owner : String , repo : String ) -> Result < bool , LDNError > {
1515
- let gh: GithubWrapper = GithubWrapper :: new ( owner, repo) ;
1515
+ let gh = github_async_new ( owner, repo) . await ;
1516
1516
1517
1517
let client_address = application_file. lifecycle . client_on_chain_address . clone ( ) ;
1518
1518
let total_requested = application_file. datacap . total_requested_amount . clone ( ) ;
@@ -1555,7 +1555,7 @@ impl LDNApplication {
1555
1555
active_allocation : Option < & Allocation > ,
1556
1556
owner : String , repo : String
1557
1557
) -> Result < bool , LDNError > {
1558
- let gh = GithubWrapper :: new ( owner, repo) ;
1558
+ let gh = github_async_new ( owner, repo) . await ;
1559
1559
1560
1560
let issue_number = application_file. issue_number . clone ( ) ;
1561
1561
@@ -1613,7 +1613,7 @@ impl LDNApplication {
1613
1613
. iter ( )
1614
1614
. find ( |obj| Some ( & obj. id ) == application_file. lifecycle . active_request . clone ( ) . as_ref ( ) ) ;
1615
1615
1616
- let gh = GithubWrapper :: new ( owner, repo) ;
1616
+ let gh = github_async_new ( owner, repo) . await ;
1617
1617
1618
1618
let issue_number = application_file. issue_number . clone ( ) ;
1619
1619
@@ -1680,7 +1680,7 @@ Your Datacap Allocation Request has been {} by the Notary
1680
1680
owner : String ,
1681
1681
repo : String
1682
1682
) -> Result < bool , LDNError > {
1683
- let gh = GithubWrapper :: new ( owner, repo) ;
1683
+ let gh = github_async_new ( owner, repo) . await ;
1684
1684
gh. add_comment_to_issue (
1685
1685
issue_number. parse ( ) . unwrap ( ) ,
1686
1686
"Application is ready to sign" ,
@@ -1697,7 +1697,7 @@ Your Datacap Allocation Request has been {} by the Notary
1697
1697
}
1698
1698
1699
1699
async fn issue_start_sign_dc ( issue_number : String , owner : String , repo : String ) -> Result < bool , LDNError > {
1700
- let gh = GithubWrapper :: new ( owner, repo) ;
1700
+ let gh = github_async_new ( owner, repo) . await ;
1701
1701
gh. add_comment_to_issue (
1702
1702
issue_number. parse ( ) . unwrap ( ) ,
1703
1703
"Application is in the process of signing datacap" ,
@@ -1713,7 +1713,7 @@ Your Datacap Allocation Request has been {} by the Notary
1713
1713
Ok ( true )
1714
1714
}
1715
1715
async fn issue_granted ( issue_number : String , owner : String , repo : String ) -> Result < bool , LDNError > {
1716
- let gh = GithubWrapper :: new ( owner, repo) ;
1716
+ let gh = github_async_new ( owner, repo) . await ;
1717
1717
gh. add_comment_to_issue ( issue_number. parse ( ) . unwrap ( ) , "Application is Granted" )
1718
1718
. await
1719
1719
. map_err ( |e| {
@@ -1726,7 +1726,7 @@ Your Datacap Allocation Request has been {} by the Notary
1726
1726
Ok ( true )
1727
1727
}
1728
1728
async fn issue_refill ( issue_number : String , owner : String , repo : String ) -> Result < bool , LDNError > {
1729
- let gh = GithubWrapper :: new ( owner, repo) ;
1729
+ let gh = github_async_new ( owner, repo) . await ;
1730
1730
gh. add_comment_to_issue ( issue_number. parse ( ) . unwrap ( ) , "Application is in Refill" )
1731
1731
. await
1732
1732
. map_err ( |e| {
@@ -1748,7 +1748,7 @@ Your Datacap Allocation Request has been {} by the Notary
1748
1748
Ok ( true )
1749
1749
}
1750
1750
async fn issue_full_dc ( issue_number : String , owner : String , repo : String ) -> Result < bool , LDNError > {
1751
- let gh = GithubWrapper :: new ( owner, repo) ;
1751
+ let gh = github_async_new ( owner, repo) . await ;
1752
1752
gh. add_comment_to_issue ( issue_number. parse ( ) . unwrap ( ) , "Application is Completed" )
1753
1753
. await
1754
1754
. map_err ( |e| {
@@ -1762,7 +1762,7 @@ Your Datacap Allocation Request has been {} by the Notary
1762
1762
}
1763
1763
1764
1764
async fn add_error_label ( issue_number : String , comment : String , owner : String , repo : String ) -> Result < ( ) , LDNError > {
1765
- let gh = GithubWrapper :: new ( owner, repo) ;
1765
+ let gh = github_async_new ( owner, repo) . await ;
1766
1766
let num: u64 = issue_number. parse ( ) . expect ( "Not a valid integer" ) ;
1767
1767
gh. add_error_label ( num, comment) . await
1768
1768
. map_err ( |e| {
@@ -1777,7 +1777,7 @@ Your Datacap Allocation Request has been {} by the Notary
1777
1777
}
1778
1778
1779
1779
async fn update_issue_labels ( issue_number : String , new_labels : & [ & str ] , owner : String , repo : String ) -> Result < ( ) , LDNError > {
1780
- let gh = GithubWrapper :: new ( owner, repo) ;
1780
+ let gh = github_async_new ( owner, repo) . await ;
1781
1781
let num: u64 = issue_number. parse ( ) . expect ( "Not a valid integer" ) ;
1782
1782
gh. update_issue_labels (
1783
1783
num,
@@ -1929,7 +1929,7 @@ impl LDNPullRequest {
1929
1929
repo : String
1930
1930
) -> Result < String , LDNError > {
1931
1931
let initial_commit = Self :: application_initial_commit ( & owner_name, & application_id) ;
1932
- let gh: GithubWrapper = GithubWrapper :: new ( owner, repo) ;
1932
+ let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ;
1933
1933
let head_hash = gh. get_main_branch_sha ( ) . await . unwrap ( ) ;
1934
1934
let create_ref_request = gh
1935
1935
. build_create_ref_request ( app_branch_name. clone ( ) , head_hash)
@@ -1972,7 +1972,7 @@ impl LDNPullRequest {
1972
1972
repo : String
1973
1973
) -> Result < u64 , LDNError > {
1974
1974
let initial_commit = Self :: application_initial_commit ( & owner_name, & application_id) ;
1975
- let gh: GithubWrapper = GithubWrapper :: new ( owner. clone ( ) , repo. clone ( ) ) ;
1975
+ let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ;
1976
1976
let head_hash = gh. get_main_branch_sha ( ) . await . unwrap ( ) ;
1977
1977
let create_ref_request = gh
1978
1978
. build_create_ref_request ( branch_name. clone ( ) , head_hash)
@@ -2031,7 +2031,7 @@ impl LDNPullRequest {
2031
2031
owner : String ,
2032
2032
repo : String
2033
2033
) -> Option < ( ) > {
2034
- let gh: GithubWrapper = GithubWrapper :: new ( owner, repo) ;
2034
+ let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ;
2035
2035
match gh
2036
2036
. update_file_content (
2037
2037
& path,
@@ -2107,7 +2107,7 @@ mod tests {
2107
2107
log:: info!( "Starting end-to-end test" ) ;
2108
2108
2109
2109
// Test Creating an application
2110
- let gh: GithubWrapper = GithubWrapper :: new ( OWNER . to_string ( ) , REPO . to_string ( ) ) ;
2110
+ let gh = github_async_new ( OWNER . to_string ( ) , REPO . to_string ( ) ) . await ;
2111
2111
2112
2112
log:: info!( "Creating a new LDNApplication from issue" ) ;
2113
2113
let ldn_application = match LDNApplication :: new_from_issue ( CreateApplicationInfo {
0 commit comments