@@ -328,6 +328,8 @@ def exit(self):
328
328
help = "Patch command such as `git apply' or `patch'" , metavar = "COMMAND" )
329
329
parser .add_option ("-p" , "--strip" , dest = "strip" , default = "1" ,
330
330
help = "Remove <n> leading slashes from diff paths" , metavar = "N" )
331
+ parser .add_option ("--get-latest-patch" , dest = "get_latest_patch" ,
332
+ help = "Get the latest patch attached to JIRA" , action = "store_true" )
331
333
332
334
(options , args ) = parser .parse_args ()
333
335
if not (options .defect or options .filename ):
@@ -342,6 +344,10 @@ def exit(self):
342
344
print "FATAL: --post-results requires --password"
343
345
sys .exit (1 )
344
346
347
+ if options .get_latest_patch and not options .defect :
348
+ print "FATAL: --get-latest-patch requires --defect"
349
+ sys .exit (1 )
350
+
345
351
branch = options .branch
346
352
if options .output_dir and not options .output_dir .startswith ('/' ):
347
353
print "INFO: A temporary staging dir for output will be used to avoid deletion of output files during 'git reset'"
@@ -356,6 +362,7 @@ def exit(self):
356
362
run_tests = options .run_tests
357
363
post_results = options .post_results
358
364
strip = options .strip
365
+ get_latest_patch = options .get_latest_patch
359
366
patch_cmd = options .patch_cmd
360
367
result = Result ()
361
368
@@ -397,12 +404,11 @@ def post_jira_comment_and_exit():
397
404
if output_dir and not os .path .isdir (output_dir ):
398
405
os .makedirs (output_dir )
399
406
400
- # If defect parameter is specified let's download the latest attachment
401
- if defect :
407
+ def get_latest_patch ():
408
+ global jira_json , json , versions , branch , attachment , patch_contents , patch_file , fh
402
409
print "Defect: %s" % defect
403
410
jira_json = jira_get_defect (result , defect , username , password )
404
411
json = json .loads (jira_json )
405
-
406
412
# JIRA must be in Patch Available state
407
413
if '"Patch Available"' not in jira_json :
408
414
print "ERROR: Defect %s not in patch available state" % (defect )
@@ -417,19 +423,22 @@ def post_jira_comment_and_exit():
417
423
sys .exit (1 )
418
424
else :
419
425
print "INFO: Guessed branch as %s" % (branch )
420
-
421
426
attachment = jira_get_attachment (result , defect , username , password )
422
427
if not attachment :
423
428
print "ERROR: No attachments found for %s" % (defect )
424
429
sys .exit (1 )
425
-
426
430
result .attachment = attachment
427
-
428
431
patch_contents = jira_request (result , result .attachment , username , password , None , {}).read ()
429
432
patch_file = "%s/%s.patch" % (output_dir , defect )
430
-
431
433
with open (patch_file , 'a' ) as fh :
432
434
fh .write (patch_contents )
435
+
436
+ if defect :
437
+ # If defect parameter is specified let's download the latest attachment
438
+ get_latest_patch ()
439
+ if options .get_latest_patch :
440
+ print "Saving latest attachment of %s as %s/%s.patch" % (defect , output_dir , defect )
441
+ sys .exit (0 )
433
442
elif options .filename :
434
443
patch_file = options .filename
435
444
else :
0 commit comments