This is an automated email from the ASF dual-hosted git repository.
leesf pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-livy.git
The following commit(s) were added to refs/heads/master by this push:
new 8b2e29fe [DEV] Support python3 for merge_livy_pr script (#418)
8b2e29fe is described below
commit 8b2e29fe9fd42c20395c63e1571f2492f005162b
Author: Marco Gaido <[email protected]>
AuthorDate: Thu Sep 7 15:56:45 2023 +0200
[DEV] Support python3 for merge_livy_pr script (#418)
---
dev/merge_livy_pr.py | 38 ++++++++++++++++++++++++++------------
1 file changed, 26 insertions(+), 12 deletions(-)
diff --git a/dev/merge_livy_pr.py b/dev/merge_livy_pr.py
index 741ec2ee..85ce7417 100755
--- a/dev/merge_livy_pr.py
+++ b/dev/merge_livy_pr.py
@@ -39,7 +39,15 @@ import os
import re
import subprocess
import sys
-import urllib2
+
+if sys.version_info[0] < 3:
+ import urllib2
+ from urllib2 import HTTPError
+ input_prompt_fn = raw_input
+else:
+ import urllib.request as urllib2
+ from urllib.error import HTTPError
+ input_prompt_fn = input
try:
import jira.client
@@ -78,7 +86,7 @@ def get_json(url):
if GITHUB_OAUTH_KEY:
request.add_header('Authorization', 'token %s' % GITHUB_OAUTH_KEY)
return json.load(urllib2.urlopen(request))
- except urllib2.HTTPError as e:
+ 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_livy_pr.py to configure an OAuth token for making
authenticated " +
@@ -97,13 +105,17 @@ def fail(msg):
def run_cmd(cmd):
print(cmd)
if isinstance(cmd, list):
- return subprocess.check_output(cmd)
+ out_bytes = subprocess.check_output(cmd)
+ else:
+ out_bytes = subprocess.check_output(cmd.split(" "))
+ if sys.version_info[0] > 2:
+ return out_bytes.decode()
else:
- return subprocess.check_output(cmd.split(" "))
+ return out_bytes
def continue_maybe(prompt):
- result = raw_input("\n%s (y/n): " % prompt)
+ result = input_prompt_fn("\n%s (y/n): " % prompt)
if result.lower() != "y":
fail("Okay, exiting")
@@ -141,7 +153,7 @@ def merge_pr(pr_num, target_ref, title, body, pr_repo_desc):
'--pretty=format:%an <%ae>']).split("\n")
distinct_authors = sorted(set(commit_authors),
key=lambda x: commit_authors.count(x),
reverse=True)
- primary_author = raw_input(
+ primary_author = input_prompt_fn(
"Enter primary author in the format of \"name <email>\" [%s]: " %
distinct_authors[0])
if primary_author == "":
@@ -191,7 +203,7 @@ def merge_pr(pr_num, target_ref, title, body, pr_repo_desc):
def cherry_pick(pr_num, merge_hash, default_branch):
- pick_ref = raw_input("Enter a branch name [%s]: " % default_branch)
+ pick_ref = input_prompt_fn("Enter a branch name [%s]: " % default_branch)
if pick_ref == "":
pick_ref = default_branch
@@ -238,7 +250,7 @@ def resolve_jira_issue(merge_branches, comment,
default_jira_id=""):
asf_jira = jira.client.JIRA({'server': JIRA_API_BASE},
basic_auth=(JIRA_USERNAME, JIRA_PASSWORD))
- jira_id = raw_input("Enter a JIRA id [%s]: " % default_jira_id)
+ jira_id = input_prompt_fn("Enter a JIRA id [%s]: " % default_jira_id)
if jira_id == "":
jira_id = default_jira_id
@@ -280,7 +292,8 @@ def resolve_jira_issue(merge_branches, comment,
default_jira_id=""):
default_fix_versions = filter(lambda x: x != v,
default_fix_versions)
default_fix_versions = ",".join(default_fix_versions)
- fix_versions = raw_input("Enter comma-separated fix version(s) [%s]: " %
default_fix_versions)
+ fix_versions = input_prompt_fn(
+ "Enter comma-separated fix version(s) [%s]: " % default_fix_versions)
if fix_versions == "":
fix_versions = default_fix_versions
fix_versions = fix_versions.replace(" ", "").split(",")
@@ -370,7 +383,7 @@ def main():
# Assumes branch names can be sorted lexicographically
latest_branch = sorted(branch_names, reverse=True)[0]
- pr_num = raw_input("Which pull request would you like to merge? (e.g. 34):
")
+ pr_num = input_prompt_fn("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))
@@ -382,7 +395,7 @@ def main():
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 = raw_input("Would you like to use the modified title? (y/n): ")
+ result = input_prompt_fn("Would you like to use the modified title?
(y/n): ")
if result.lower() == "y":
title = modified_title
print("Using modified title:")
@@ -433,7 +446,7 @@ def main():
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 raw_input("\n%s (y/n): " % pick_prompt).lower() == "y":
+ while input_prompt_fn("\n%s (y/n): " % pick_prompt).lower() == "y":
merged_refs = merged_refs + [cherry_pick(pr_num, merge_hash,
latest_branch)]
if JIRA_IMPORTED:
@@ -449,6 +462,7 @@ def main():
print("Could not find jira-python library. Run 'sudo pip install jira'
to install.")
print("Exiting without trying to close the associated JIRA.")
+
if __name__ == "__main__":
import doctest
(failure_count, test_count) = doctest.testmod()