in merge_spark_docker_pr.py [0:0]
def main():
global original_head
os.chdir(SPARK_DOCKER_HOME)
original_head = get_current_ref()
# Check this up front to avoid failing the JIRA update at the very end
if not JIRA_USERNAME or not JIRA_PASSWORD:
continue_maybe("The env-vars JIRA_USERNAME and/or JIRA_PASSWORD are not set. Continue?")
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))
pr_events = get_json("%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 = 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"]
modified_body = re.sub(re.compile(r"<!--[^>]*-->\n?", re.DOTALL), "", pr["body"]).lstrip()
if modified_body != pr["body"]:
print("=" * 80)
print(modified_body)
print("=" * 80)
print("I've removed the comments from PR template like the above:")
result = input("Would you like to use the modified body? (y/n): ")
if result.lower() == "y":
body = modified_body
print("Using modified body:")
else:
body = pr["body"]
print("Using original body:")
print("=" * 80)
print(body)
print("=" * 80)
else:
body = pr["body"]
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"]):
msg = (
"Pull request %s is not mergeable in its current form.\n" % pr_num
+ "Continue? (experts only!)"
)
continue_maybe(msg)
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_pr(pr_num, target_ref, title, body, pr_repo_desc)
if JIRA_IMPORTED:
if JIRA_USERNAME and JIRA_PASSWORD:
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("JIRA_USERNAME and JIRA_PASSWORD not set")
print("Exiting without trying to close the associated JIRA.")
else:
print("Could not find jira-python library. Run 'sudo pip3 install jira' to install.")
print("Exiting without trying to close the associated JIRA.")