distributedlog-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From si...@apache.org
Subject incubator-distributedlog git commit: Improve merge pull request scripts
Date Wed, 04 Jan 2017 08:40:32 GMT
Repository: incubator-distributedlog
Updated Branches:
  refs/heads/master f607a48ff -> 0711bc2fd


Improve merge pull request scripts

- check if a pull request is approved or not
- reject merging if there is no approval
- handle cases that reviewers don't have name and email configured.

Author: Sijie Guo <sijie@apache.org>

Reviewers: Franck Cuny <fcuny@apache.org>

Closes #93 from sijie/sijie/improve_merge_scripts


Project: http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/commit/0711bc2f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/tree/0711bc2f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/diff/0711bc2f

Branch: refs/heads/master
Commit: 0711bc2fdc2afbb573ce42d9eecccf03e166f006
Parents: f607a48
Author: Sijie Guo <sijie@apache.org>
Authored: Wed Jan 4 00:40:28 2017 -0800
Committer: Sijie Guo <sijie@apache.org>
Committed: Wed Jan 4 00:40:28 2017 -0800

----------------------------------------------------------------------
 scripts/dev/dl-merge-pr.py | 42 ++++++++++++++++++++++++++++++++---------
 scripts/dev/reviewers      | 18 ++++++++++++++++++
 2 files changed, 51 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/0711bc2f/scripts/dev/dl-merge-pr.py
----------------------------------------------------------------------
diff --git a/scripts/dev/dl-merge-pr.py b/scripts/dev/dl-merge-pr.py
index ca853d0..6c9d3e8 100755
--- a/scripts/dev/dl-merge-pr.py
+++ b/scripts/dev/dl-merge-pr.py
@@ -84,8 +84,9 @@ TEMP_BRANCH_PREFIX = 'PR_TOOL'
 RELEASE_BRANCH_PREFIX = ''
 
 DEV_BRANCH_NAME = 'master'
+DEFAULT_FIX_VERSION = os.environ.get("DEFAULT_FIX_VERSION", "0.4.0")
 
-def get_json(url):
+def get_json(url, preview_api = False):
   """
   Returns parsed JSON from an API call to the GitHub API.
   """
@@ -93,6 +94,8 @@ def get_json(url):
     request = urllib2.Request(url)
     if GITHUB_OAUTH_KEY:
       request.add_header('Authorization', 'token {0}'.format(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':
@@ -139,7 +142,7 @@ def clean_up():
     print('Restoring head pointer to {0}'.format(original_head))
     run_cmd(['git', 'checkout', original_head])
 
-  branches = run_cmd(['git', 'branch']).strip().split('\n')
+  branches = run_cmd(['git', 'branch']).replace(" ", "").split('\n')
 
   for branch in filter(lambda x: x.startswith(TEMP_BRANCH_PREFIX), branches):
     print('Deleting local branch {0}'.format(branch))
@@ -290,6 +293,7 @@ def cherry_pick(pr_num, merge_hash, default_branch):
 def fix_version_from_branch(branch, versions):
   # Note: Assumes this is a sorted (newest->oldest) list of un-released versions
   if branch == DEV_BRANCH_NAME:
+    versions = filter(lambda x: x == DEFAULT_FIX_VERSION, versions)
     if len(versions) > 0:
       return versions[0]
     else:
@@ -328,9 +332,10 @@ def resolve_jira_issue(merge_branches, comment, jira_id):
 
   if cur_status == 'Resolved' or cur_status == 'Closed':
     fail('JIRA issue {0} already has status \'{1}\''.format(jira_id, cur_status))
-    print ('=== JIRA {0} ==='.format(jira_id))
-    print ('summary\t\t{0}\nassignee\t{1}\nstatus\t\t{2}\nurl\t\t{3}/{4}\n'.format(
-      cur_summary, cur_assignee, cur_status, JIRA_BASE, jira_id))
+
+  print ('=== JIRA {0} ==='.format(jira_id))
+  print ('summary\t\t{0}\nassignee\t{1}\nstatus\t\t{2}\nurl\t\t{3}/{4}\n'.format(
+    cur_summary, cur_assignee, cur_status, JIRA_BASE, jira_id))
 
   versions = asf_jira.project_versions(CAPITALIZED_PROJECT_NAME)
   versions = sorted(versions, key=lambda x: x.name, reverse=True)
@@ -418,21 +423,40 @@ def get_reviewers(pr_num):
   """
   Gets a candidate list of reviewers that have commented on the PR with '+1' or 'LGTM'
   """
-  approval_msgs = ['+1', 'lgtm']
+  reviewers_ids = set()
 
+  approval_msgs = ['+1', 'lgtm']
   pr_comments = get_json('{0}/issues/{1}/comments'.format(GITHUB_API_BASE, pr_num))
-
-  reviewers_ids = set()
   for comment in pr_comments:
     for approval_msg in approval_msgs:
       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")
+
+  dir_path = os.path.dirname(os.path.realpath(__file__))
+  with open('{0}/reviewers'.format(dir_path)) as reviewers_data:
+    reviewers = json.load(reviewers_data)
+
   reviewers_emails = []
   for reviewer_id in reviewers_ids:
-    user = get_json('{0}/users/{1}'.format(GITHUB_API_URL, reviewer_id))
     username = None
     useremail = None
+    if reviewers[reviewer_id] is not None:
+      reviewer = reviewers[reviewer_id]
+      username = reviewer['name']
+      useremail = reviewer['email']
+      reviewers_emails += ['{0} <{1}>'.format(username, useremail)]
+      continue
+    user = get_json('{0}/users/{1}'.format(GITHUB_API_URL, reviewer_id))
     if user['email'] is not None:
         useremail = user['email'].strip()
     else:

http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/0711bc2f/scripts/dev/reviewers
----------------------------------------------------------------------
diff --git a/scripts/dev/reviewers b/scripts/dev/reviewers
new file mode 100644
index 0000000..c1a78e2
--- /dev/null
+++ b/scripts/dev/reviewers
@@ -0,0 +1,18 @@
+{
+    "franckcuny": {
+        "name" : "Franck Cuny",
+        "email" : "fcuny@apache.org"
+    },
+    "leighst": {
+        "name" : "Leigh Stewart",
+        "email" : "lstewart@apache.org"
+    },
+    "mgodave": {
+        "name" : "Dave Rusek",
+        "email" : "drusek@apache.org"
+    },
+    "sijie": {
+        "name" : "Sijie Guo",
+        "email" : "sijie@apache.org"
+    }
+}


Mime
View raw message