Repository: mesos Updated Branches: refs/heads/master d0300e1a4 -> a221abc2a
Made post-reviews.py handle bad (or not) ReviewBoard URLs. Handles the case where the ReviewBoard URL is invalid. af081a07234794f60a2575e0383ce537d7111c18 - Fixed post-reviews.py hanging bug. (29 seconds ago) Invalid ReviewBoard URL : 'https://reviews.apache.org/r/35771 abcd' Reads `REVIEWBOARD_URL` from `.reviewboardrc` if it's available. We use `imp.load_source` to import the `.reviewboardrc` file. > __.reviewboardrc__ > > The .reviewboardrc file is a generic place for configuring a > repository. This must be in a directory in the user's checkout path > to work. __It must parse as a valid Python file__, or you'll see an > error when using rbt. Review: https://reviews.apache.org/r/35777 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/a221abc2 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/a221abc2 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/a221abc2 Branch: refs/heads/master Commit: a221abc2ae8e9bcea683ce381904956c443ddec9 Parents: d0300e1 Author: Michael Park <[email protected]> Authored: Thu Jul 9 19:09:53 2015 +0200 Committer: Till Toenshoff <[email protected]> Committed: Thu Jul 9 19:09:53 2015 +0200 ---------------------------------------------------------------------- support/post-reviews.py | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/a221abc2/support/post-reviews.py ---------------------------------------------------------------------- diff --git a/support/post-reviews.py b/support/post-reviews.py index b04e26b..78201ee 100755 --- a/support/post-reviews.py +++ b/support/post-reviews.py @@ -24,7 +24,9 @@ import argparse import atexit +import imp import os +import re import sys from distutils.version import LooseVersion @@ -95,12 +97,26 @@ if diff_stat: top_level_dir = execute(['git', 'rev-parse', '--show-toplevel']).strip() # Use the tracking_branch specified by the user if exists. -# TODO(jieyu): Parse .reviewboardrc as well. parser = argparse.ArgumentParser(add_help=False) +parser.add_argument('--reviewboard-url') parser.add_argument('--tracking-branch') args, _ = parser.parse_known_args() -tracking_branch = args.tracking_branch if args.tracking_branch else 'master' +# Try to read the .reviewboardrc in the top-level directory. +reviewboardrc_filepath = os.path.join(top_level_dir, '.reviewboardrc') +if os.path.exists(reviewboardrc_filepath): + sys.dont_write_bytecode = True # Prevent generation of '.reviewboardrcc'. + reviewboardrc = imp.load_source('reviewboardrc', reviewboardrc_filepath) + +reviewboard_url = ( + args.reviewboard_url if args.reviewboard_url else + reviewboardrc.REVIEWBOARD_URL if 'REVIEWBOARD_URL' in dir(reviewboardrc) else + 'https://reviews.apache.org') + +tracking_branch = ( + args.tracking_branch if args.tracking_branch else + reviewboardrc.TRACKING_BRANCH if 'TRACKING_BRANCH' in dir(reviewboardrc) else + 'master') branch_ref = execute(['git', 'symbolic-ref', 'HEAD']).strip() branch = branch_ref.replace('refs/heads/', '', 1) @@ -165,10 +181,17 @@ for i in range(len(shas)): review_request_id = None - if message.find('Review: ') != -1: - url = message[(message.index('Review: ') + len('Review: ')):].strip() - # TODO(benh): Handle bad (or not Review Board) URLs. - review_request_id = os.path.basename(url.strip('/')) + pos = message.find('Review:') + if pos != -1: + pattern = re.compile('Review: ({url})$'.format( + url=os.path.join(reviewboard_url, 'r', '[0-9]+'))) + match = pattern.search(message.strip().strip('/')) + if match is None: + print "\nInvalid ReviewBoard URL: '{}'".format(message[pos:]) + sys.exit(1) + + url = match.group(1) + review_request_id = os.path.basename(url) # Show the commit. if review_request_id is None:
