-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathcrbug.py
136 lines (112 loc) · 5.13 KB
/
crbug.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
#!/usr/bin/env python
#################################################################################################
#
# crbug.py -- Create a Bug, populate the Abundanza multi-select field in the 'Jira 7 Testing'
# workspace
#
USAGE = """
Usage: crbug.py
"""
#################################################################################################
import sys, os
from pyral import Rally, rallyWorkset
#################################################################################################
errout = sys.stderr.write
#################################################################################################
def main(args):
options = [opt for opt in args if opt.startswith('--')]
args = [arg for arg in args if arg not in options]
server, user, password, apikey, workspace, project = rallyWorkset(options)
if apikey:
rally = Rally(server, apikey=apikey, workspace=workspace, project=project)
else:
rally = Rally(server, user=user, password=password, workspace=workspace, project=project)
# rally.enableLogging("rally.history.crbug")
target_project = rally.getProject()
target_entity_name = 'Defect'
target_attribute_name = 'Abundanza'
allowed_values = []
candidate_values = ['bosch', 'rybosome', 'stihl', 'snap-on']
value_refs = []
type_schema_attrs = rally.typedef(target_entity_name).Attributes
ts_hits = [attr_schema for attr_schema in type_schema_attrs
if attr_schema.ElementName == f'c_{target_attribute_name}']
if ts_hits:
tsa = ts_hits[0]
allowed_values = tsa.AllowedValues
def notFound(target_value, allowed_values):
hits = [aavs.value for aavs in allowed_values
if aavs.value == target_value]
return True if not hits else False
if allowed_values:
disallowed_values = [cand_val for cand_val in candidate_values
if notFound(cand_val, allowed_values)]
if disallowed_values:
for dav in disallowed_values:
print(f'WARNING: {dav} is not an allowed value for the {target_entity_name}.{target_attribute_name} field')
candidate_values = list(set(candidate_values) - set(disallowed_values))
value_refs = getAllowedValueRefs(candidate_values, allowed_values)
info = {
"Project" : target_project.ref,
"Name" : "Mushy fries sicken our customers",
"State" : "Submitted",
"ScheduleState" : "Defined",
"Description" : "revolt is soon to arrive at your franchise",
"Notes" : "I have really only done some daydreaming wrt this defect",
#"Abundanza" : "bosch,stihl,snap-on"
"Abundanza" : value_refs
}
print("Creating Defect ...")
defect = rally.put('Defect', info)
print("Created Defect: %s OID: %s" % (defect.FormattedID, defect.oid))
#abund = defect.Abundanza
abund = defect.c_Abundanza
if abund:
abund = ", ".join([aav.value for aav in abund])
else:
abund = ''
print(f' Abundanza: {abund}')
#print(repr(defect.__dict__))
#print(defect.details())
#################################################################################################
def getAllowedValueRefs(specified_values, allowed_values_schema):
"""
Turn the specified values into refs to the corresponding
allowedattributevalue items.
have to return a structure like:
[
{'_ref' : 'allowedattributevalue/875421254' },
{'_ref' : 'allowedattributevalue/875432439' },
...
]
"""
ref_box = []
for aav_text in specified_values:
hits = [aavs.ref for aavs in allowed_values_schema
if aavs.value == aav_text]
if hits:
ref = hits[0]
ref_box.append({'_ref' : ref})
return ref_box
#################################################################################################
def emptyDefect():
task = {'Workspace' : '',
'Project' : '',
'Name' : '',
'State' : '',
'ScheduleState' : '',
}
return task
#################################################################################################
def queryForDefects(rally):
response = rally.get('Defect', fetch=True)
# a response has status_code, content and data attributes
for defect in response:
#print "%s %s %s %s" % (defect.__class__.__name__, defect.oid, defect.name, defect._ref)
print("%s %s %s %s %s %s" % (defect.FormattedID, defect.Name,
defect.Workspace.Name, defect.Project.Name,
defect.Release.Name, defect.Iteration.Name))
#################################################################################################
#################################################################################################
if __name__ == '__main__':
main(sys.argv[1:])