@@ -384,6 +384,7 @@ def parse_args() -> Any:
384384 parser = ArgumentParser ("Merge PR into default branch" )
385385 parser .add_argument ("--dry-run" , action = "store_true" )
386386 parser .add_argument ("--on-green" , action = "store_true" )
387+ parser .add_argument ("--all-green" , action = "store_true" )
387388 parser .add_argument ("--revert" , action = "store_true" )
388389 parser .add_argument ("--force" , action = "store_true" )
389390 parser .add_argument ("--comment-id" , type = int )
@@ -887,7 +888,7 @@ def prefix_with_github_url(suffix_str: str) -> str:
887888 return f"https://github.com/{ suffix_str } "
888889
889890
890- def merge_on_green (pr_num : int , repo : GitRepo , dry_run : bool = False , timeout_minutes : int = 400 ) -> None :
891+ def merge_on_green (pr_num : int , repo : GitRepo , dry_run : bool = False , timeout_minutes : int = 400 , all_green : bool = False ) -> None :
891892 repo = GitRepo (get_git_repo_dir (), get_git_remote_name ())
892893 org , project = repo .gh_owner_and_name ()
893894 start_time = time .time ()
@@ -897,10 +898,25 @@ def merge_on_green(pr_num: int, repo: GitRepo, dry_run: bool = False, timeout_mi
897898 current_time = time .time ()
898899 elapsed_time = current_time - start_time
899900
900-
901901 pr = GitHubPR (org , project , pr_num )
902902 try :
903- return pr .merge_into (repo , dry_run = dry_run )
903+ if all_green :
904+ checks = pr .get_checkrun_conclusions ()
905+ pending_checks = []
906+ failed_checks = []
907+ for check in checks :
908+ if checks [check ] is None :
909+ pending_checks .append (check )
910+ elif checks [check ] != 'SUCCESS' :
911+ failed_checks .append (check )
912+ if len (failed_checks ) > 0 :
913+ raise RuntimeError (f"Failed to merge due to failing checks, { ',' .join (failed_checks )} " )
914+ if len (pending_checks ) > 0 :
915+ reject_reason = f"Refusing to merge as mandatory check(s) { ',' .join (pending_checks )} are missing"
916+ raise MandatoryChecksMissingError (reject_reason )
917+ pr .merge_into (repo , dry_run = dry_run )
918+ else :
919+ pr .merge_into (repo , dry_run = dry_run )
904920 except MandatoryChecksMissingError as ex :
905921 last_exception = str (ex )
906922 print (f"Merged failed due to: { ex } . Retrying in 60 seconds." )
@@ -942,9 +958,9 @@ def handle_exception(e: Exception, msg: str = "Merge failed") -> None:
942958 gh_post_comment (org , project , args .pr_num , "Cross-repo ghstack merges are not supported" , dry_run = args .dry_run )
943959 return
944960
945- if args .on_green :
961+ if args .on_green or args . _all_green :
946962 try :
947- merge_on_green (args .pr_num , repo , dry_run = args .dry_run )
963+ merge_on_green (args .pr_num , repo , dry_run = args .dry_run , all_green = args . all_green )
948964 except Exception as e :
949965 handle_exception (e )
950966 else :
0 commit comments