This repository has been archived by the owner on Aug 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.py
60 lines (54 loc) · 2.11 KB
/
client.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
'''Rally client.'''
from pyral import Rally, rallySettings
import simplejson as json
class RallyClient:
rally = None
debug = False
PrefixActionMap = {"US": "HierarchicalRequirement", "DE": "Defect" }
def __init__(self, config):
self.rally = Rally(config.rallyUrl, config.username, config.password, workspace="Betfair", project="Betfair")
self.rally.enableLogging('rallycli.log')
self.debug = config.debug
def retrieveItems(self, itemIds):
''' Use pyral to retrieve items from Rally. '''
items = {}
for itemId in itemIds:
query_criteria = 'formattedID = "%s"' % itemId
prefix = itemId[0:2]
response = self.rally.get(self.PrefixActionMap[prefix], fetch=True, query=query_criteria)
if self.debug:
print response.content
if response.errors:
sys.stdout.write("\n".join(response.errors))
print "ERROR"
sys.exit(1)
for item in response: # there should only be one qualifying item
# items[itemId] = item
# print "%s: %s (%s)" % (item.FormattedID, item.Name, item.Project.Name)
items[item.FormattedID] = item
return items
def info(self, args):
''' Return information for specified work items, in a variety of formats. '''
itemIds = args.workItems
# print "Retrieving items %s..." % (itemIds)
items = self.retrieveItems(itemIds)
for itemId, item in items.iteritems():
if item == None:
print "ERROR: Could not retrieve item %s from Rally" % itemId
else:
# print item.attributes()
# print item.ObjectID
# @TODO Refactor these into configurable/dynamic values
baseUrl = "https://rally1.rallydev.com/#"
workspaceId = "3254856811d"
itemUrl = "%s/%s/detail/userstory/%s" % (baseUrl, workspaceId, item.ObjectID)
if args.format == "confluence" :
print "# [%s: %s|%s]" % (itemId, item.Name, itemUrl)
elif args.format == "conftable" :
print "| %s | %s | %s |" % (itemId, item.Name, itemUrl)
elif args.format == "csv":
print "%s,%s,%s" % (itemId, item.Name, itemUrl)
elif args.format == "tsv":
print "%s\t%s\t%s" % (itemId, item.Name, itemUrl)
else:
print "%s: %s (%s)" % (itemId, item.Name, itemUrl)