@@ -81,13 +81,6 @@ pub struct TriggerSSAInfo {
8181 pub early_refill_comment : Option < String > ,
8282}
8383
84- #[ derive( Deserialize ) ]
85- pub struct BranchDeleteInfo {
86- pub owner : String ,
87- pub repo : String ,
88- pub branch_name : String ,
89- }
90-
9184#[ derive( Deserialize ) ]
9285pub struct NewPrNumberAndFileSha {
9386 pub pr_number : u64 ,
@@ -1952,11 +1945,13 @@ impl LDNApplication {
19521945
19531946 let gh = github_async_new ( self . github . owner . clone ( ) , self . github . repo . clone ( ) ) . await ?;
19541947
1955- gh. merge_pull_request ( pr_number) . await . map_err ( |e| {
1956- LDNError :: Load ( format ! (
1957- "Failed to merge pull request {pr_number}. Reason: {e}"
1958- ) )
1959- } ) ?;
1948+ gh. merge_pull_request_and_delete_branch ( & pr_number)
1949+ . await
1950+ . map_err ( |e| {
1951+ LDNError :: Load ( format ! (
1952+ "Failed to merge pull request {pr_number} or delete branch. Reason: {e}"
1953+ ) )
1954+ } ) ?;
19601955
19611956 database:: applications:: merge_application_by_pr_number (
19621957 self . github . owner . clone ( ) ,
@@ -2249,29 +2244,31 @@ impl LDNApplication {
22492244 }
22502245 log:: info!( "- Application is in a valid state!" ) ;
22512246
2252- Self :: merge_application ( pr_number, owner, repo) . await ?;
2247+ Self :: merge_application_and_delete_branch ( pr_number, owner, repo) . await ?;
22532248 return Ok ( true ) ;
22542249 } else if application. lifecycle . get_state ( ) == AppState :: Declined {
2255- Self :: merge_application ( pr_number, owner, repo) . await ?;
2250+ Self :: merge_application_and_delete_branch ( pr_number, owner, repo) . await ?;
22562251 return Ok ( true ) ;
22572252 }
22582253
22592254 log:: warn!( "- Application is not in a valid state" ) ;
22602255 Ok ( false )
22612256 }
22622257
2263- pub async fn merge_application (
2258+ pub async fn merge_application_and_delete_branch (
22642259 pr_number : u64 ,
22652260 owner : String ,
22662261 repo : String ,
22672262 ) -> Result < bool , LDNError > {
22682263 let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ?;
22692264
2270- gh. merge_pull_request ( pr_number) . await . map_err ( |e| {
2271- LDNError :: Load ( format ! (
2272- "Failed to merge pull request {pr_number}. Reason: {e}"
2273- ) )
2274- } ) ?;
2265+ gh. merge_pull_request_and_delete_branch ( & pr_number)
2266+ . await
2267+ . map_err ( |e| {
2268+ LDNError :: Load ( format ! (
2269+ "Failed to merge pull request {pr_number} or delete branch. Reason: {e}"
2270+ ) )
2271+ } ) ?;
22752272
22762273 database:: applications:: merge_application_by_pr_number ( owner, repo, pr_number)
22772274 . await
@@ -2370,11 +2367,6 @@ impl LDNApplication {
23702367 log:: info!( "- Application is in a valid state!" ) ;
23712368 return Ok ( true ) ;
23722369 }
2373- // let bot_user = get_env_var_or_default("BOT_USER");
2374- // if author != bot_user {
2375- // log::warn!("- Author is not the bot user");
2376- // return Ok(false);
2377- // }
23782370
23792371 log:: info!( "- Application is in a valid state" ) ;
23802372 Ok ( true )
@@ -2745,18 +2737,11 @@ impl LDNApplication {
27452737
27462738 pub async fn check_for_changes (
27472739 pr_number : u64 ,
2748- author : & str ,
27492740 owner : String ,
27502741 repo : String ,
27512742 ) -> Result < bool , LDNError > {
27522743 log:: info!( "Starting check_for_changes:" ) ;
27532744
2754- let bot_user = get_env_var_or_default ( "BOT_USER" ) ;
2755- if author != bot_user {
2756- log:: warn!( "- Author is not the bot user" ) ;
2757- return Err ( LDNError :: New ( "PR File edited by user" . to_string ( ) ) ) ;
2758- }
2759-
27602745 let gh: GithubWrapper = github_async_new ( owner. clone ( ) , repo. clone ( ) ) . await ?;
27612746 let result = Self :: get_pr_files_and_app ( owner. clone ( ) , repo. clone ( ) , pr_number) . await ;
27622747
@@ -3491,23 +3476,6 @@ impl LDNApplication {
34913476 Ok ( ( ) )
34923477 }
34933478
3494- pub async fn delete_branch (
3495- owner : String ,
3496- repo : String ,
3497- branch_name : String ,
3498- ) -> Result < bool , LDNError > {
3499- let gh = github_async_new ( owner, repo) . await ?;
3500- let request = gh
3501- . build_remove_ref_request ( branch_name. clone ( ) )
3502- . map_err ( |e| LDNError :: New ( format ! ( "build_remove_ref_request function failed: {e}" ) ) ) ?;
3503-
3504- gh. remove_branch ( request)
3505- . await
3506- . map_err ( |e| LDNError :: New ( format ! ( "Error deleting branch {branch_name} /// {e}" ) ) ) ?;
3507-
3508- Ok ( true )
3509- }
3510-
35113479 async fn add_comment_to_issue (
35123480 issue_number : String ,
35133481 owner : String ,
@@ -4268,11 +4236,13 @@ _The initial issue can be edited in order to solve the request of the verifier.
42684236 if !application_file. allocation . 0 . is_empty ( ) {
42694237 let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ?;
42704238
4271- gh. merge_pull_request ( pr_number) . await . map_err ( |e| {
4272- LDNError :: Load ( format ! (
4273- "Failed to merge pull request {pr_number}. Reason: {e}"
4274- ) )
4275- } ) ?;
4239+ gh. merge_pull_request_and_delete_branch ( & pr_number)
4240+ . await
4241+ . map_err ( |e| {
4242+ LDNError :: Load ( format ! (
4243+ "Failed to merge pull request {pr_number} or delete branch. Reason: {e}"
4244+ ) )
4245+ } ) ?;
42764246
42774247 database:: applications:: merge_application_by_pr_number (
42784248 owner. to_string ( ) ,
@@ -4712,7 +4682,8 @@ _The initial issue can be edited in order to solve the request of the verifier.
47124682 self . remove_first_pending_allocation ( & application_file)
47134683 . await ?;
47144684 } else {
4715- self . remove_pending_refill ( & app_model. pr_number ) . await ?;
4685+ self . remove_pending_refill ( & ( app_model. pr_number as u64 ) )
4686+ . await ?;
47164687 }
47174688
47184689 let comment = format ! (
@@ -4784,18 +4755,21 @@ _The initial issue can be edited in order to solve the request of the verifier.
47844755 Ok ( ( ) )
47854756 }
47864757
4787- async fn remove_pending_refill ( & self , pr_number : & i64 ) -> Result < ( ) , LDNError > {
4788- Self :: delete_branch (
4789- self . github . owner . clone ( ) ,
4790- self . github . repo . clone ( ) ,
4791- self . branch_name . clone ( ) ,
4792- )
4793- . await ?;
4758+ async fn remove_pending_refill ( & self , pr_number : & u64 ) -> Result < ( ) , LDNError > {
4759+ self . github
4760+ . delete_branch_safe ( pr_number)
4761+ . await
4762+ . map_err ( |e| {
4763+ LDNError :: New ( format ! (
4764+ "Failed to delete branch for PR number: {pr_number} Reason: {e:?}"
4765+ ) )
4766+ } ) ?;
4767+
47944768 database:: applications:: delete_application (
47954769 self . application_id . clone ( ) ,
47964770 self . github . owner . clone ( ) ,
47974771 self . github . repo . clone ( ) ,
4798- * pr_number as u64 ,
4772+ * pr_number,
47994773 )
48004774 . await
48014775 . map_err ( |e| {
@@ -5044,22 +5018,6 @@ impl LDNPullRequest {
50445018 Ok ( ( ) )
50455019 }
50465020
5047- pub async fn delete_branch (
5048- application_id : String ,
5049- owner : String ,
5050- repo : String ,
5051- ) -> Result < ( ) , LDNError > {
5052- let gh = github_async_new ( owner. clone ( ) , repo. clone ( ) ) . await ?;
5053- let branch_name = LDNPullRequest :: application_branch_name ( & application_id) ;
5054- let request = gh
5055- . build_remove_ref_request ( branch_name. clone ( ) )
5056- . map_err ( |e| LDNError :: New ( format ! ( "build_remove_ref_request function failed: {e}" ) ) ) ?;
5057- gh. remove_branch ( request)
5058- . await
5059- . map_err ( |e| LDNError :: New ( format ! ( "Error deleting branch {branch_name} /// {e}" ) ) ) ?;
5060- Ok ( ( ) )
5061- }
5062-
50635021 pub ( super ) fn application_branch_name ( application_id : & str ) -> String {
50645022 format ! ( "Application/{application_id}" )
50655023 }
0 commit comments