@@ -341,15 +341,22 @@ impl GithubWrapper {
341341 }
342342
343343 pub async fn list_branches ( & self ) -> Result < Vec < Branch > , OctocrabError > {
344- let iid = self
344+ let mut all_branches = Vec :: new ( ) ;
345+ let mut page = self
345346 . inner
346347 . repos ( & self . owner , & self . repo )
347348 . list_branches ( )
348349 . send ( )
349350 . await ?;
350- Ok ( iid. items )
351- }
351+ all_branches. extend ( page. items ) ;
352+
353+ while let Some ( next_page) = self . inner . get_page :: < Branch > ( & page. next ) . await ? {
354+ all_branches. extend ( next_page. clone ( ) . items ) ;
355+ page = next_page;
356+ }
352357
358+ Ok ( all_branches)
359+ }
353360 /// creates new branch under head on github
354361 /// you should use build_create_ref_request function to construct request
355362 pub async fn create_branch ( & self , request : Request < String > ) -> Result < bool , OctocrabError > {
@@ -611,6 +618,13 @@ impl GithubWrapper {
611618 file_sha,
612619 application_id,
613620 } = data;
621+ let branch_exists = self . check_if_branch_exists ( & branch_name) . await ?;
622+ if branch_exists {
623+ return Err ( OctocrabError :: Other {
624+ source : format ! ( "Branch {branch_name} already exists." ) . into ( ) ,
625+ backtrace : GenerateImplicitData :: generate ( ) ,
626+ } ) ;
627+ }
614628 self . create_branch ( ref_request) . await ?;
615629 let file_update = self
616630 . update_file_content ( & file_name, & commit, & file_content, & branch_name, & file_sha)
@@ -762,6 +776,15 @@ impl GithubWrapper {
762776 Ok ( pull_request. head . ref_field . clone ( ) )
763777 }
764778
779+ pub async fn check_if_branch_exists ( & self , branch_name : & str ) -> Result < bool , OctocrabError > {
780+ let branch_exists = self
781+ . list_branches ( )
782+ . await ?
783+ . iter ( )
784+ . any ( |branch| branch. name == branch_name) ;
785+ Ok ( branch_exists)
786+ }
787+
765788 pub async fn get_files_from_public_repo (
766789 & self ,
767790 owner : & str ,
0 commit comments