This is an automated email from the ASF dual-hosted git repository.

sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new e04c791  [DEV] make merge script work with python 3
e04c791 is described below

commit e04c791499e51f2d5b4f288c5f349777103c555d
Author: Sijie Guo <[email protected]>
AuthorDate: Fri Sep 14 10:33:17 2018 -0700

    [DEV] make merge script work with python 3
    
    Descriptions of the changes in this PR:
    
    ### Motivation
    
    make sure the script works for python 3 as well.
    
    ### Changes
    
    since python2 and python3 have different syntax and library, make a copy of 
the merge script for python3.
    
    
    
    
    Author:
    
    Reviewers: Enrico Olivelli <[email protected]>
    
    This closes #1677 from sijie/make_merge_script_works_for_37
---
 dev/bk-merge-pr.py                      | 114 +++++++++----------
 dev/{bk-merge-pr.py => bk-merge-pr3.py} | 193 ++++++++++++++++----------------
 2 files changed, 154 insertions(+), 153 deletions(-)

diff --git a/dev/bk-merge-pr.py b/dev/bk-merge-pr.py
index 2c69890..4dec84d 100755
--- a/dev/bk-merge-pr.py
+++ b/dev/bk-merge-pr.py
@@ -69,11 +69,11 @@ def get_json(url, preview_api = False):
         return json.load(urllib2.urlopen(request))
     except urllib2.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 
" + \
+            print("Exceeded the GitHub API rate limit; see the instructions in 
" + \
                   "bk-merge-pr.py to configure an OAuth token for making 
authenticated " + \
-                  "GitHub requests."
+                  "GitHub requests.")
         else:
-            print "Unable to fetch URL, exiting: %s" % url
+            print("Unable to fetch URL, exiting: %s" % url)
         sys.exit(-1)
 
 def post_json(url, data):
@@ -83,11 +83,11 @@ def post_json(url, data):
         return json.load(urllib2.urlopen(request))
     except urllib2.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 
" + \
+            print("Exceeded the GitHub API rate limit; see the instructions in 
" + \
                   "bk-merge-pr.py to configure an OAuth token for making 
authenticated " + \
-                  "GitHub requests."
+                  "GitHub requests.")
         else:
-            print "Unable to fetch URL, exiting: %s - %s" % (url, e)
+            print("Unable to fetch URL, exiting: %s - %s" % (url, e))
         sys.exit(-1)
 
 def put_json(url, data):
@@ -98,23 +98,23 @@ def put_json(url, data):
         return json.load(urllib2.urlopen(request))
     except urllib2.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 
" + \
+            print("Exceeded the GitHub API rate limit; see the instructions in 
" + \
                   "bk-merge-pr.py to configure an OAuth token for making 
authenticated " + \
-                  "GitHub requests."
+                  "GitHub requests.")
         else:
-            print "Unable to fetch URL, exiting: %s - %s" % (url, e)
-            print e
+            print("Unable to fetch URL, exiting: %s - %s" % (url, e))
+            print(e)
         sys.exit(-1)
 
 
 def fail(msg):
-    print msg
+    print(msg)
     clean_up()
     sys.exit(-1)
 
 
 def run_cmd(cmd):
-    print cmd
+    print(cmd)
     if isinstance(cmd, list):
         return subprocess.check_output(cmd)
     else:
@@ -128,13 +128,13 @@ def continue_maybe(prompt):
 
 def clean_up():
     if original_head != get_current_branch():
-        print "Restoring head pointer to %s" % original_head
+        print("Restoring head pointer to %s" % original_head)
         run_cmd("git checkout %s" % original_head)
 
     branches = run_cmd("git branch").replace(" ", "").split("\n")
 
     for branch in filter(lambda x: x.startswith(TEMP_BRANCH_PREFIX), branches):
-        print "Deleting local branch %s" % branch
+        print("Deleting local branch %s" % branch)
         run_cmd("git branch -D %s" % branch)
 
 def get_current_branch():
@@ -369,9 +369,9 @@ def check_ci_status(pr):
         comments = get_json(pr["comments_url"])
         ignore_ci_comments = [c for c in comments if c["body"].upper() == 
"IGNORE CI"]
         if len(ignore_ci_comments) > 0:
-            print "\n\nWARNING: The PR has not passed CI (state is %s)" % 
(state) \
+            print("\n\nWARNING: The PR has not passed CI (state is %s)" % 
(state) \
                 + ", but this has been overridden by %s. \n" % 
(ignore_ci_comments[0]["user"]["login"]) \
-                + "Proceed at your own peril!\n\n"
+                + "Proceed at your own peril!\n\n")
         else:
             check_individual_ci_status(ci_status, comments)
 
@@ -411,14 +411,14 @@ def check_individual_ci_status(ci_status, comments):
         # all ci passed except integration tests
         ignore_it_ci_comments = [c for c in comments if c["body"].upper() == 
"IGNORE IT CI"]
         if len(ignore_it_ci_comments) > 0:
-            print "\n\nWARNING: The PR has not passed integration tests CI" \
+            print("\n\nWARNING: The PR has not passed integration tests CI" \
                 + ", but this has been overridden by %s. \n" % 
(ignore_it_ci_comments[0]["user"]["login"]) \
-                + "Proceed at your own peril!\n\n"
+                + "Proceed at your own peril!\n\n")
         else:
             fail("The PR has not passed integration tests CI")
     elif len(ci_failures) != 0 or len(ci_integration_test_failures) != 0:
         fail_msg = "The PR has not passed CI:\n"
-        print ""
+        print("")
         for status in ci_failures:
             fail_msg += "\t %s = %s\n" % (status["context"], status["state"])
         for status in ci_integration_test_failures:
@@ -426,16 +426,16 @@ def check_individual_ci_status(ci_status, comments):
         fail(fail_msg)
 
 def ask_release_for_github_issues(branch, labels):
-    print "=== Add release to github issues ==="
+    print("=== Add release to github issues ===")
     while True:
         fix_releases = ask_for_labels("release/%s" % branch, labels, [])
         if len(fix_releases) != 1:
-            print "Please choose only one release to add for branch '%s'." % 
branch
+            print("Please choose only one release to add for branch '%s'." % 
branch)
             continue
 
-        print "=== Apply following releases to github issues ==" 
-        print "Fix Releases: %s" % ', '.join(fix_releases)
-        print ""
+        print("=== Apply following releases to github issues ==")
+        print("Fix Releases: %s" % ', '.join(fix_releases))
+        print("")
 
         if raw_input("Would you like to add these releases to github issues? 
(y/n): ") == "y":
             break
@@ -446,12 +446,12 @@ def ask_updates_for_github_issues(milestones, labels, 
issue_labels, milestone_re
         fix_milestone, fix_milestone_number, fix_areas, fix_types = \
             get_updates_for_github_issues(milestones, labels, issue_labels, 
milestone_required)
 
-        print "=== Apply following milestone, area, type to github issues ==" 
-        print "Fix Types: %s" % ', '.join(fix_types)
-        print "Fix Areas: %s" % ', '.join(fix_areas)
+        print("=== Apply following milestone, area, type to github issues ==")
+        print("Fix Types: %s" % ', '.join(fix_types))
+        print("Fix Areas: %s" % ', '.join(fix_areas))
         if milestone_required:
-            print "Fix Milestone: %s" % fix_milestone
-        print ""
+            print("Fix Milestone: %s" % fix_milestone)
+        print("")
 
         if raw_input("Would you like to update github issues with these 
labels? (y/n): ") == "y":
             break
@@ -475,7 +475,7 @@ def get_updates_for_github_issues(milestones, labels, 
issue_labels, milestone_re
             elif fix_milestone in milestone_map:
                 break
             else:
-                print "Invalid milestone: %s." % fix_milestone
+                print("Invalid milestone: %s." % fix_milestone)
         fix_milestone_number = milestone_map[fix_milestone]
 
     # get area
@@ -494,19 +494,19 @@ def ask_for_labels(prefix, labels, issue_labels):
             % (prefix, ', '.join(filtered_labels).strip(), ', 
'.join(issue_filtered_labels).strip()))
         if fix_labels == "":
             if not issue_filtered_labels:
-                print "Please specify a '%s' label to close the issue!" % 
prefix
+                print("Please specify a '%s' label to close the issue!" % 
prefix)
                 continue
             else:
                 fix_labels = issue_filtered_labels
                 break
         fix_labels = fix_labels.replace(" ", "").split(",")
         if not fix_labels:
-            print "Please specify a '%s' label to close the issue!" % prefix
+            print("Please specify a '%s' label to close the issue!" % prefix)
             continue
         invalid_label = False
         for label in fix_labels:
             if label not in filtered_labels:
-                print "Invalid '%s' label: %s." % (prefix, label)
+                print("Invalid '%s' label: %s." % (prefix, label))
                 invalid_label = True
                 break
         if invalid_label:
@@ -581,12 +581,12 @@ def main():
     global original_head
 
     if not GITHUB_OAUTH_KEY:
-        print "OAuth key is needed for merging bookkeeper pull requests."
-        print "If environment variable 'GITHUB_OAUTH_KEY' is not defined,"
-        print "then requests will be unauthenticated."
-        print "You can create an OAuth key at 
https://github.com/settings/tokens";
-        print "and set it to the environment variable 'GITHUB_OAUTH_KEY'."
-        print "(This token only needs the 'public_repo' scope permissions)"
+        print("OAuth key is needed for merging bookkeeper pull requests.")
+        print("If environment variable 'GITHUB_OAUTH_KEY' is not defined,")
+        print("then requests will be unauthenticated.")
+        print("You can create an OAuth key at 
https://github.com/settings/tokens";)
+        print("and set it to the environment variable 'GITHUB_OAUTH_KEY'.")
+        print("(This token only needs the 'public_repo' scope permissions)")
         exit(-1)
 
     # 0. get the current state so we can go back
@@ -618,16 +618,16 @@ def main():
     # Decide whether to use the modified title or not
     modified_title, github_issue_ids = standardize_issue_ref(commit_title)
     if modified_title != commit_title:
-        print "I've re-written the title as follows to match the standard 
format:"
-        print "Original: %s" % commit_title
-        print "Modified: %s" % modified_title
+        print("I've re-written the title as follows to match the standard 
format:")
+        print("Original: %s" % commit_title)
+        print("Modified: %s" % modified_title)
         result = raw_input("Would you like to use the modified title? (y/n): ")
         if result.lower() == "y":
             commit_title = modified_title
-            print "Using modified title:"
+            print("Using modified title:")
         else:
-            print "Using original title:"
-        print commit_title
+            print("Using original title:")
+        print(commit_title)
 
     body = pr["body"]
     modified_body = ""
@@ -635,19 +635,19 @@ def main():
         if line.startswith('>'):
             continue
         modified_body = modified_body + line + "\n"
-    modified_body = modified_body.rstrip("\n")
+    modified_body = modified_body[:-1]
     if modified_body != body:
-        print "I've re-written the body as follows to match the standard 
formats:"
-        print "Original: "
-        print body
-        print "Modified: "
-        print modified_body
+        print("I've re-written the body as follows to match the standard 
formats:")
+        print("Original: ")
+        print(body)
+        print("Modified: ")
+        print(modified_body)
         result = raw_input("Would you like to use the modified body? (y/n): ")
         if result.lower() == "y":
             body = modified_body
-            print "Using modified body."
+            print("Using modified body.")
         else:
-            print "Using original body."
+            print("Using original body.")
 
     target_ref = pr["base"]["ref"]
     user_login = pr["user"]["login"]
@@ -698,13 +698,13 @@ def main():
         merge_hash = merge_commits[0]["commit_id"]
         message = get_json("%s/commits/%s" % (GITHUB_API_BASE, 
merge_hash))["commit"]["message"]
 
-        print "Pull request %s has already been merged, assuming you want to 
backport" % pr_num
+        print("Pull request %s has already been merged, assuming you want to 
backport" % pr_num)
         commit_is_downloaded = run_cmd(['git', 'rev-parse', '--quiet', 
'--verify',
                                     "%s^{commit}" % merge_hash]).strip() != ""
         if not commit_is_downloaded:
             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)
+        print("Found commit %s:\n%s" % (merge_hash, message))
         
         cherry_pick(pr_num, merge_hash, ask_for_branch(latest_branch))
         sys.exit(0)
@@ -714,8 +714,8 @@ def main():
             "You may need to rebase the PR."
         fail(msg)
 
-    print ("\n=== Pull Request #%s ===" % pr_num)
-    print ("PR title\t%s\nCommit 
title\t%s\nSource\t\t%s\nTarget\t\t%s\nURL\t\t%s" % (
+    print("\n=== Pull Request #%s ===" % pr_num)
+    print("PR title\t%s\nCommit 
title\t%s\nSource\t\t%s\nTarget\t\t%s\nURL\t\t%s" % (
         pr_title, commit_title, pr_repo_desc, target_ref, url))
     continue_maybe("Proceed with merging pull request #%s?" % pr_num)
 
diff --git a/dev/bk-merge-pr.py b/dev/bk-merge-pr3.py
similarity index 80%
copy from dev/bk-merge-pr.py
copy to dev/bk-merge-pr3.py
index 2c69890..4f755f9 100755
--- a/dev/bk-merge-pr.py
+++ b/dev/bk-merge-pr3.py
@@ -30,7 +30,8 @@ import os
 import re
 import subprocess
 import sys
-import urllib2
+from urllib.request import urlopen, Request
+from urllib.error import HTTPError
 
 PROJECT_NAME = "bookkeeper"
 
@@ -61,80 +62,80 @@ DEFAULT_FIX_VERSION = os.environ.get("DEFAULT_FIX_VERSION", 
"0.9.1.0")
 
 def get_json(url, preview_api = False):
     try:
-        request = urllib2.Request(url)
+        request = Request(url)
         if GITHUB_OAUTH_KEY:
             request.add_header('Authorization', 'token %s' % GITHUB_OAUTH_KEY)
         if preview_api:
             request.add_header('Accept', 
'application/vnd.github.black-cat-preview+json')
-        return json.load(urllib2.urlopen(request))
-    except urllib2.HTTPError as e:
+        return json.loads(urlopen(request).read())
+    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 
" + \
+            print("Exceeded the GitHub API rate limit; see the instructions in 
" + \
                   "bk-merge-pr.py to configure an OAuth token for making 
authenticated " + \
-                  "GitHub requests."
+                  "GitHub requests.")
         else:
-            print "Unable to fetch URL, exiting: %s" % url
+            print("Unable to fetch URL, exiting: %s" % url)
         sys.exit(-1)
 
 def post_json(url, data):
     try:
-        request = urllib2.Request(url, data, { 'Content-Type': 
'application/json' })
+        request = Request(url, data.encode(encoding='utf-8'), { 
'Content-Type': 'application/json' })
         request.add_header('Authorization', 'token %s' % GITHUB_OAUTH_KEY)
-        return json.load(urllib2.urlopen(request))
-    except urllib2.HTTPError as e:
+        return json.loads(urlopen(request).read())
+    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 
" + \
+            print("Exceeded the GitHub API rate limit; see the instructions in 
" + \
                   "bk-merge-pr.py to configure an OAuth token for making 
authenticated " + \
-                  "GitHub requests."
+                  "GitHub requests.")
         else:
-            print "Unable to fetch URL, exiting: %s - %s" % (url, e)
+            print("Unable to fetch URL, exiting: %s - %s" % (url, e))
         sys.exit(-1)
 
 def put_json(url, data):
     try:
-        request = urllib2.Request(url, data, { 'Content-Type': 
'application/json' })
+        request = Request(url, data.encode(encoding='utf-8'), { 
'Content-Type': 'application/json' })
         request.get_method = lambda: 'PUT'
         request.add_header('Authorization', 'token %s' % GITHUB_OAUTH_KEY)
-        return json.load(urllib2.urlopen(request))
-    except urllib2.HTTPError as e:
+        return json.loads(urlopen(request).read())
+    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 
" + \
+            print("Exceeded the GitHub API rate limit; see the instructions in 
" + \
                   "bk-merge-pr.py to configure an OAuth token for making 
authenticated " + \
-                  "GitHub requests."
+                  "GitHub requests.")
         else:
-            print "Unable to fetch URL, exiting: %s - %s" % (url, e)
-            print e
+            print("Unable to fetch URL, exiting: %s - %s" % (url, e))
+            print(e)
         sys.exit(-1)
 
 
 def fail(msg):
-    print msg
+    print(msg)
     clean_up()
     sys.exit(-1)
 
 
 def run_cmd(cmd):
-    print cmd
+    print(cmd)
     if isinstance(cmd, list):
-        return subprocess.check_output(cmd)
+        return subprocess.check_output(cmd).decode(encoding='utf-8')
     else:
-        return subprocess.check_output(cmd.split(" "))
+        return subprocess.check_output(cmd.split(" ")).decode(encoding='utf-8')
 
 
 def continue_maybe(prompt):
-    result = raw_input("\n%s (y/n): " % prompt)
+    result = input("\n%s (y/n): " % prompt)
     if result.lower() != "y":
         fail("Okay, exiting")
 
 def clean_up():
     if original_head != get_current_branch():
-        print "Restoring head pointer to %s" % original_head
+        print("Restoring head pointer to %s" % original_head)
         run_cmd("git checkout %s" % original_head)
 
     branches = run_cmd("git branch").replace(" ", "").split("\n")
 
-    for branch in filter(lambda x: x.startswith(TEMP_BRANCH_PREFIX), branches):
-        print "Deleting local branch %s" % branch
+    for branch in list(filter(lambda x: x.startswith(TEMP_BRANCH_PREFIX), 
branches)):
+        print("Deleting local branch %s" % branch)
         run_cmd("git branch -D %s" % branch)
 
 def get_current_branch():
@@ -145,7 +146,7 @@ def get_milestones():
 
 def get_all_labels():
     result = get_json("https://api.github.com/repos/%s/%s/labels?per_page=%s"; 
% (GITHUB_USER, PROJECT_NAME, GITHUB_PAGE_SIZE))
-    return map(lambda x: x['name'], result)
+    return list(map(lambda x: x['name'], result))
 
 # merge the requested PR and return the merge hash
 def merge_pr(pr_num, target_ref, title, body, default_pr_reviewers, 
pr_repo_desc):
@@ -156,13 +157,13 @@ def merge_pr(pr_num, target_ref, title, body, 
default_pr_reviewers, 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(
         "Enter primary author in the format of \"name <email>\" [%s]: " %
         distinct_authors[0])
     if primary_author == "":
         primary_author = distinct_authors[0]
 
-    reviewers = raw_input("Enter reviewers [%s]: " % 
default_pr_reviewers).strip()
+    reviewers = input("Enter reviewers [%s]: " % default_pr_reviewers).strip()
     if reviewers == '':
         reviewers = default_pr_reviewers
 
@@ -170,7 +171,7 @@ def merge_pr(pr_num, target_ref, title, body, 
default_pr_reviewers, pr_repo_desc
                       '--pretty=format:%h [%an] %s']).split("\n")
     
     if len(commits) > 1:
-        result = raw_input("List pull request commits in squashed commit 
message? (y/n): ")
+        result = input("List pull request commits in squashed commit message? 
(y/n): ")
         if result.lower() == "y":
           should_list_commits = True
         else:
@@ -231,7 +232,7 @@ def merge_pr(pr_num, target_ref, title, body, 
default_pr_reviewers, pr_repo_desc
     return merge_hash, merge_log
 
 def ask_for_branch(default_branch):
-    pick_ref = raw_input("Enter a branch name [%s]: " % default_branch)
+    pick_ref = input("Enter a branch name [%s]: " % default_branch)
     if pick_ref == "":
         pick_ref = default_branch
     return pick_ref
@@ -270,13 +271,13 @@ def cherry_pick(pr_num, merge_hash, pick_ref):
 def fix_version_from_branch(branch, versions, target_ref):
     # Note: Assumes this is a sorted (newest->oldest) list of un-released 
versions
     if branch == target_ref:
-        versions = filter(lambda x: x == DEFAULT_FIX_VERSION, versions)
+        versions = list(filter(lambda x: x == DEFAULT_FIX_VERSION, versions))
         if len(versions) > 0:
             return versions[0]
         else:
             return None
     else:
-        versions = filter(lambda x: x.startswith(branch), versions)
+        versions = list(filter(lambda x: x.startswith(branch), versions))
         if len(versions) > 0:
             return versions[-1]
         else:
@@ -359,7 +360,7 @@ def get_reviewers(pr_num):
             username = user['name'].strip()
         if username is None:
             continue
-        reviewers_emails.append('{0} <{1}>'.format(username.encode('utf8'), 
useremail))
+        reviewers_emails.append('{0} <{1}>'.format(username, useremail))
     return ', '.join(reviewers_emails)
 
 def check_ci_status(pr):
@@ -369,9 +370,9 @@ def check_ci_status(pr):
         comments = get_json(pr["comments_url"])
         ignore_ci_comments = [c for c in comments if c["body"].upper() == 
"IGNORE CI"]
         if len(ignore_ci_comments) > 0:
-            print "\n\nWARNING: The PR has not passed CI (state is %s)" % 
(state) \
+            print("\n\nWARNING: The PR has not passed CI (state is %s)" % 
(state) \
                 + ", but this has been overridden by %s. \n" % 
(ignore_ci_comments[0]["user"]["login"]) \
-                + "Proceed at your own peril!\n\n"
+                + "Proceed at your own peril!\n\n")
         else:
             check_individual_ci_status(ci_status, comments)
 
@@ -411,14 +412,14 @@ def check_individual_ci_status(ci_status, comments):
         # all ci passed except integration tests
         ignore_it_ci_comments = [c for c in comments if c["body"].upper() == 
"IGNORE IT CI"]
         if len(ignore_it_ci_comments) > 0:
-            print "\n\nWARNING: The PR has not passed integration tests CI" \
+            print("\n\nWARNING: The PR has not passed integration tests CI" \
                 + ", but this has been overridden by %s. \n" % 
(ignore_it_ci_comments[0]["user"]["login"]) \
-                + "Proceed at your own peril!\n\n"
+                + "Proceed at your own peril!\n\n")
         else:
             fail("The PR has not passed integration tests CI")
     elif len(ci_failures) != 0 or len(ci_integration_test_failures) != 0:
         fail_msg = "The PR has not passed CI:\n"
-        print ""
+        print("")
         for status in ci_failures:
             fail_msg += "\t %s = %s\n" % (status["context"], status["state"])
         for status in ci_integration_test_failures:
@@ -426,18 +427,18 @@ def check_individual_ci_status(ci_status, comments):
         fail(fail_msg)
 
 def ask_release_for_github_issues(branch, labels):
-    print "=== Add release to github issues ==="
+    print("=== Add release to github issues ===")
     while True:
         fix_releases = ask_for_labels("release/%s" % branch, labels, [])
         if len(fix_releases) != 1:
-            print "Please choose only one release to add for branch '%s'." % 
branch
+            print("Please choose only one release to add for branch '%s'." % 
branch)
             continue
 
-        print "=== Apply following releases to github issues ==" 
-        print "Fix Releases: %s" % ', '.join(fix_releases)
-        print ""
+        print("=== Apply following releases to github issues ==")
+        print("Fix Releases: %s" % ', '.join(fix_releases))
+        print("")
 
-        if raw_input("Would you like to add these releases to github issues? 
(y/n): ") == "y":
+        if input("Would you like to add these releases to github issues? 
(y/n): ") == "y":
             break
     return fix_releases
 
@@ -446,14 +447,14 @@ def ask_updates_for_github_issues(milestones, labels, 
issue_labels, milestone_re
         fix_milestone, fix_milestone_number, fix_areas, fix_types = \
             get_updates_for_github_issues(milestones, labels, issue_labels, 
milestone_required)
 
-        print "=== Apply following milestone, area, type to github issues ==" 
-        print "Fix Types: %s" % ', '.join(fix_types)
-        print "Fix Areas: %s" % ', '.join(fix_areas)
+        print("=== Apply following milestone, area, type to github issues ==")
+        print("Fix Types: %s" % ', '.join(fix_types))
+        print("Fix Areas: %s" % ', '.join(fix_areas))
         if milestone_required:
-            print "Fix Milestone: %s" % fix_milestone
-        print ""
+            print("Fix Milestone: %s" % fix_milestone)
+        print("")
 
-        if raw_input("Would you like to update github issues with these 
labels? (y/n): ") == "y":
+        if input("Would you like to update github issues with these labels? 
(y/n): ") == "y":
             break
 
     return fix_milestone, fix_milestone_number, fix_areas, fix_types
@@ -464,10 +465,10 @@ def get_updates_for_github_issues(milestones, labels, 
issue_labels, milestone_re
     fix_milestone_number = ""
     if milestone_required:
         default_milestone_name = milestones[0]['title']
-        milestone_list = map(lambda x: x['title'], milestones)
+        milestone_list = list(map(lambda x: x['title'], milestones))
         milestone_map = dict((milestone['title'], milestone['number']) for 
milestone in milestones)
         while True:
-            fix_milestone = raw_input("Choose fix milestone : options are [%s] 
- default: [%s]: " % (', '.join(milestone_list).strip(), 
default_milestone_name))
+            fix_milestone = input("Choose fix milestone : options are [%s] - 
default: [%s]: " % (', '.join(milestone_list).strip(), default_milestone_name))
             fix_milestone = fix_milestone.strip()
             if fix_milestone == "":
                 fix_milestone = default_milestone_name
@@ -475,7 +476,7 @@ def get_updates_for_github_issues(milestones, labels, 
issue_labels, milestone_re
             elif fix_milestone in milestone_map:
                 break
             else:
-                print "Invalid milestone: %s." % fix_milestone
+                print("Invalid milestone: %s." % fix_milestone)
         fix_milestone_number = milestone_map[fix_milestone]
 
     # get area
@@ -487,26 +488,26 @@ def get_updates_for_github_issues(milestones, labels, 
issue_labels, milestone_re
     return fix_milestone, fix_milestone_number, fix_areas, fix_types
 
 def ask_for_labels(prefix, labels, issue_labels):
-    issue_filtered_labels = map(lambda l: l.split('/')[1], filter(lambda x: 
x.startswith(prefix), issue_labels))
-    filtered_labels = map(lambda l: l.split('/')[1], filter(lambda x: 
x.startswith(prefix), labels))
+    issue_filtered_labels = list(map(lambda l: l.split('/')[1], filter(lambda 
x: x.startswith(prefix), issue_labels)))
+    filtered_labels = list(map(lambda l: l.split('/')[1], filter(lambda x: 
x.startswith(prefix), labels)))
     while True:
-        fix_labels = raw_input("Choose label '%s' - options are: [%s] - 
default: [%s] (comma separated): "
+        fix_labels = input("Choose label '%s' - options are: [%s] - default: 
[%s] (comma separated): "
             % (prefix, ', '.join(filtered_labels).strip(), ', 
'.join(issue_filtered_labels).strip()))
         if fix_labels == "":
             if not issue_filtered_labels:
-                print "Please specify a '%s' label to close the issue!" % 
prefix
+                print("Please specify a '%s' label to close the issue!" % 
prefix)
                 continue
             else:
                 fix_labels = issue_filtered_labels
                 break
         fix_labels = fix_labels.replace(" ", "").split(",")
         if not fix_labels:
-            print "Please specify a '%s' label to close the issue!" % prefix
+            print("Please specify a '%s' label to close the issue!" % prefix)
             continue
         invalid_label = False
         for label in fix_labels:
             if label not in filtered_labels:
-                print "Invalid '%s' label: %s." % (prefix, label)
+                print("Invalid '%s' label: %s." % (prefix, label))
                 invalid_label = True
                 break
         if invalid_label:
@@ -527,7 +528,7 @@ def get_assignees_url(github_issue_id):
 def get_github_issue_labels(github_issue_id):
     url = "https://api.github.com/repos/%s/%s/issues/%s/labels"; % 
(GITHUB_USER, PROJECT_NAME, github_issue_id) 
     result = get_json(url)
-    return map(lambda x: x["name"], result)
+    return list(map(lambda x: x["name"], result))
 
 def add_release_to_github_issues(github_issue_ids, labels, fix_release):
     for github_issue_id in github_issue_ids:
@@ -545,8 +546,8 @@ def add_release_to_github_issue(github_issue_id, labels, 
fix_release):
 
 def update_github_issue(github_issue_id, fix_milestone_number, fix_milestone, 
fix_areas, fix_types, other_labels):
     url = get_github_issue_url(github_issue_id)
-    labels = other_labels + map(lambda x: "area/%s" % x, fix_areas)
-    labels = labels + map(lambda x: "type/%s" % x, fix_types)
+    labels = other_labels + list(map(lambda x: ("area/%s" % x), fix_areas))
+    labels = labels + list(map(lambda x: ("type/%s" % x), fix_types))
     if fix_milestone_number == '':
         data = json.dumps({
             'labels': labels,
@@ -581,12 +582,12 @@ def main():
     global original_head
 
     if not GITHUB_OAUTH_KEY:
-        print "OAuth key is needed for merging bookkeeper pull requests."
-        print "If environment variable 'GITHUB_OAUTH_KEY' is not defined,"
-        print "then requests will be unauthenticated."
-        print "You can create an OAuth key at 
https://github.com/settings/tokens";
-        print "and set it to the environment variable 'GITHUB_OAUTH_KEY'."
-        print "(This token only needs the 'public_repo' scope permissions)"
+        print("OAuth key is needed for merging bookkeeper pull requests.")
+        print("If environment variable 'GITHUB_OAUTH_KEY' is not defined,")
+        print("then requests will be unauthenticated.")
+        print("You can create an OAuth key at 
https://github.com/settings/tokens";)
+        print("and set it to the environment variable 'GITHUB_OAUTH_KEY'.")
+        print("(This token only needs the 'public_repo' scope permissions)")
         exit(-1)
 
     # 0. get the current state so we can go back
@@ -596,12 +597,12 @@ def main():
     milestones = get_milestones()
     labels = get_all_labels()
     branches = get_json("%s/branches" % GITHUB_API_BASE)
-    branch_names = filter(lambda x: x.startswith(RELEASE_BRANCH_PREFIX), 
[x['name'] for x in branches])
+    branch_names = list(filter(lambda x: x.startswith(RELEASE_BRANCH_PREFIX), 
[x['name'] for x in branches]))
     # Assumes branch names can be sorted lexicographically
     latest_branch = sorted(branch_names, reverse=True)[0]
 
     # 2. retrieve the details for a given pull request
-    pr_num = raw_input("Which pull request would you like to merge? (e.g. 34): 
")
+    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))
     pr_reviewers = get_reviewers(pr_num)
@@ -611,23 +612,23 @@ def main():
 
     # 3. repair the title for commit message
     pr_title = pr["title"]
-    commit_title = raw_input("Commit title [%s]: " % 
pr_title.encode("utf-8")).decode("utf-8")
+    commit_title = input("Commit title [%s]: " % pr_title)
     if commit_title == "":
         commit_title = pr_title
 
     # Decide whether to use the modified title or not
     modified_title, github_issue_ids = standardize_issue_ref(commit_title)
     if modified_title != commit_title:
-        print "I've re-written the title as follows to match the standard 
format:"
-        print "Original: %s" % commit_title
-        print "Modified: %s" % modified_title
-        result = raw_input("Would you like to use the modified title? (y/n): ")
+        print("I've re-written the title as follows to match the standard 
format:")
+        print("Original: %s" % commit_title)
+        print("Modified: %s" % modified_title)
+        result = input("Would you like to use the modified title? (y/n): ")
         if result.lower() == "y":
             commit_title = modified_title
-            print "Using modified title:"
+            print("Using modified title:")
         else:
-            print "Using original title:"
-        print commit_title
+            print("Using original title:")
+        print(commit_title)
 
     body = pr["body"]
     modified_body = ""
@@ -635,19 +636,19 @@ def main():
         if line.startswith('>'):
             continue
         modified_body = modified_body + line + "\n"
-    modified_body = modified_body.rstrip("\n")
+    modified_body = modified_body[:-1]
     if modified_body != body:
-        print "I've re-written the body as follows to match the standard 
formats:"
-        print "Original: "
-        print body
-        print "Modified: "
-        print modified_body
-        result = raw_input("Would you like to use the modified body? (y/n): ")
+        print("I've re-written the body as follows to match the standard 
formats:")
+        print("Original: ")
+        print(body)
+        print("Modified: ")
+        print(modified_body)
+        result = input("Would you like to use the modified body? (y/n): ")
         if result.lower() == "y":
             body = modified_body
-            print "Using modified body."
+            print("Using modified body.")
         else:
-            print "Using original body."
+            print("Using original body.")
 
     target_ref = pr["base"]["ref"]
     user_login = pr["user"]["login"]
@@ -667,7 +668,7 @@ def main():
     fix_milestone, fix_milestone_number, fix_areas, fix_types = \
         ask_updates_for_github_issues(milestones, labels, issue_labels, 
target_ref == "master")
     # update issues with fix milestone, are and type
-    other_labels = filter(lambda x: not x.startswith("area"), issue_labels)
+    other_labels = list(filter(lambda x: not x.startswith("area"), 
issue_labels))
     all_issue_labels = update_github_issues( \
         github_issue_ids, \
         fix_milestone_number, \
@@ -698,13 +699,13 @@ def main():
         merge_hash = merge_commits[0]["commit_id"]
         message = get_json("%s/commits/%s" % (GITHUB_API_BASE, 
merge_hash))["commit"]["message"]
 
-        print "Pull request %s has already been merged, assuming you want to 
backport" % pr_num
+        print("Pull request %s has already been merged, assuming you want to 
backport" % pr_num)
         commit_is_downloaded = run_cmd(['git', 'rev-parse', '--quiet', 
'--verify',
                                     "%s^{commit}" % merge_hash]).strip() != ""
         if not commit_is_downloaded:
             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)
+        print("Found commit %s:\n%s" % (merge_hash, message))
         
         cherry_pick(pr_num, merge_hash, ask_for_branch(latest_branch))
         sys.exit(0)
@@ -714,8 +715,8 @@ def main():
             "You may need to rebase the PR."
         fail(msg)
 
-    print ("\n=== Pull Request #%s ===" % pr_num)
-    print ("PR title\t%s\nCommit 
title\t%s\nSource\t\t%s\nTarget\t\t%s\nURL\t\t%s" % (
+    print("\n=== Pull Request #%s ===" % pr_num)
+    print("PR title\t%s\nCommit 
title\t%s\nSource\t\t%s\nTarget\t\t%s\nURL\t\t%s" % (
         pr_title, commit_title, pr_repo_desc, target_ref, url))
     continue_maybe("Proceed with merging pull request #%s?" % pr_num)
 
@@ -727,7 +728,7 @@ def main():
     run_cmd("git fetch %s" % PR_REMOTE_NAME)
 
     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("\n%s (y/n): " % pick_prompt).lower() == "y":
         pick_ref = ask_for_branch(latest_branch) 
         branch_version = pick_ref.split('-')[1]
         # add releases

Reply via email to