From eb2d7f5f75476c9ce2c307890c1363d9d21f61fb Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Tue, 29 Aug 2023 21:34:55 -0700 Subject: [PATCH] [SPARK-45008][INFRA] Improve branch suggestion for backporting ### What changes were proposed in this pull request? This PR automatically iterates to the next branch to be merged instead of using the latest all the time ### Why are the changes needed? anti-misoperation ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? ### Was this patch authored or co-authored using generative AI tooling? Locally tested ```python >>> def get_json(url): ... try: ... request = Request(url) ... if GITHUB_OAUTH_KEY: ... request.add_header("Authorization", "token %s" % GITHUB_OAUTH_KEY) ... return json.load(urlopen(request)) ... except HTTPError as e: ... if "X-RateLimit-Remaining" in e.headers and e.headers["X-RateLimit-Remaining"] == "0": ... print( ... "Exceeded the GitHub API rate limit; see the instructions in " ... + "dev/merge_spark_pr.py to configure an OAuth token for making authenticated " ... + "GitHub requests." ... ) ... else: ... print("Unable to fetch URL, exiting: %s" % url) ... sys.exit(-1) ... >>> branches = get_json("%s/branches" % GITHUB_API_BASE) >>> >>> branch_names = list(filter(lambda x: x.startswith("branch-"), [x["name"] for x in branches])) >>> branch_names = sorted(branch_names, reverse=True) >>> branch_iter = iter(branch_names) >>> print(next(branch_iter, branch_names[0])) branch-3.5 >>> print(next(branch_iter, branch_names[0])) branch-3.4 >>> print(next(branch_iter, branch_names[0])) branch-3.3 >>> print(next(branch_iter, branch_names[0])) branch-3.2 >>> print(next(branch_iter, branch_names[0])) branch-3.1 >>> print(next(branch_iter, branch_names[0])) branch-3.0 >>> print(next(branch_iter, branch_names[0])) branch-2.4 >>> print(next(branch_iter, branch_names[0])) branch-2.3 >>> print(next(branch_iter, branch_names[0])) branch-2.2 >>> print(next(branch_iter, branch_names[0])) branch-2.1 >>> print(next(branch_iter, branch_names[0])) branch-2.0 >>> print(next(branch_iter, branch_names[0])) branch-1.6 >>> print(next(branch_iter, branch_names[0])) branch-1.5 >>> print(next(branch_iter, branch_names[0])) branch-1.4 >>> print(next(branch_iter, branch_names[0])) branch-1.3 >>> print(next(branch_iter, branch_names[0])) branch-1.2 >>> print(next(branch_iter, branch_names[0])) branch-1.1 >>> print(next(branch_iter, branch_names[0])) branch-1.0-jdbc >>> print(next(branch_iter, branch_names[0])) branch-1.0 >>> print(next(branch_iter, branch_names[0])) branch-0.9 >>> print(next(branch_iter, branch_names[0])) branch-0.8 >>> print(next(branch_iter, branch_names[0])) branch-0.7 >>> print(next(branch_iter, branch_names[0])) branch-0.6 >>> print(next(branch_iter, branch_names[0])) branch-0.5 >>> print(next(branch_iter, branch_names[0])) branch-3.5 >>> quit() ``` Closes #42723 from yaooqinn/SPARK-45008. Authored-by: Kent Yao Signed-off-by: Dongjoon Hyun --- dev/merge_spark_pr.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dev/merge_spark_pr.py b/dev/merge_spark_pr.py index adda74b3f4844..23f5af7dacac8 100755 --- a/dev/merge_spark_pr.py +++ b/dev/merge_spark_pr.py @@ -557,7 +557,8 @@ def main(): branches = get_json("%s/branches" % GITHUB_API_BASE) branch_names = list(filter(lambda x: x.startswith("branch-"), [x["name"] for x in branches])) # Assumes branch names can be sorted lexicographically - latest_branch = sorted(branch_names, reverse=True)[0] + branch_names = sorted(branch_names, reverse=True) + branch_iter = iter(branch_names) pr_num = input("Which pull request would you like to merge? (e.g. 34): ") pr = get_json("%s/pulls/%s" % (GITHUB_API_BASE, pr_num)) @@ -627,7 +628,7 @@ def main(): fail("Couldn't find any merge commit for #%s, you may need to update HEAD." % pr_num) print("Found commit %s:\n%s" % (merge_hash, message)) - cherry_pick(pr_num, merge_hash, latest_branch) + cherry_pick(pr_num, merge_hash, next(branch_iter, branch_names[0])) sys.exit(0) if not bool(pr["mergeable"]): @@ -647,7 +648,9 @@ def main(): pick_prompt = "Would you like to pick %s into another branch?" % merge_hash while input("\n%s (y/n): " % pick_prompt).lower() == "y": - merged_refs = merged_refs + [cherry_pick(pr_num, merge_hash, latest_branch)] + merged_refs = merged_refs + [ + cherry_pick(pr_num, merge_hash, next(branch_iter, branch_names[0])) + ] if asf_jira is not None: continue_maybe("Would you like to update an associated JIRA?")