You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by hy...@apache.org on 2014/01/17 08:28:47 UTC

git commit: TAJO-478: Add request-patch-review.py that helps submitting patches to jira and reviewboard. (hyunsik)

Updated Branches:
  refs/heads/master b822c2882 -> 568c52392


TAJO-478: Add request-patch-review.py that helps submitting patches to jira and reviewboard. (hyunsik)


Project: http://git-wip-us.apache.org/repos/asf/incubator-tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tajo/commit/568c5239
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tajo/tree/568c5239
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tajo/diff/568c5239

Branch: refs/heads/master
Commit: 568c52392e0e4532ac78df762137d43072d46cbc
Parents: b822c28
Author: Hyunsik Choi <hy...@apache.org>
Authored: Fri Jan 17 16:28:10 2014 +0900
Committer: Hyunsik Choi <hy...@apache.org>
Committed: Fri Jan 17 16:28:10 2014 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |   3 +
 request-patch-review.py                         | 163 ++++++++++++++++
 .../src/site/markdown/review-request-tool.md    | 191 +++++++++++++++++++
 tajo-project/src/site/site.xml                  |   1 +
 4 files changed, 358 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/568c5239/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 9919921..b9016f8 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -337,6 +337,9 @@ Release 0.8.0 - unreleased
 
   TASKS
 
+    TAJO-478: Add request-patch-review.py that helps submitting patches to
+    jira and reviewboard. (hyunsik)
+
     TAJO-508: Apply findbugs-excludeFilterFile to TajoQA. (jinho)
 
     TAJO-457: Update committer list and contributor list. (hyunsik)

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/568c5239/request-patch-review.py
----------------------------------------------------------------------
diff --git a/request-patch-review.py b/request-patch-review.py
new file mode 100644
index 0000000..bb2d7ee
--- /dev/null
+++ b/request-patch-review.py
@@ -0,0 +1,163 @@
+#!/usr/bin/env python
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import argparse
+import sys
+import os 
+import time
+import datetime
+import tempfile
+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='Tajo 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('-skip-rb', '--skip-reviewboard', action='store_true', dest='skip_reviewboard', required=False, help='Skip a review request to 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('-c', '--change-description', action='store', dest='change_description', required=False, help='Description of what changed in this revision of the review request when updating an existing request')
+  popt.add_argument('-pa', '--patch-available', action='store_true', dest='patch_available', required=False, help='Transite the JIRA status to Patch Available. If its status is already Patch Available, it updates the status of the JIRA issue by transiting its status to Open and Patch Available sequentially.')
+  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()
+
+  # the patch name is determined here.
+  patch_file=tempfile.gettempdir() + "/" + opt.jira + ".patch"
+  if opt.reviewboard:
+    ts = time.time()
+    st = datetime.datetime.fromtimestamp(ts).strftime('%Y%m%d_%H:%M:%S')
+    patch_file=tempfile.gettempdir() + "/" + opt.jira + '_' + st + '.patch'
+
+  # first check if rebase is needed
+  git_branch_hash="git rev-parse " + opt.branch
+  p_now=os.popen(git_branch_hash)
+  branch_now=p_now.read()
+  p_now.close()
+
+  git_common_ancestor="git merge-base " + opt.branch + " HEAD"
+  p_then=os.popen(git_common_ancestor)
+  branch_then=p_then.read()
+  p_then.close()
+
+  # get remote and branch name
+  remote_name=opt.branch.split("/")[0]
+  branch_name=opt.branch.split("/")[1]
+
+  if branch_now != branch_then:
+    print 'ERROR: Your current working branch is from an older version of ' + opt.branch + '. Please rebase first by using git pull --rebase'
+    sys.exit(1)
+
+  git_configure_reviewboard="git config reviewboard.url https://reviews.apache.org"
+  print "Configuring reviewboard url to https://reviews.apache.org"
+  p=os.popen(git_configure_reviewboard)
+  p.close()
+
+  # update the specified remote branch
+  git_remote_update="git fetch " + remote_name
+  print "Updating your remote branche " + opt.branch + " to pull the latest changes"
+  p=os.popen(git_remote_update)
+  p.close()
+
+  # get jira and issue instance 
+  jira=get_jira()
+  issue = jira.issue(opt.jira)
+
+  if not opt.skip_reviewboard:
+    rb_command="post-review --publish --tracking-branch " + opt.branch + " --target-groups=Tajo --branch=" + branch_name + " --bugs-closed=" + opt.jira
+    if opt.reviewboard:
+      rb_command=rb_command + " -r " + opt.reviewboard
+    summary=issue.key + ": " + issue.fields.summary # default summary is 'TAJO-{NUM}: {JIRA TITLE}'
+    if opt.summary: # if a summary is given, this field is added or updated
+      summary=opt.summary
+    if not opt.reviewboard: # if a review request is created
+      rb_command=rb_command + " --summary '" + summary + "'"
+    description=issue.fields.description 
+    if opt.description: # if a descriptin is give, this field is added
+      description = opt.description
+    if opt.reviewboard and opt.change_description:
+      rb_command=rb_command + " --change-description '" + opt.change_description + "'"
+    if not opt.reviewboard: # if a review request is created
+      rb_command=rb_command + " --description '" + description + "'"
+    if opt.testing:
+      rb_command=rb_command + " --testing-done=" + opt.testing
+    if opt.debug:
+      rb_command=rb_command + " --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: Your reviewboard was not created/updated since there was no diff to upload. The reasons that can cause this issue are 1) Your diff is not checked into your local branch. Please check in the diff to the local branch and retry 2) You are not specifying the local branch name as part of the --branch option. Please specify the remote branch name obtained from git branch -r'
+        p.close()
+        sys.exit(1)
+      elif line.startswith("Your review request still exists, but the diff is not attached") and not opt.debug:
+        print 'ERROR: Your reviewboard was not created/updated. Please run the script with the --debug option to troubleshoot the problem'
+        p.close()
+        sys.exit(1)
+    p.close()
+    if opt.debug: 
+      print 'rb url=',rb_url
+ 
+  git_command="git diff --no-prefix " + 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 ',opt.jira
+  attachment=open(patch_file)
+  jira.add_attachment(issue,attachment)
+  attachment.close()
+
+  # Add comment about a request to reviewboard and its url.
+  if not opt.skip_reviewboard:
+    comment="Created a review request against branch " + branch_name + " in reviewboard " 
+    if opt.reviewboard:
+      comment="Updated the review request against branch " + branch_name + " in reviewboard "
+
+    comment = comment + "\n" + rb_url
+    jira.add_comment(opt.jira, comment)
+
+  # Transition the jira status to Patch Available
+  if opt.patch_available:
+    if issue.fields.status.id == '10002': # If the jira status is already Patch Available (id - 10002)
+      jira.transition_issue(issue, '731') # Cancel (id - 731) the uploaded patch
+      issue = jira.issue(opt.jira)
+    jira.transition_issue(issue, '10002')
+
+if __name__ == '__main__':
+  sys.exit(main())
+

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/568c5239/tajo-project/src/site/markdown/review-request-tool.md
----------------------------------------------------------------------
diff --git a/tajo-project/src/site/markdown/review-request-tool.md b/tajo-project/src/site/markdown/review-request-tool.md
new file mode 100644
index 0000000..d32a20b
--- /dev/null
+++ b/tajo-project/src/site/markdown/review-request-tool.md
@@ -0,0 +1,191 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+## Table of Contents
+
+* [Tajo Review Request Tool] (#ReviewTool)
+ * [Setup](#Setup)
+ * [Usage](#Usage)
+ * [Upload the first patch] (#UploadFirstPatch)
+ * [Update the existing patch] (#UpdatePatch)
+* [Preparation] (#Preparation)
+ * [Jira command line tool] (#JiraTool)
+ * [Reviewboard] (#Reviewboard)
+* [FAQ] (#FAQ)
+
+## <a name="ReviewTool"></a>Tajo Review Request Tool
+
+### <a name="Setup"></a>Setup
+ 1. Follow instructions here to [setup the jira-python package] (#JiraTool)
+ 1. Follow instructions here to [setup the reviewboard python tools] (#Reviewboard)
+ 1. Install the argparse module
+ 
+Linux
+
+```
+sudo yum install python-argparse
+```
+
+Mac
+
+```
+sudo easy_install argparse
+```
+
+### <a name="Usage"></a>Usage
+
+```
+$ ./request-patch-review.py --help
+usage: request-patch-review.py [-h] -b BRANCH -j JIRA [-skip-rb] [-s SUMMARY]
+                               [-d DESCRIPTION] [-c CHANGE_DESCRIPTION] [-pa]
+                               [-r REVIEWBOARD] [-t TESTING] [-db]
+
+Kafka patch review tool
+
+optional arguments:
+  -h, --help            show this help message and exit
+  -b BRANCH, --branch BRANCH
+                        Tracking branch to create diff against
+  -j JIRA, --jira JIRA  JIRA corresponding to the reviewboard
+  -skip-rb, --skip-reviewboard
+                        Skip a review request to reviewboard.
+  -s SUMMARY, --summary SUMMARY
+                        Summary for the reviewboard
+  -d DESCRIPTION, --description DESCRIPTION
+                        Description for reviewboard
+  -c CHANGE_DESCRIPTION, --change-description CHANGE_DESCRIPTION
+                        Description of what changed in this revision of the
+                        review request when updating an existing request
+  -pa, --patch-available
+                        Transite the JIRA status to Patch Available. If its
+                        status is already Patch Available, it updates the
+                        status of the JIRA issue by transiting its status to
+                        Open and Patch Available sequentially.
+  -r REVIEWBOARD, --rb REVIEWBOARD
+                        Review board that needs to be updated
+  -t TESTING, --testing-done TESTING
+                        Text for the Testing Done section of the reviewboard
+  -db, --debug          Enable debug mode
+
+```
+
+### <a name="UploadFirstPatch"></a> Upload the first patch
+**You should create a jira issue prior to a patch review request.**
+
+ * Specify the branch against which the patch should be created (-b)
+ * Specify the corresponding JIRA (-j)
+ * Specify an optional summary (-s) and description (-d) for the reviewboard
+  * If they are not given, the summary and description of the first review request in reviewboard are borrowed from the corresponding JIRA issue.
+ 
+Example:
+
+```
+$ ./request-patch-review.py -b origin/master -j TAJO-543
+```
+
+### <a name="UpdatePatch"></a>Update the existing patch
+ * Specify the remote branch against which the patch should be created (-b)
+ * Specify the corresponding JIRA (--jira)
+ * Specify the rb to be updated (-r)
+ * Specify an optional summary (-s) and description (-d) for the reviewboard, if you want to update them.
+ * Specify a change description (-c) for the reviewboard, if you want to describe it. The change description is what changed in this revision of the review request.
+ 
+Example:
+
+```
+$ ./request-patch-review.py -b origin/master -j TAJO-543 -r 14081 -c "Add more unit tests"
+```
+
+## <a name="Preparation"></a>Preparation
+### <a name="JiraTool"></a>JIRA command line tool
+ 1. Download the JIRA command line package
+
+Install the jira-python package
+
+```
+sudo easy_install jira-python
+```
+
+ 2. Configure JIRA username and password
+ 
+Create a ${HOME}/.jira.ini file in your $HOME directory that contains your Apache JIRA username and password
+
+```
+$ cat ~/.jira.ini
+user=hyunsik
+password=***********
+```
+
+### <a name="Reviewboard"></a>Reviewboard
+This is a quick tutorial on using Review Board with Tajo.
+
+#### 1. Install the post-review tool
+If you are on RHEL, Fedora or CentOS, follow these steps
+
+```
+sudo yum install python-setuptools
+sudo easy_install -U RBTools
+```
+
+If you are on Mac, follow these steps
+
+```
+sudo easy_install -U setuptools
+sudo easy_install -U RBTools
+```
+
+For other platforms, follow the instructions here to setup the post-review tool.
+
+
+#### 2. Configure Stuff
+Then you need to configure a few things to make it work:
+First set the review board url to use. You can do this from in git:
+
+```
+git config reviewboard.url https://reviews.apache.org
+```
+
+If you checked out using the git wip http url that confusingly won't work with review board. So you need to configure an override to use the non-http url. You can do this by adding a config file like this:
+
+```
+$ cat ~/.reviewboardrc
+REPOSITORY = 'git://git.apache.org/incubator-tajo.git'
+TARGET_GROUPS = 'Tajo'
+```
+
+## <a name="FAR"></a>FAQ
+**When I run the script, it throws the following error and exits**
+
+```
+$ tajo-patch-review.py -b asf/master -j TAJO-593
+There don't seem to be any diffs
+```
+
+There are 2 reasons that can cause this -
+ * The code is not checked into your local branch
+ * The -b branch is not pointing to the remote branch. In the example above, "master" is specified as the branch, which is the local branch. The correct value for the -b (--branch) option is the remote branch. "git branch -r" gives the list of the remote branch names.
+ 
+**When I run the script, it throws the following error and exits**
+
+```
+Error uploading diff
+
+Your review request still exists, but the diff is not attached.
+```
+
+One of the most common root causes of this error are that the git remote branches are not up-to-date. Since the script already does that, it is probably due to some other problem. You can run the script with the --debug option that will make post-review run in the debug mode and list the root cause of the issue.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/568c5239/tajo-project/src/site/site.xml
----------------------------------------------------------------------
diff --git a/tajo-project/src/site/site.xml b/tajo-project/src/site/site.xml
index 746d670..6cf6c0c 100644
--- a/tajo-project/src/site/site.xml
+++ b/tajo-project/src/site/site.xml
@@ -104,6 +104,7 @@
       <item name="Get Involved" href="http://www.apache.org/foundation/getinvolved.html" />
       <item name="How To Contribute" href="http://wiki.apache.org/tajo/HowToContribute" />
       <item name="Review Board" href="https://reviews.apache.org/groups/tajo" />
+      <item name="Review Request Tool" href="review-request-tool.html" />
       <item name="Coding Style" href="http://wiki.apache.org/tajo/CodingStyle" />
     </menu>