bookkeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From si...@apache.org
Subject bookkeeper git commit: BOOKKEEPER-1021: Improve merge script to handle github reviews api
Date Tue, 11 Apr 2017 06:28:42 GMT
Repository: bookkeeper
Updated Branches:
  refs/heads/master f30f60889 -> ab707d2c6


BOOKKEEPER-1021: Improve merge script to handle github reviews api

Author: Sijie Guo <sijie@apache.org>

Reviewers: Govind Menon <None>

Closes #123 from sijie/sijie/improve_merge_scripts


Project: http://git-wip-us.apache.org/repos/asf/bookkeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/bookkeeper/commit/ab707d2c
Tree: http://git-wip-us.apache.org/repos/asf/bookkeeper/tree/ab707d2c
Diff: http://git-wip-us.apache.org/repos/asf/bookkeeper/diff/ab707d2c

Branch: refs/heads/master
Commit: ab707d2c6b3251b2a9a30a6d14074704460b3da5
Parents: f30f608
Author: Sijie Guo <sijie@apache.org>
Authored: Mon Apr 10 23:28:37 2017 -0700
Committer: Sijie Guo <sijie@apache.org>
Committed: Mon Apr 10 23:28:37 2017 -0700

----------------------------------------------------------------------
 dev/bk-merge-pr.py | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/ab707d2c/dev/bk-merge-pr.py
----------------------------------------------------------------------
diff --git a/dev/bk-merge-pr.py b/dev/bk-merge-pr.py
index a3fd206..e3904a8 100755
--- a/dev/bk-merge-pr.py
+++ b/dev/bk-merge-pr.py
@@ -74,11 +74,13 @@ DEV_BRANCH_NAME = "master"
 
 DEFAULT_FIX_VERSION = os.environ.get("DEFAULT_FIX_VERSION", "0.9.1.0")
 
-def get_json(url):
+def get_json(url, preview_api = False):
     try:
         request = urllib2.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:
         if "X-RateLimit-Remaining" in e.headers and e.headers["X-RateLimit-Remaining"] ==
'0':
@@ -395,10 +397,26 @@ def get_reviewers(pr_num):
             if approval_msg in comment['body'].lower():
                 reviewers_ids.add(comment['user']['login'])
 
+    approval_review_states = ['approved']
+    pr_reviews = get_json('{0}/pulls/{1}/reviews'.format(GITHUB_API_BASE, pr_num), True)
+    for review in pr_reviews:
+        for approval_state in approval_review_states:
+            if approval_state in review['state'].lower():
+                reviewers_ids.add(review['user']['login'])
+
+    if len(reviewers_ids) == 0:
+        fail("No approvals found in this pull request")
+
     reviewers_emails = []
     for reviewer_id in reviewers_ids:
+        username = None
+        useremail = None
         user = get_json("%s/users/%s" % (GITHUB_API_URL, reviewer_id))
-        reviewers_emails += ['%s <%s>' % (user['name'].strip(), user['email'].strip())]
+        useremail = user['email'].strip() if user['email'] or None
+        username = user['name'].strip() if user['name'] or useremail
+        if username is None:
+            continue
+        reviewers_emails.append('{0} <{1}>'.format(username, useremail))
     return ', '.join(reviewers_emails)
 
 def main():


Mime
View raw message