diff --git a/.reviewboardrc b/.reviewboardrc new file mode 100644 index 0000000..5e8d670 --- /dev/null +++ b/.reviewboardrc @@ -0,0 +1,3 @@ +REPOSITORY = 'git://git.apache.org/kafka.git' +TARGET_GROUPS = 'kafka' +GUESS_FIELDS = True diff --git a/kafka-patch-review.py b/kafka-patch-review.py new file mode 100644 index 0000000..856ca1d --- /dev/null +++ b/kafka-patch-review.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python + +import argparse +import sys +import os +import time +import datetime +from jira.client import JIRA + +def get_jira(): + options = { + 'server': 'https://issues.apache.org/jira' + } + # read the config file + home=jira_home=os.getenv('HOME') + home=home.rstrip('/') + jira_config = dict(line.strip().split('=') for line in open(home + '/jira.ini')) + jira = JIRA(options,basic_auth=(jira_config['user'], jira_config['password'])) + return jira + +def main(): + ''' main(), shut up, pylint ''' + popt = argparse.ArgumentParser(description='Kafka patch review tool') + popt.add_argument('-b', '--branch', action='store', dest='branch', required=True, help='Tracking branch to create diff against') + popt.add_argument('-j', '--jira', action='store', dest='jira', required=True, help='JIRA corresponding to the reviewboard') + popt.add_argument('-s', '--summary', action='store', dest='summary', required=False, help='Summary for the reviewboard') + popt.add_argument('-d', '--description', action='store', dest='description', required=False, help='Description for reviewboard') + popt.add_argument('-r', '--rb', action='store', dest='reviewboard', required=False, help='Review board that needs to be updated') + popt.add_argument('-t', '--testing-done', action='store', dest='testing', required=False, help='Text for the Testing Done section of the reviewboard') + popt.add_argument('-db', '--debug', action='store_true', required=False, help='Enable debug mode') + opt = popt.parse_args() + + patch_file=opt.jira + ".patch" + if opt.reviewboard: + ts = time.time() + st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d_%H:%M:%S') + patch_file=opt.jira + '_' + st + '.patch' + + rb_command="post-review --publish --tracking-branch " + opt.branch + " --target-groups=kafka --bugs-closed=" + opt.jira + summary="Patch for " + opt.jira + if opt.summary: + summary=opt.summary + rb_command=rb_command + " --summary \"" + summary + "\"" + if opt.description: + rb_command=rb_command + " --description \"" + opt.description + "\"" + if opt.reviewboard: + rb_command=rb_command + " -r " + opt.reviewboard + if opt.testing: + rb_command=rb_command + " --testing-done=" + opt.testing + if opt.debug: + print rb_command + p=os.popen(rb_command) + rb_url="" + for line in p: + print line + if line.startswith('http'): + rb_url = line + elif line.startswith("There don't seem to be any diffs"): + print 'ERROR: No diff to upload. Please check in the diff to the local branch and retry' + p.close() + sys.exit(1) + p.close() + if opt.debug: + print 'rb url=',rb_url + + git_command="git diff " + opt.branch + " > " + patch_file + if opt.debug: + print git_command + p=os.popen(git_command) + p.close() + + print 'Creating diff against', opt.branch, 'and uploading patch to JIRA',opt.jira + jira=get_jira() + issue = jira.issue(opt.jira) + attachment=open(patch_file) + jira.add_attachment(issue,attachment) + attachment.close() + + comment="Created reviewboard " + if not opt.reviewboard: + print 'Created a new reviewboard ',rb_url + else: + print 'Updating reviewboard',opt.reviewboard + comment="Updated reviewboard " + + comment = comment + rb_url + jira.add_comment(opt.jira, comment) + +if __name__ == '__main__': + sys.exit(main()) +