Skip to content

Commit 4f1ed46

Browse files
committed
Deque removal, logic simplifications, & prompt user to pick a title (orig or modified)
1 parent df73f6a commit 4f1ed46

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

dev/merge_spark_pr.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import subprocess
3131
import sys
3232
import urllib2
33-
from collections import deque
3433

3534
try:
3635
import jira.client
@@ -300,51 +299,42 @@ def standardize_jira_ref(text):
300299
'[SPARK-1146] [WIP] Vagrant support for Spark'
301300
>>> standardize_jira_ref("SPARK-1032. If Yarn app fails before registering, app master stays aroun...")
302301
'[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'
303306
"""
307+
jira_refs = []
308+
components = []
309+
304310
# If the string is compliant, no need to process any further
305311
if (re.search(r'^\[SPARK-[0-9]{3,6}\] (\[[A-Z0-9_\s,]+\] )+\S+', text)):
306312
return text
307313

308314
# 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
314318
jira_refs.append('[' + re.sub(r'\s+', '-', ref.upper()) + ']')
315319
text = text.replace(ref, '')
316320

317321
# Extract spark component(s):
318-
components = deque()
319322
# Look for alphanumeric chars, spaces, dashes, periods, and/or commas
320323
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):
324325
components.append(component.upper())
325326
text = text.replace(component, '')
326327

327-
# Cleanup remaining symbols:
328+
# Cleanup any remaining symbols:
328329
pattern = re.compile(r'^\W+(.*)', re.IGNORECASE)
329330
if (pattern.search(text) is not None):
330331
text = pattern.search(text).groups()[0]
331332

332333
# 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()
339335

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())
348338

349339
return clean_text
350340

@@ -362,6 +352,21 @@ def main():
362352
pr_events = get_json("%s/issues/%s/events" % (GITHUB_API_BASE, pr_num))
363353

364354
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+
365370
title = standardize_jira_ref(pr["title"])
366371
body = pr["body"]
367372
target_ref = pr["base"]["ref"]

0 commit comments

Comments
 (0)