-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_jiras.py
executable file
·38 lines (32 loc) · 1.06 KB
/
get_jiras.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
##
# Authored by Erik Babel and Travis Wyatt; modified by Chris Corea
##
import json
import re
from macpath import split
jsonString = open("build_json.txt").read()
parsed = json.loads(jsonString)
changeset = parsed['changeSet']
changes = changeset['items']
# RegEx pattern captures one or more JIRA ticket names from a commit message.
#
# Examples of allowed commit messages:
# [PRO-1234] message
# [jira PRO-1234] message
# [jira:PRO-1234] message
# [PRO-1234,PRO-133] message
# [jira:PRO-1234,PRO-133] message
# [jira:PRO-1234,jira:PRO-133] message
# [PRO-1234,PRO-133;RTL-6213] message
# [PRO-1234;PRO-133,rtl-6213] message
pattern = "^\[((?:(?:jira\:?\s*)?\w+-\d+[,;]?[\s]?)+)+\].*$"
p = re.compile(pattern, re.IGNORECASE)
jiras = []
for change in changes:
m = p.match(change['msg'])
if m:
names = re.split('[,; ]', m.groups()[0])
jiras.extend([x.lstrip('jira:').lstrip('JIRA:').lstrip('jira').lstrip('JIRA').strip() for x in names])
jiras = list(set(jiras)) # remove duplicates (order is lost)
print ' '.join(jiras)