@@ -1151,7 +1151,7 @@ def merge_into(
1151
1151
* ,
1152
1152
skip_mandatory_checks : bool = False ,
1153
1153
dry_run : bool = False ,
1154
- comment_id : Optional [ int ] = None ,
1154
+ comment_id : int ,
1155
1155
ignore_current_checks : Optional [list [str ]] = None ,
1156
1156
) -> None :
1157
1157
# Raises exception if matching rule is not found
@@ -1231,29 +1231,29 @@ def merge_changes(
1231
1231
branch_to_merge_into = self .default_branch () if branch is None else branch
1232
1232
if repo .current_branch () != branch_to_merge_into :
1233
1233
repo .checkout (branch_to_merge_into )
1234
- if not self .is_ghstack_pr ():
1235
- msg = self .gen_commit_message ()
1236
- pr_branch_name = f"__pull-request-{ self .pr_num } __init__"
1237
- repo .fetch (self .last_commit ()["oid" ], pr_branch_name )
1238
- repo ._run_git ("merge" , "--squash" , pr_branch_name )
1239
- repo ._run_git ("commit" , f'--author="{ self .get_author ()} "' , "-m" , msg )
1240
-
1241
- # Did the PR change since we started the merge?
1242
- pulled_sha = repo .show_ref (pr_branch_name )
1243
- latest_pr_status = GitHubPR (self .org , self .project , self .pr_num )
1244
- if pulled_sha != latest_pr_status .last_commit ()["oid" ]:
1245
- raise RuntimeError (
1246
- "PR has been updated since CI checks last passed. Please rerun the merge command."
1247
- )
1248
- return []
1249
- else :
1234
+ if self .is_ghstack_pr ():
1250
1235
return self .merge_ghstack_into (
1251
1236
repo ,
1252
1237
skip_mandatory_checks ,
1253
1238
comment_id = comment_id ,
1254
1239
skip_all_rule_checks = skip_all_rule_checks ,
1255
1240
)
1256
1241
1242
+ msg = self .gen_commit_message ()
1243
+ pr_branch_name = f"__pull-request-{ self .pr_num } __init__"
1244
+ repo .fetch (self .last_commit ()["oid" ], pr_branch_name )
1245
+ repo ._run_git ("merge" , "--squash" , pr_branch_name )
1246
+ repo ._run_git ("commit" , f'--author="{ self .get_author ()} "' , "-m" , msg )
1247
+
1248
+ # Did the PR change since we started the merge?
1249
+ pulled_sha = repo .show_ref (pr_branch_name )
1250
+ latest_pr_status = GitHubPR (self .org , self .project , self .pr_num )
1251
+ if pulled_sha != latest_pr_status .last_commit ()["oid" ]:
1252
+ raise RuntimeError (
1253
+ "PR has been updated since CI checks last passed. Please rerun the merge command."
1254
+ )
1255
+ return []
1256
+
1257
1257
1258
1258
class MergeRuleFailedError (RuntimeError ):
1259
1259
def __init__ (self , message : str , rule : Optional ["MergeRule" ] = None ) -> None :
@@ -2156,9 +2156,9 @@ def categorize_checks(
2156
2156
def merge (
2157
2157
pr : GitHubPR ,
2158
2158
repo : GitRepo ,
2159
+ comment_id : int ,
2159
2160
dry_run : bool = False ,
2160
2161
skip_mandatory_checks : bool = False ,
2161
- comment_id : Optional [int ] = None ,
2162
2162
timeout_minutes : int = 400 ,
2163
2163
stale_pr_days : int = 3 ,
2164
2164
ignore_current : bool = False ,
@@ -2416,12 +2416,18 @@ def handle_exception(e: Exception, title: str = "Merge failed") -> None:
2416
2416
gh_post_pr_comment (org , project , args .pr_num , message , dry_run = args .dry_run )
2417
2417
return
2418
2418
try :
2419
+ # Ensure comment id is set, else fail
2420
+ if not args .comment_id :
2421
+ raise ValueError (
2422
+ "Comment ID is required for merging PRs, please provide it using --comment-id"
2423
+ )
2424
+
2419
2425
merge (
2420
2426
pr ,
2421
2427
repo ,
2428
+ comment_id = args .comment_id ,
2422
2429
dry_run = args .dry_run ,
2423
2430
skip_mandatory_checks = args .force ,
2424
- comment_id = args .comment_id ,
2425
2431
ignore_current = args .ignore_current ,
2426
2432
)
2427
2433
except Exception as e :
0 commit comments