@@ -4,7 +4,7 @@ use gen::cli::{Cli, Subcommands};
44use gen:: config:: Conf ;
55use gen:: edit:: change_file;
66use gen:: github:: GitHub ;
7- use gen:: process:: { gh, git} ;
7+ use gen:: process:: { gh, git, try_git } ;
88use rand:: Rng ;
99use regex:: Regex ;
1010use serde_json:: to_string_pretty;
@@ -104,14 +104,19 @@ fn test_with_flakes(config: &Conf) -> bool {
104104 random_float > config. flake_rate
105105}
106106
107- fn create_pull_request ( words : & [ String ] ) -> String {
107+ fn create_pull_request ( words : & [ String ] ) -> Result < String , String > {
108108 let branch_name = format ! ( "change/{}" , words. join( "-" ) ) ;
109109 git ( & [ "checkout" , "-t" , "-b" , & branch_name] ) ;
110110
111111 let commit_msg = format ! ( "Moving words {}" , words. join( ", " ) ) ;
112112 git ( & [ "commit" , "-am" , & commit_msg] ) ;
113- git ( & [ "push" , "--set-upstream" , "origin" , "HEAD" ] ) ;
114-
113+ let result = try_git ( & [ "push" , "--set-upstream" , "origin" , "HEAD" ] ) ;
114+ if result. is_err ( ) {
115+ git ( & [ "checkout" , "main" ] ) ;
116+ git ( & [ "pull" ] ) ;
117+ return Err ( "could not push to origin" . to_owned ( ) ) ;
118+ }
119+
115120 let pr_url = gh ( & [
116121 "pr" ,
117122 "create" ,
@@ -130,7 +135,7 @@ fn create_pull_request(words: &[String]) -> String {
130135 git ( & [ "checkout" , "main" ] ) ;
131136 git ( & [ "pull" ] ) ;
132137
133- pr_number. to_string ( )
138+ Ok ( pr_number. to_string ( ) )
134139}
135140
136141fn run ( ) -> anyhow:: Result < ( ) > {
@@ -195,8 +200,13 @@ fn run() -> anyhow::Result<()> {
195200 let max_impacted_deps = config. max_impacted_deps as u32 ; // Convert usize to u32
196201 let words = change_file ( & filenames, max_impacted_deps) ; // Use the converted value
197202
198- let pr = create_pull_request ( & words) ;
203+ let pr_result = create_pull_request ( & words) ;
204+ if pr_result. is_err ( ) {
205+ println ! ( "problem created pr for {:?}" , words) ;
206+ continue ;
207+ }
199208 let duration = start. elapsed ( ) ;
209+ let pr = pr_result. unwrap ( ) ;
200210 println ! ( "created pr: {} in {:?}" , pr, duration) ;
201211 prs. push ( pr) ;
202212 }
0 commit comments