-
Notifications
You must be signed in to change notification settings - Fork 0
/
activity.py
205 lines (181 loc) · 7.18 KB
/
activity.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
###
# Copyright (c) 2011, Chip Childers
# All rights reserved.
#
#
###
"""
The activity module holds the ActivityFeed and ActivityItem class
structures for reading and interpreting a Jira Studio activity
stream RSS feed.
"""
import feedparser
import urllib
class ActivityFeed():
"""A class to manipulate Jira Studio activity feeds"""
def __init__(self, url, username, password, last_known_update = None):
if url is None:
raise Exception, "You must provide a Jira Studio feed URL"
split_url = url.split("://")
self.url = ''.join([split_url[0],
"://",
urllib.quote(username),
":",
urllib.quote(password),
"@",
split_url[1]])
self.feed = feedparser.parse(self.url)
if last_known_update is None:
self.last_updated = self.feed.entries[5]['updated_parsed']
else:
self.last_updated = last_known_update
def find_next_item(self, force_latest = False):
"""
Queries the feed, and returns the next ActivityItem
"""
i = 9
while i > -1:
if self.feed.entries[i]['updated_parsed'] > self.last_updated:
self.last_updated = self.feed.entries[i]['updated_parsed']
return ActivityItem(self.feed.entries[i])
i = i - 1
if force_latest:
return (ActivityItem(self.feed.entries[0]))
return None
def update_feed(self):
"""Forces an update of the feed content from the server"""
self.feed = feedparser.parse(self.url)
class ActivityItem():
"""
ActivityItem is a class responsible for understanding
Jira Studio activity item syntax.
"""
streams_base = "http://streams.atlassian.com/"
bamboo_pass = ''.join([streams_base,
"syndication/verbs/bamboo/pass"])
bamboo_fail = ''.join([streams_base,
"syndication/verbs/bamboo/fail"])
bamboo_browse = 'https://mountdiablo.jira.com/builds/browse'
jira_update = 'http://activitystrea.ms/schema/1.0/update'
jira_post = 'http://activitystrea.ms/schema/1.0/post'
jira_reopen = ''.join([streams_base,
'syndication/verbs/jira/reopen'])
jira_resolve = ''.join([streams_base,
'syndication/verbs/jira/resolve'])
jira_close = ''.join([streams_base,
'syndication/verbs/jira/close'])
jira_browse = 'https://mountdiablo.jira.com/browse/'
crucible_verb = ''.join([streams_base,
'syndication/verbs/crucible/'])
general_post = 'http://activitystrea.ms/schema/1.0/post'
crucible_link = 'https://mountdiablo.jira.com/source/cru/'
fisheye_push = ''.join([streams_base,
'syndication/verbs/fisheye/push'])
fisheye_browse = 'https://mountdiablo.jira.com/source/changelog/EDISON?cs='
def __init__(self, entry):
self.entry = entry
self.updated = self.entry['updated_parsed']
self.action = None
self.status = None
self.id = None
self.url = None
self.actor = None
app = self.entry['atlassian_application']
if app == 'com.atlassian.fisheye':
self.application = 'Subversion'
self._fisheye_item()
elif app == 'com.atlassian.jira':
self._jira_item()
self.application = 'Jira'
elif app == 'com.atlassian.bamboo':
self.application = 'Bamboo'
self._bamboo_item()
else:
self.application = 'Unknown'
def get_summary(self):
"""Provides a simple string summary of an activity item"""
updatestring = ''
if self.application == "Bamboo":
updatestring = ''.join([
"New build ",
self.id,
" ",
self.status,
"! ",
self.url])
elif self.application == "Jira":
updatestring = ''.join([
self.actor,
" ",
self.action,
" ",
self.url])
elif self.application == "Subversion":
updatestring = ''.join([self.actor,
" ",
self.status,
" ",
self.url])
else:
updatestring = ''.join([self.actor,
" did something interesting, but I ",
"don't understand what."])
return updatestring
def _bamboo_item(self):
"""Interprets a bamboo activity item"""
self.action = 'Build'
self.actor = self.entry['usr_username']
if self.entry['activity_verb'] == ActivityItem.bamboo_pass:
self.status = 'Passed'
elif self.entry['activity_verb'] == ActivityItem.bamboo_fail:
self.status = 'Failed'
else:
self.status = 'Unknown'
for i in self.entry['links']:
if i['href'].startswith(ActivityItem.bamboo_browse):
self.id = i['href'].split('/browse/')[1]
self.url = i['href']
def _jira_item(self):
"""Interprets a Jira activity item"""
if self.entry['activity_verb'] == ActivityItem.jira_update:
self.action = 'Updated'
elif self.entry['activity_verb'] == ActivityItem.jira_post:
self.action = 'Updated'
elif self.entry['activity_verb'] == ActivityItem.jira_reopen:
self.action = 'Reopened'
elif self.entry['activity_verb'] == ActivityItem.jira_resolve:
self.action = 'Resolved'
elif self.entry['activity_verb'] == ActivityItem.jira_close:
self.action = 'Closed'
else:
self.action = 'Updated'
self.actor = self.entry['usr_username']
self.status = ''
for i in self.entry['links']:
if i['href'].startswith(ActivityItem.jira_browse):
self.id = i['href'].split('/browse/')[1]
self.url = i['href']
def _fisheye_item(self):
"""Interprets Fisheye and Crucible activity items"""
if self.entry['activity_verb'].startswith(
ActivityItem.crucible_verb) or \
self.entry['activity_verb'] == ActivityItem.general_post:
self.action = 'Review'
self.status = self.entry['activity_verb'].split('/crucible/')[1]
for i in self.entry['links']:
if i['href'].startswith(ActivityItem.crucible_link):
self.id = i['href'].split('/cru/')[1]
self.url = i['href']
elif self.entry['activity_verb'] == ActivityItem.fisheye_push:
self.action = 'Commit'
self.status = 'Committed'
for i in self.entry['links']:
if i['href'].startswith(ActivityItem.fisheye_browse):
self.id = i['href'].split('cs=')[1]
self.url = i['href']
else:
self.action = 'Unknown'
self.status = 'Unknown'
self.id = 'Unknown'
self.url = 'Unknown'
self.actor = self.entry['usr_username']