This repository was archived by the owner on Aug 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjira.py
53 lines (44 loc) · 1.98 KB
/
jira.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import text
from feed import FeedPoller
import re
class JiraPoller(FeedPoller):
"""
Polls a Jira RSS feed and formats changes to issue trackers.
"""
def __init__(self, base_url=None, **kw):
self.base_url = base_url
super(JiraPoller, self).__init__(**kw)
def parse(self, entry):
m = re.search(r'(CRM-[0-9]+)$', entry.link)
if (not m) or (entry.generator_detail.href != self.base_url):
return
issue = m.group(1)
if 'content' in entry:
details = entry.content[0].value
assignment_phrases = [
r"Changed the (?P<property>[^']+) to '(?P<value>[^']+)'",
r"Added the (?P<property>[^']+) '(?P<value>[^']+)'",
r"Removed the (?P<property>[^']+) '(?P<previous_value>[^']+)'",
]
assignments = dict()
to_strip = []
for pattern in assignment_phrases:
for m in re.finditer(pattern, details):
#if 'previous_value' in m.groupdict():
# normal_form = "%s:%s->%s" % (text.abbrevs(m.group('property')), m.group("previous_value"), m.group('value'))
#else:
if 'value' in m.groupdict():
assignments[text.abbrevs(m.group('property'))] = m.group('value')
to_strip.append(m.group(0))
revs = set()
for m in re.finditer(r'r=(\d+)', details):
revs.add(", r"+m.group(1))
normal_form_assignments = "|".join(["%s:%s" % (k, v) for k, v in assignments.items()])
for p in to_strip:
details = details.replace(p, "")
summary = "%s %s %s" % (normal_form_assignments, "".join(revs), details)
else:
summary = entry.summary
summary = text.strip(summary, truncate=True)
url = "%s/browse/%s" % (self.base_url, issue)
return "%s: %s %s -- %s" % (entry.usr_username, issue, summary, url)