in dev/merge_zeppelin_pr.py [0:0]
def main():
initialize_jira()
global original_head
os.chdir(ZEPPELIN_HOME)
original_head = get_current_ref()
branches = http_get("%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, key=lambda x: list(map(int, x.removeprefix("branch-").split('.'))), reverse=True)
branch_iter = iter(branch_names)
pr_num = bold_input("Which pull request would you like to merge? (e.g. 34): ")
pr = http_get("%s/pulls/%s" % (GITHUB_API_BASE, pr_num))
pr_events = http_get("%s/issues/%s/events" % (GITHUB_API_BASE, pr_num))
url = pr["url"]
# Warn if the PR is WIP
if "[WIP]" in pr["title"]:
msg = "The PR title has `[WIP]`:\n%s\nContinue?" % pr["title"]
continue_maybe(msg)
# Decide whether to use the modified title or not
modified_title = standardize_jira_ref(pr["title"]).rstrip(".")
if modified_title != pr["title"]:
print("I've re-written the title as follows to match the standard format:")
print("Original: %s" % pr["title"])
print("Modified: %s" % modified_title)
result = bold_input("Would you like to use the modified title? (y/N): ")
if result.lower() == "y":
title = modified_title
print("Using modified title:")
else:
title = pr["title"]
print("Using original title:")
print(title)
else:
title = pr["title"]
body = pr["body"]
if body is None:
body = ""
modified_body = re.sub(re.compile(r"<!--[^>]*-->\n?", re.DOTALL), "", body).lstrip()
if modified_body != body:
print("=" * 80)
print(modified_body)
print("=" * 80)
print("I've removed the comments from PR template like the above:")
result = bold_input("Would you like to use the modified body? (y/N): ")
if result.lower() == "y":
body = modified_body
print("Using modified body:")
else:
print("Using original body:")
print("=" * 80)
print(body)
print("=" * 80)
target_ref = pr["base"]["ref"]
user_login = pr["user"]["login"]
base_ref = pr["head"]["ref"]
pr_repo_desc = "%s/%s" % (user_login, base_ref)
if not bool(pr["mergeable"]):
fail("Pull request %s is not mergeable in its current form." % pr_num)
if asf_jira is not None:
jira_ids = re.findall("ZEPPELIN-[0-9]{3,6}", title)
for jira_id in jira_ids:
try:
print_jira_issue_summary(asf_jira.issue(jira_id))
except Exception:
print_error("Unable to fetch summary of %s" % jira_id)
print("\n=== Pull Request #%s ===" % pr_num)
print("title\t%s\nsource\t%s\ntarget\t%s\nurl\t%s" % (title, pr_repo_desc, target_ref, url))
continue_maybe("Proceed with merging pull request #%s?" % pr_num)
merged_refs = [target_ref]
merge_hash = merge_pr(pr_num, target_ref, title, body, pr_repo_desc)
pick_prompt = "Would you like to pick %s into another branch?" % merge_hash
while bold_input("\n%s (y/N): " % pick_prompt).lower() == "y":
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?")
jira_comment = "Issue resolved by pull request %s\n[%s/%s]" % (
pr_num,
GITHUB_BASE,
pr_num,
)
resolve_jira_issues(title, merged_refs, jira_comment)
else:
print("Exiting without trying to close the associated JIRA.")