302302"""
303303
304304RE_GHSTACK_HEAD_REF = re .compile (r"^(gh/[^/]+/[0-9]+/)head$" )
305- RE_GHSTACK_SOURCE_ID = re .compile (r'^ghstack-source-id: (.+)\n? ' , re .MULTILINE )
305+ RE_GHSTACK_DESC = re .compile (r'Stack.*:\r?\n(\* [^\r\n]+\r?\n)+ ' , re .MULTILINE )
306306RE_PULL_REQUEST_RESOLVED = re .compile (
307307 r'Pull Request resolved: '
308308 r'https://github.com/(?P<owner>[^/]+)/(?P<repo>[^/]+)/pull/(?P<number>[0-9]+)' ,
@@ -564,8 +564,11 @@ def add_conclusions(edges: List[Dict[str, Dict[str, Any]]]) -> None:
564564 checkruns = node ["checkRuns" ]
565565 if workflow_run is not None :
566566 conclusions [workflow_run ["workflow" ]["name" ]] = (node ["conclusion" ], node ["url" ])
567+ has_failing_check = False
567568 while checkruns is not None :
568569 for checkrun_node in checkruns ["nodes" ]:
570+ if checkrun_node ["conclusion" ] == 'FAILURE' :
571+ has_failing_check = True
569572 conclusions [checkrun_node ["name" ]] = (checkrun_node ["conclusion" ], checkrun_node ["detailsUrl" ])
570573 if bool (checkruns ["pageInfo" ]["hasNextPage" ]):
571574 rc = gh_graphql (GH_GET_PR_NEXT_CHECK_RUNS ,
@@ -578,6 +581,9 @@ def add_conclusions(edges: List[Dict[str, Dict[str, Any]]]) -> None:
578581 checkruns = last_commit ["checkSuites" ]["nodes" ][- 1 ]["checkRuns" ]
579582 else :
580583 checkruns = None
584+ # Github doesn't set conclusion to failure if a job is still pending
585+ if workflow_run is not None and has_failing_check :
586+ conclusions [workflow_run ["workflow" ]["name" ]] = ("FAILURE" , node ["url" ])
581587
582588 add_conclusions (checksuites ["edges" ])
583589 while bool (checksuites ["pageInfo" ]["hasNextPage" ]):
@@ -702,33 +708,38 @@ def merge_ghstack_into(self, repo: GitRepo, force: bool, comment_id: Optional[in
702708 if self .org != m .group ('owner' ) or self .project != m .group ('repo' ):
703709 raise RuntimeError (f"PR { m .group ('number' )} resolved to wrong owner/repo pair" )
704710 pr_num = int (m .group ('number' ))
711+ commit_msg = self .gen_commit_message (filter_ghstack = True )
705712 if pr_num != self .pr_num :
706713 pr = GitHubPR (self .org , self .project , pr_num )
707714 if pr .is_closed ():
708715 print (f"Skipping { idx + 1 } of { len (rev_list )} PR (#{ pr_num } ) as its already been merged" )
709716 continue
710- approved_by = pr .get_approved_by ( )
717+ commit_msg = pr .gen_commit_message ( filter_ghstack = True )
711718 # Raises exception if matching rule is not found
712719 find_matching_merge_rule (pr , repo , force = force , skip_internal_checks = can_skip_internal_checks (self , comment_id ))
713720
714- # Adding the url here makes it clickable within the Github UI
715- approved_by_urls = ', ' .join (prefix_with_github_url (login ) for login in approved_by )
716721 repo .cherry_pick (rev )
717- msg = re .sub (RE_GHSTACK_SOURCE_ID , "" , msg )
718- msg += f"\n Approved by: { approved_by_urls } \n "
719- repo .amend_commit_message (msg )
722+ repo .amend_commit_message (commit_msg )
723+
724+ def gen_commit_message (self , filter_ghstack : bool = False ) -> str :
725+ """ Fetches title and body from PR description
726+ adds reviewed by, pull request resolved and optionally
727+ filters out ghstack info """
728+ # Adding the url here makes it clickable within the Github UI
729+ approved_by_urls = ', ' .join (prefix_with_github_url (login ) for login in self .get_approved_by ())
730+ msg = self .get_title () + f" (#{ self .pr_num } )\n \n "
731+ msg += self .get_body () if not filter_ghstack else re .sub (RE_GHSTACK_DESC , "" , self .get_body ())
732+ msg += f"\n Pull Request resolved: { self .get_pr_url ()} \n "
733+ msg += f"Approved by: { approved_by_urls } \n "
734+ return msg
720735
721736 def merge_into (self , repo : GitRepo , * , force : bool = False , dry_run : bool = False , comment_id : Optional [int ] = None ) -> None :
722737 # Raises exception if matching rule is not found
723738 find_matching_merge_rule (self , repo , force = force , skip_internal_checks = can_skip_internal_checks (self , comment_id ))
724739 if repo .current_branch () != self .default_branch ():
725740 repo .checkout (self .default_branch ())
726741 if not self .is_ghstack_pr ():
727- # Adding the url here makes it clickable within the Github UI
728- approved_by_urls = ', ' .join (prefix_with_github_url (login ) for login in self .get_approved_by ())
729- msg = self .get_title () + f" (#{ self .pr_num } )\n \n " + self .get_body ()
730- msg += f"\n Pull Request resolved: { self .get_pr_url ()} \n "
731- msg += f"Approved by: { approved_by_urls } \n "
742+ msg = self .gen_commit_message ()
732743 pr_branch_name = f"__pull-request-{ self .pr_num } __init__"
733744 repo .fetch (f"pull/{ self .pr_num } /head" , pr_branch_name )
734745 repo ._run_git ("merge" , "--squash" , pr_branch_name )
0 commit comments