99from .next_version import next_version
1010from .url_exists import url_exists
1111from .hash_url import hash_url
12- from ..git_utils import bot_github_user_ctx , git_branch_ctx , make_pr_for_recipe , automerge_is_enabled ,set_bot_user
12+ from ..git_utils import bot_github_user_ctx , git_branch_ctx , make_pr_for_recipe , automerge_is_enabled ,set_bot_user , get_current_branch_name
1313import sys
1414import json
1515
@@ -226,7 +226,7 @@ def user_ctx(user, email, bypass=False):
226226 subprocess .check_output (['git' , 'config' , '--unset' , 'user.email' ])
227227
228228
229- def bump_recipe_versions (recipe_dir , use_bot = True , pr_limit = 10 ):
229+ def bump_recipe_versions (recipe_dir , pr_target_branch , use_bot = True , pr_limit = 1 ):
230230
231231 # empty context manager
232232 @contextlib .contextmanager
@@ -249,11 +249,17 @@ def empty_context_manager():
249249
250250 # get all opened PRs
251251 with user_ctx ():
252+
253+ current_branch_name = get_current_branch_name ()
254+ if current_branch_name == pr_target_branch :
255+ print (f"Already on target branch { pr_target_branch } " )
256+ else :
257+ print (f"swichting from { current_branch_name } to { pr_target_branch } " )
258+ # switch to the target branch
259+ subprocess .run (['git' , 'stash' ], check = False )
260+ subprocess .check_output (['git' , 'checkout' , pr_target_branch ])
252261
253- # get current branch name
254- current_branch_name = subprocess .check_output (['git' , 'rev-parse' , '--abbrev-ref' , 'HEAD' ]).decode ('utf-8' ).strip ()
255-
256- print (f"Current branch name: { current_branch_name } " )
262+ assert get_current_branch_name () == pr_target_branch
257263
258264 # Check for opened PRs and merge them if the CI passed
259265 print ("Checking opened PRs and merge them if green!" )
@@ -265,13 +271,13 @@ def empty_context_manager():
265271 if not pr_line :
266272 continue
267273 pr_id = pr_line .split ()[0 ]
268- target_branch_name = subprocess .check_output (
274+ that_pr_target_branch = subprocess .check_output (
269275 ['gh' , 'pr' , 'view' , pr_id , '--json' , 'baseRefName' , '-q' , '.baseRefName' ]
270276 ).decode ('utf-8' ).strip ()
271- if target_branch_name == current_branch_name :
277+ if that_pr_target_branch == pr_target_branch :
272278 prs .append (pr_line )
273279 else :
274- print (f"skip PR { pr_id } [ current branch { current_branch_name } but PR is for { target_branch_name } ] " )
280+ print (f"PR { pr_id } is not targeting { pr_target_branch } [ but { that_pr_target_branch } ], skipping it " )
275281
276282 all_recipes = [recipe for recipe in Path (recipe_dir ).iterdir () if recipe .is_dir ()]
277283 # map from folder names to recipe-dir
0 commit comments