You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2016/02/26 23:11:49 UTC

mesos git commit: Added a support/push-reviews.py script to push reviews upstream.

Repository: mesos
Updated Branches:
  refs/heads/master 6f47f7175 -> d1d3f4bbc


Added a support/push-reviews.py script to push reviews upstream.

This script allows committers to push locally applied review chain to the ASF
git repo and mark the reviews as submitted.

Review: https://reviews.apache.org/r/43552


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

Branch: refs/heads/master
Commit: d1d3f4bbc68288bde365ea5df0eaccc3cae04b3a
Parents: 6f47f71
Author: Vinod Kone <vi...@gmail.com>
Authored: Thu Feb 11 12:07:25 2016 -0800
Committer: Vinod Kone <vi...@gmail.com>
Committed: Fri Feb 26 14:11:11 2016 -0800

----------------------------------------------------------------------
 support/push-reviews.py | 124 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 124 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d1d3f4bb/support/push-reviews.py
----------------------------------------------------------------------
diff --git a/support/push-reviews.py b/support/push-reviews.py
new file mode 100755
index 0000000..acab1f5
--- /dev/null
+++ b/support/push-reviews.py
@@ -0,0 +1,124 @@
+#!/usr/bin/env python
+
+# This script is typically used by Mesos committers to push a locally applied
+# review chain to ASF git repo and mark the reviews as submitted on ASF
+# ReviewBoard.
+#
+# Example Usage:
+#
+# > git checkout master
+# > git pull origin
+# > ./support/apply-reviews.py -c -r 1234
+# > ./support/push-reviews.py
+#
+# TODO(vinod): Also post the commit message to the corresponding ASF JIRA
+# tickets and resolve them if necessary.
+
+import argparse
+import os
+import re
+import sys
+
+from subprocess import check_output
+
+REVIEWBOARD_URL =  'https://reviews.apache.org'
+
+
+def get_reviews(revision_range):
+    """Returns the list of reviews found in the commits in the revision range.
+    """
+    log = check_output(['git',
+                        '--no-pager',
+                        'log',
+                        '--no-color',
+                        '--reverse',
+                        revision_range]).strip()
+
+    review_ids = []
+    for line in log.split('\n'):
+        pos = line.find('Review: ')
+        if pos != -1:
+            pattern = re.compile('Review: ({url})$'.format(
+                url=os.path.join(REVIEWBOARD_URL, 'r', '[0-9]+')))
+            match = pattern.search(line.strip().strip('/'))
+            if match is None:
+                print "\nInvalid ReviewBoard URL: '{}'".format(line[pos:])
+                sys.exit(1)
+
+            url = match.group(1)
+            review_ids.append(os.path.basename(url))
+
+    return review_ids
+
+
+def close_reviews(reviews, options):
+    """ Marks the given reviews as submitted on ReviewBoard."""
+    # Close the reviews on ReviewBoard.
+    for review_id in reviews:
+       print 'Closing review', review_id
+       if not options['dry_run']:
+           # TODO(vinod): Include the commit message as '--description'.
+           check_output(['rbt', 'close', review_id])
+
+
+def parse_options():
+    """Returns a dictionary of options parsed from command line arguments."""
+    parser = argparse.ArgumentParser()
+
+    parser.add_argument('-n',
+                        '--dry-run',
+                        action='store_true',
+                        help='Perform a dry run.')
+
+    args = parser.parse_args()
+
+    options = {}
+    options['dry_run'] = args.dry_run
+
+    return options
+
+
+if __name__ == '__main__':
+    options = parse_options()
+
+    current_branch_ref = check_output(['git', 'symbolic-ref', 'HEAD']).strip()
+    current_branch = current_branch_ref.replace('refs/heads/', '', 1)
+
+    if current_branch != 'master':
+        print 'Please run this script from master branch'
+        sys.exit(1)
+
+    remote_tracking_branch = check_output(['git',
+                                           'rev-parse',
+                                           '--abbrev-ref',
+                                           'master@{upstream}']).strip()
+
+    merge_base = check_output(['git',
+			       'merge-base',
+			       remote_tracking_branch,
+			       'master']).strip()
+
+    if merge_base == current_branch_ref:
+        print 'No new commits found to push'
+        sys.exit(1)
+
+    reviews = get_reviews(merge_base + ".." + current_branch_ref)
+
+    print 'Found reviews', reviews
+
+    # Push the current branch to remote master.
+    remote = check_output(['git',
+                           'config',
+                           '--get',
+                           'branch.master.remote']).strip()
+
+    print 'Pushing commits to', remote
+
+    if not options['dry_run']:
+        check_output(['git',
+                      'push',
+                      remote,
+                      'master:master'])
+
+    # Now mark the reviews as submitted.
+    close_reviews(reviews, options)