3030import subprocess
3131import sys
3232import urllib2
33+ import Queue
3334
3435try :
3536 import jira .client
@@ -286,6 +287,42 @@ def resolve_jira_issues(title, merge_branches, comment):
286287 resolve_jira_issue (merge_branches , comment , jira_id )
287288
288289
290+ def standardize_jira_ref (text ):
291+ # Standardize the [MODULE] SPARK-XXXXX prefix
292+ # Converts "[SPARK-XXX][mllib] Issue", "[MLLib] SPARK-XXX. Issue" or "SPARK XXX [MLLIB]: Issue" to "[MLLIB] SPARK-XXX: Issue"
293+
294+ # Check for compliance
295+ if (re .search (r'\[[A-Z0-9_]+\] SPARK-[0-9]{4,5}: \S+' , text )):
296+ return text
297+
298+ # Extract JIRA ref(s):
299+ jira_refs = Queue .Queue ()
300+ pattern = re .compile (r'(SPARK[-\s]*[0-9]{4,5})' , re .IGNORECASE )
301+ while (pattern .search (text ) is not None ):
302+ jira_refs .put (re .sub (r'\s' , '-' , pattern .search (text ).groups ()[0 ].upper ()))
303+ text = text .replace (pattern .search (text ).groups ()[0 ], '' )
304+
305+ # Extract spark component(s):
306+ components = Queue .Queue ()
307+ pattern = re .compile (r'(\[\w+\])' , re .IGNORECASE )
308+ while (pattern .search (text ) is not None ):
309+ components .put (pattern .search (text ).groups ()[0 ])
310+ text = text .replace (pattern .search (text ).groups ()[0 ], '' )
311+
312+ # Cleanup remaining symbols:
313+ pattern = re .compile (r'\W+(.*)' , re .IGNORECASE )
314+ text = pattern .search (text ).groups ()[0 ]
315+
316+ # Assemble full text (module(s), JIRA ref(s), remaining text)
317+ clean_text = ''
318+ while (not components .empty ()):
319+ clean_text += components .get () + ' '
320+ while (not jira_refs .empty ()):
321+ clean_text += jira_refs .get () + ' '
322+ clean_text = clean_text .rstrip () + ': ' + text .strip ()
323+
324+ return clean_text
325+
289326branches = get_json ("%s/branches" % GITHUB_API_BASE )
290327branch_names = filter (lambda x : x .startswith ("branch-" ), [x ['name' ] for x in branches ])
291328# Assumes branch names can be sorted lexicographically
@@ -296,7 +333,7 @@ def resolve_jira_issues(title, merge_branches, comment):
296333pr_events = get_json ("%s/issues/%s/events" % (GITHUB_API_BASE , pr_num ))
297334
298335url = pr ["url" ]
299- title = pr ["title" ]
336+ title = standardize_jira_ref ( pr ["title" ])
300337body = pr ["body" ]
301338target_ref = pr ["base" ]["ref" ]
302339user_login = pr ["user" ]["login" ]
0 commit comments