kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nehanarkh...@apache.org
Subject kafka git commit: KAFKA-2153 kafka-patch-review tool uploads a patch even if it is empty; reviewed by Neha Narkhede, Gwen Shapira
Date Mon, 04 May 2015 18:59:02 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk e40ebcff6 -> 944628b0f


KAFKA-2153 kafka-patch-review tool uploads a patch even if it is empty; reviewed by Neha Narkhede,
Gwen Shapira


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

Branch: refs/heads/trunk
Commit: 944628b0f5b5a7873c2bfd3d52c445b7ab0eaff3
Parents: e40ebcf
Author: Ashish Singh <asingh@cloudera.com>
Authored: Mon May 4 11:58:46 2015 -0700
Committer: Neha Narkhede <nehanarkhede@apache.org>
Committed: Mon May 4 11:58:53 2015 -0700

----------------------------------------------------------------------
 dev-utils/test-patch.py | 23 ++++++++++++++++-------
 kafka-patch-review.py   | 37 +++++++++++++++++++++++++++++++------
 2 files changed, 47 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/944628b0/dev-utils/test-patch.py
----------------------------------------------------------------------
diff --git a/dev-utils/test-patch.py b/dev-utils/test-patch.py
index 9d88a6e..66ec79f 100644
--- a/dev-utils/test-patch.py
+++ b/dev-utils/test-patch.py
@@ -328,6 +328,8 @@ parser.add_option("--patch-command", dest="patch_cmd", default="git apply",
                   help="Patch command such as `git apply' or `patch'", metavar="COMMAND")
 parser.add_option("-p", "--strip", dest="strip", default="1",
                   help="Remove <n> leading slashes from diff paths", metavar="N")
+parser.add_option("--get-latest-patch", dest="get_latest_patch",
+                  help="Get the latest patch attached to JIRA", action="store_true")
 
 (options, args) = parser.parse_args()
 if not (options.defect or options.filename):
@@ -342,6 +344,10 @@ if options.post_results and not options.password:
   print "FATAL: --post-results requires --password"
   sys.exit(1)
 
+if options.get_latest_patch and not options.defect:
+    print "FATAL: --get-latest-patch requires --defect"
+    sys.exit(1)
+
 branch = options.branch
 if options.output_dir and not options.output_dir.startswith('/'):
   print "INFO: A temporary staging dir for output will be used to avoid deletion of output
files during 'git reset'"
@@ -356,6 +362,7 @@ password = options.password
 run_tests = options.run_tests
 post_results = options.post_results
 strip = options.strip
+get_latest_patch = options.get_latest_patch
 patch_cmd = options.patch_cmd
 result = Result()
 
@@ -397,12 +404,11 @@ if output_dir.endswith("/"):
 if output_dir and not os.path.isdir(output_dir):
   os.makedirs(output_dir)
 
-# If defect parameter is specified let's download the latest attachment
-if defect:
+def get_latest_patch():
+  global jira_json, json, versions, branch, attachment, patch_contents, patch_file, fh
   print "Defect: %s" % defect
   jira_json = jira_get_defect(result, defect, username, password)
   json = json.loads(jira_json)
-
   # JIRA must be in Patch Available state
   if '"Patch Available"' not in jira_json:
     print "ERROR: Defect %s not in patch available state" % (defect)
@@ -417,19 +423,22 @@ if defect:
       sys.exit(1)
     else:
       print "INFO: Guessed branch as %s" % (branch)
-
   attachment = jira_get_attachment(result, defect, username, password)
   if not attachment:
     print "ERROR: No attachments found for %s" % (defect)
     sys.exit(1)
-
   result.attachment = attachment
-
   patch_contents = jira_request(result, result.attachment, username, password, None, {}).read()
   patch_file = "%s/%s.patch" % (output_dir, defect)
-
   with open(patch_file, 'a') as fh:
     fh.write(patch_contents)
+
+if defect:
+  # If defect parameter is specified let's download the latest attachment
+  get_latest_patch()
+  if options.get_latest_patch:
+    print "Saving latest attachment of %s as %s/%s.patch" % (defect, output_dir, defect)
+    sys.exit(0)
 elif options.filename:
   patch_file = options.filename
 else:

http://git-wip-us.apache.org/repos/asf/kafka/blob/944628b0/kafka-patch-review.py
----------------------------------------------------------------------
diff --git a/kafka-patch-review.py b/kafka-patch-review.py
index 9592680..b5a2e95 100644
--- a/kafka-patch-review.py
+++ b/kafka-patch-review.py
@@ -99,6 +99,37 @@ def main():
     print "Failed to login to the JIRA instance", sys.exc_info()[0], sys.exc_info()[1]
     sys.exit(1)
 
+  git_command="git format-patch " + opt.branch + " --stdout > " + patch_file
+  if opt.debug:
+    print git_command
+  p=os.popen(git_command)
+  p.close()
+
+  print 'Getting latest patch attached to the JIRA'
+  tmp_dir = tempfile.mkdtemp()
+  get_latest_patch_command="python ./dev-utils/test-patch.py --get-latest-patch --defect
" + opt.jira + " --output " + tmp_dir + " > /dev/null 2>&1"
+  p=os.popen(get_latest_patch_command)
+  p.close()
+
+  previous_patch=tmp_dir + "/" + opt.jira + ".patch"
+  diff_file=tmp_dir + "/" + opt.jira + ".diff"
+  if os.path.isfile(previous_patch) and os.stat(previous_patch).st_size > 0:
+    print 'Creating diff with previous version of patch uploaded to JIRA'
+    diff_command = "diff " + previous_patch+ " " + patch_file + " > " + diff_file
+    try:
+      p=os.popen(diff_command)
+      sys.stdout.flush()
+      p.close()
+    except:
+      pass
+    print 'Diff with previous version of patch uploaded to JIRA is saved to ' + diff_file
+
+    print 'Checking if the there are changes that need to be pushed'
+    if os.stat(diff_file).st_size == 0:
+      print 'No changes found on top of changes uploaded to JIRA'
+      print 'Aborting'
+      sys.exit(1)
+
   rb_command= post_review_tool + " --publish --tracking-branch " + opt.branch + " --target-groups=kafka
--bugs-closed=" + opt.jira
   if opt.debug:
     rb_command=rb_command + " --debug"
@@ -134,12 +165,6 @@ def main():
   if opt.debug:
     print 'rb url=',rb_url
 
-  git_command="git format-patch " + opt.branch + " --stdout > " + 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
   issue = jira.issue(opt.jira)
   attachment=open(patch_file)


Mime
View raw message