30
30
import subprocess
31
31
import sys
32
32
import urllib2
33
- from collections import deque
34
33
35
34
try :
36
35
import jira .client
@@ -300,51 +299,42 @@ def standardize_jira_ref(text):
300
299
'[SPARK-1146] [WIP] Vagrant support for Spark'
301
300
>>> standardize_jira_ref("SPARK-1032. If Yarn app fails before registering, app master stays aroun...")
302
301
'[SPARK-1032] If Yarn app fails before registering, app master stays aroun...'
302
+ >>> standardize_jira_ref("[SPARK-6250][SPARK-6146][SPARK-5911][SQL] Types are now reserved words in DDL parser.")
303
+ '[SPARK-6250] [SPARK-6146] [SPARK-5911] [SQL] Types are now reserved words in DDL parser.'
304
+ >>> standardize_jira_ref("Additional information for users building from source code")
305
+ 'Additional information for users building from source code'
303
306
"""
307
+ jira_refs = []
308
+ components = []
309
+
304
310
# If the string is compliant, no need to process any further
305
311
if (re .search (r'^\[SPARK-[0-9]{3,6}\] (\[[A-Z0-9_\s,]+\] )+\S+' , text )):
306
312
return text
307
313
308
314
# Extract JIRA ref(s):
309
- jira_refs = deque ()
310
- pattern = re .compile (r'(SPARK[-\s]*[0-9]{3,6})' , re .IGNORECASE )
311
- while (pattern .search (text ) is not None ):
312
- ref = pattern .search (text ).groups ()[0 ]
313
- # Replace any whitespace with a dash & convert to uppercase
315
+ pattern = re .compile (r'(SPARK[-\s]*[0-9]{3,6})+' , re .IGNORECASE )
316
+ for ref in pattern .findall (text ):
317
+ # Add brackets, replace spaces with a dash, & convert to uppercase
314
318
jira_refs .append ('[' + re .sub (r'\s+' , '-' , ref .upper ()) + ']' )
315
319
text = text .replace (ref , '' )
316
320
317
321
# Extract spark component(s):
318
- components = deque ()
319
322
# Look for alphanumeric chars, spaces, dashes, periods, and/or commas
320
323
pattern = re .compile (r'(\[[\w\s,-\.]+\])' , re .IGNORECASE )
321
- while (pattern .search (text ) is not None ):
322
- component = pattern .search (text ).groups ()[0 ]
323
- # Convert to uppercase
324
+ for component in pattern .findall (text ):
324
325
components .append (component .upper ())
325
326
text = text .replace (component , '' )
326
327
327
- # Cleanup remaining symbols:
328
+ # Cleanup any remaining symbols:
328
329
pattern = re .compile (r'^\W+(.*)' , re .IGNORECASE )
329
330
if (pattern .search (text ) is not None ):
330
331
text = pattern .search (text ).groups ()[0 ]
331
332
332
333
# Assemble full text (JIRA ref(s), module(s), remaining text)
333
- if (len (jira_refs ) < 1 ):
334
- jira_ref_text = ""
335
- jira_ref_text = ' ' .join (jira_refs ).strip ()
336
- if (len (components ) < 1 ):
337
- components = ""
338
- component_text = ' ' .join (components ).strip ()
334
+ clean_text = ' ' .join (jira_refs ).strip () + " " + ' ' .join (components ).strip () + " " + text .strip ()
339
335
340
- if (len (jira_ref_text ) < 1 and len (component_text ) < 1 ):
341
- clean_text = text .strip ()
342
- elif (len (jira_ref_text ) < 1 ):
343
- clean_text = component_text + ' ' + text .strip ()
344
- elif (len (component_text ) < 1 ):
345
- clean_text = jira_ref_text + ' ' + text .strip ()
346
- else :
347
- clean_text = jira_ref_text + ' ' + component_text + ' ' + text .strip ()
336
+ # Replace multiple spaces with a single space, e.g. if no jira refs and/or components were included
337
+ clean_text = re .sub (r'\s+' , ' ' , clean_text .strip ())
348
338
349
339
return clean_text
350
340
@@ -362,6 +352,21 @@ def main():
362
352
pr_events = get_json ("%s/issues/%s/events" % (GITHUB_API_BASE , pr_num ))
363
353
364
354
url = pr ["url" ]
355
+
356
+ # Decide whether to use the modified title or not
357
+ print "I've re-written the title as follows to match the standard format:"
358
+ print "Original: %s" % pr ["title" ]
359
+ print "Modified: %s" % standardize_jira_ref (pr ["title" ])
360
+ prompt = "Would you like to use the modified title?"
361
+ result = raw_input ("%s (y/n): " % prompt )
362
+ if result .lower () == "y" :
363
+ title = standardize_jira_ref (pr ["title" ])
364
+ print "Using modified title:"
365
+ else :
366
+ title = pr ["title" ]
367
+ print "Using original title:"
368
+ print title
369
+
365
370
title = standardize_jira_ref (pr ["title" ])
366
371
body = pr ["body" ]
367
372
target_ref = pr ["base" ]["ref" ]
0 commit comments