Skip to content

Commit 88bed54

Browse files
jorisvandenbosschejreback
authored andcommitted
BLD: update merge script to update on github (#15917)
* BLD: update merge script to update on github * adapt question
1 parent d9e00d2 commit 88bed54

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

scripts/merge-py.py renamed to scripts/merge-pr.py

+53-2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ def continue_maybe(prompt):
9999
fail("Okay, exiting")
100100

101101

102+
def continue_maybe2(prompt):
103+
result = input("\n%s (y/n): " % prompt)
104+
if result.lower() != "y":
105+
return False
106+
else:
107+
return True
108+
109+
102110
original_head = run_cmd("git rev-parse HEAD")[:8]
103111

104112

@@ -193,6 +201,40 @@ def merge_pr(pr_num, target_ref):
193201
return merge_hash
194202

195203

204+
def update_pr(pr_num, user_login, base_ref):
205+
206+
pr_branch_name = "%s_MERGE_PR_%s" % (BRANCH_PREFIX, pr_num)
207+
208+
run_cmd("git fetch %s pull/%s/head:%s" % (PR_REMOTE_NAME, pr_num,
209+
pr_branch_name))
210+
run_cmd("git checkout %s" % pr_branch_name)
211+
212+
continue_maybe("Update ready (local ref %s)? Push to %s/%s?" % (
213+
pr_branch_name, user_login, base_ref))
214+
215+
push_user_remote = "https://github.com/%s/pandas.git" % user_login
216+
217+
try:
218+
run_cmd('git push %s %s:%s' % (push_user_remote, pr_branch_name,
219+
base_ref))
220+
except Exception as e:
221+
222+
if continue_maybe2("Force push?"):
223+
try:
224+
run_cmd(
225+
'git push -f %s %s:%s' % (push_user_remote, pr_branch_name,
226+
base_ref))
227+
except Exception as e:
228+
fail("Exception while pushing: %s" % e)
229+
clean_up()
230+
else:
231+
fail("Exception while pushing: %s" % e)
232+
clean_up()
233+
234+
clean_up()
235+
print("Pull request #%s updated!" % pr_num)
236+
237+
196238
def cherry_pick(pr_num, merge_hash, default_branch):
197239
pick_ref = input("Enter a branch name [%s]: " % default_branch)
198240
if pick_ref == "":
@@ -257,8 +299,17 @@ def fix_version_from_branch(branch, versions):
257299
print("\n=== Pull Request #%s ===" % pr_num)
258300
print("title\t%s\nsource\t%s\ntarget\t%s\nurl\t%s"
259301
% (title, pr_repo_desc, target_ref, url))
260-
continue_maybe("Proceed with merging pull request #%s?" % pr_num)
302+
303+
261304

262305
merged_refs = [target_ref]
263306

264-
merge_hash = merge_pr(pr_num, target_ref)
307+
print("\nProceed with updating or merging pull request #%s?" % pr_num)
308+
update = input("Update PR and push to remote (r), merge locally (l), "
309+
"or do nothing (n) ?")
310+
update = update.lower()
311+
312+
if update == 'r':
313+
merge_hash = update_pr(pr_num, user_login, base_ref)
314+
elif update == 'l':
315+
merge_hash = merge_pr(pr_num, target_ref)

0 commit comments

Comments
 (0)