-
Notifications
You must be signed in to change notification settings - Fork 0
/
pui_sprints.rb
308 lines (234 loc) · 9.57 KB
/
pui_sprints.rb
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
require 'HTTParty'
VC_BOARD_ID = 43
def init()
config = YAML.load(File.read('config/credentials.yml'))
@auth = {username: config['username'], password: config['password']}
@options = {basic_auth: @auth}
get_cl_arguments()
end
def get_cl_arguments()
args = Hash[ ARGV.flat_map{|s| s.scan(/--?([^=\s]+)(?:=(\S+))?/) } ]
if(args.key?('c')) then
@cycletimes = true
puts "cycle times on"
else
@cycletimes = false
end
end
def do_it()
stopwatch = Stopwatch.new
puts "$$$$$$$$$$$$$$$$$$"
latest_sprints = get_latest_sprints()
if(@cycletimes) then
puts "expanding the changelog for returned issues"
sprint_issue_data = get_sprint_issues_data(latest_sprints)
to_changelog_csv(sprint_issue_data)
puts "outputing cycle times"
to_cycle_times_csv(sprint_issue_data)
end
sprint_report_issue_data = get_sprint_report_issue_data(latest_sprints)
to_sprint_report_csv(sprint_report_issue_data)
puts "%%%%%%%%%%% Elapsed Time %%%%%%%%%%%%%"
stopwatch.elapsed_time
puts "%%%%%%%%%%% Elapsed Time %%%%%%%%%%%%%"
end
def get_latest_sprints()
puts "https://vitals.atlassian.net/rest/greenhopper/latest/sprintquery/#{VC_BOARD_ID}"
vc_sprints = HTTParty.get("https://vitals.atlassian.net/rest/greenhopper/latest/sprintquery/#{VC_BOARD_ID}", @options)
#earliest_sprint_id = 684 #Sprint 73
#earliest_sprint_id = 935 #Sprint 100 (17.3)
earliest_sprint_id = 850 #Sprint 91 (17.2)
latest_sprints = Hash.new
latest_sprints[VC_BOARD_ID] = []
vc_sprints["sprints"].each do |sprint|
sprint_sequence = Float(sprint["sequence"])
if(sprint_sequence >= earliest_sprint_id) then
latest_sprints[VC_BOARD_ID] << sprint
end
end
latest_sprints
end
def get_sprint_report_issue_data(latest_sprint_data)
sprint_report_issue_data = []
latest_sprint_data.each do |key, value|
value.each do |sprint|
sprint_id = sprint["id"]
sprint_data = get_sprint_report_issues(key,sprint_id)
sprint_name = sprint_data["sprint"]["name"]
puts "Sprint: #{sprint_name}, rapid board: #{key}"
sprint_end_date = DateTime.parse(sprint_data["sprint"]["endDate"]).strftime("%m/%d/%Y")
sprint_report_issues = []
sprint_data["contents"]["completedIssues"].collect { |issue| sprint_report_issue_data << {:sprint_name => sprint_name, :sprint_end_date => sprint_end_date, :team_board_id => key, :issue_data => issue } }
sprint_data["contents"]["puntedIssues"].collect { |issue| sprint_report_issue_data << {:sprint_name => sprint_name, :sprint_end_date => sprint_end_date, :team_board_id => key, :issue_data => issue } }
sprint_data["contents"]["issuesNotCompletedInCurrentSprint"].collect { |issue| sprint_report_issue_data << {:sprint_name => sprint_name, :sprint_end_date => sprint_end_date, :team_board_id => key, :issue_data => issue } }
end
end
sprint_report_issue_data
end
def get_sprint_issues_data(latest_sprint_data)
sprint_issue_data = []
latest_sprint_data.each do |key, value|
value.each do |sprint|
sprint_id = sprint["id"]
sprint_data = get_sprint_report_issues(key,sprint_id)
sprint_issues = []
sprint_data["contents"]["completedIssues"].collect { |issue| sprint_issues << issue }
sprint_data["contents"]["puntedIssues"].collect { |issue| sprint_issues << issue }
sprint_data["contents"]["issuesNotCompletedInCurrentSprint"].collect { |issue| sprint_issues << issue }
sprint_name = sprint_data["sprint"]["name"]
puts "Sprint: #{sprint_name}, rapid board: #{key}"
sprint_issues.each do |sprint_issue|
sprint_issue_data << get_current_issue_data(sprint_issue["key"], sprint_name)
end
end
end
sprint_issue_data
end
def get_sprint_report_issues(rapid_view_id,sprint_id)
uri = "https://vitals.atlassian.net/rest/greenhopper/latest/rapid/charts/sprintreport?rapidViewId=#{rapid_view_id}&sprintId=#{sprint_id}"
puts uri
HTTParty.get(uri, @options)
end
def get_current_issue_data(issue_key,sprint_name)
uri = "https://vitals.atlassian.net/rest/api/latest/search?jql=key=#{issue_key}&expand=changelog"
puts uri
query_result = HTTParty.get(uri, @options)
issues = query_result["issues"]
issue_count = issues.count
issue_data = nil
if(issue_count == 1) then
issue_data = issues[0]
else
puts "Error: unexpected results for #{issue_key}. Expected 1 result and got #{issue_count}"
end
issue_sprint_data = {:sprint_name => sprint_name, :issue_data => issue_data }
end
def get_sprint_report_csv_string(issues)
string_builder = StringIO.new
string_builder << "id,key,issue type,status,story points,sprint name, sprint end date, team\n"
issues.each do |issue|
id = issue[:issue_data]["id"]
key = issue[:issue_data]["key"]
sprint_name = issue[:sprint_name]
sprint_end_date = issue[:sprint_end_date]
issue_type = issue[:issue_data]["typeName"]
status = issue[:issue_data]["statusName"]
story_points = issue[:issue_data]["currentEstimateStatistic"]["statFieldValue"]["value"]
team = "Unknown Team"
if(issue[:team_board_id] == VC_BOARD_ID) then
team = "Vitals Choice"
end
string_builder << "#{id},"
string_builder << "#{key},"
string_builder << "#{issue_type},"
string_builder << "#{status},"
string_builder << "#{story_points},"
string_builder << "#{sprint_name},"
string_builder << "#{sprint_end_date},"
string_builder << "#{team}"
string_builder << "\n"
end
string_builder.string
end
def to_sprint_report_csv(issues)
out_file = File.new("pui_sprint_report_results.csv","w+")
out_file.write(get_sprint_report_csv_string(issues))
end
#returns cycle time in minutes
def get_cycle_times(issues)
cycle_times = Hash.new
issue_status_changes = Hash.new
#get issue change log sets
issues.select { |issue| issue[:issue_data]["fields"]["status"]["name"] == "Resolved" }.each do |issue|
key = issue[:issue_data]["key"]
issue_status_changes[key] = []
issue[:issue_data]["changelog"]["histories"].each do |history|
history["items"].select { |item| item["field"] == "status" }.each do |status_history|
history_created = DateTime.parse(history["created"])
issue_status_changes[key] << history_created
end
end
start_date = issue_status_changes[key].min
end_date = issue_status_changes[key].max
cycle_times[key] = ((end_date - start_date) * 24 * 60).floor
end
cycle_times
end
def to_cycle_times_csv(issues)
cycle_times = get_cycle_times(issues)
string_builder = StringIO.new
string_builder << "issue key, cycle time\n"
cycle_times.keys.each do |key|
string_builder << "#{key},"
string_builder << "#{cycle_times[key]}\n"
end
out_file = File.new("pui_sprint_cycle_times.csv", "w+")
out_file.write(string_builder.string)
end
def get_changelog_csv_string(issues)
string_builder = StringIO.new
string_builder << "issue_id,issue_key, history_id, history_author_name, history_author_display_name, history_author_avatarURL48x48, history_created, previous_history_created, history_item_field,"
string_builder << "history_item_fieldtype, history_item_from, history_item_fromString, history_item_to, history_item_toString\n"
issues.each do |issue|
id = issue[:issue_data]["id"]
key = issue[:issue_data]["key"]
histories = issue[:issue_data]["changelog"]["histories"]
previous_history_created = nil
histories.each do |history|
history_id = history["id"]
history_author_name = history["author"]["name"]
history_author_display_name = history["author"]["displayName"]
history_author_avatarURL48x48 = history["author"]["avatarUrls"]["48x48"]
history_created = DateTime.parse(history["created"]).strftime("%FT%R")
#filtered to only record status change history items...for now
history["items"].select { |item| item["field"] == "status" }.each do |item|
history_item_field = item["field"]
history_item_fieldtype = item["fieldtype"]
history_item_from = item["from"]
history_item_fromString = item["fromString"]
history_item_to = item["to"]
history_item_toString = item["toString"]
string_builder << "\"#{id}\","
string_builder << "\"#{key}\","
string_builder << "\"#{history_id}\","
string_builder << "\"#{history_author_name}\","
string_builder << "\"#{history_author_display_name}\","
string_builder << "\"#{history_author_avatarURL48x48}\","
string_builder << "\"#{history_created}\","
if(previous_history_created.nil?) then
string_builder << ","
elsif
string_builder << "\"#{previous_history_created}\","
end
string_builder << "\"#{history_item_field}\","
string_builder << "\"#{history_item_fieldtype}\","
string_builder << "\"#{history_item_from}\","
string_builder << "\"#{history_item_fromString}\","
string_builder << "\"#{history_item_to}\","
string_builder << "\"#{history_item_toString}\""
string_builder << "\n"
end
previous_history_created = history_created
end
end
string_builder.string
end
def to_changelog_csv(issues)
out_file = File.new("pui_sprint_results_changelog.csv","w+")
out_file.write(get_changelog_csv_string(issues))
end
class Stopwatch
def initialize()
@start = Time.now
end
def elapsed_time
now = Time.now
elapsed = now - @start
puts 'Started: ' + @start.to_s
puts 'Now: ' + now.to_s
puts 'Elapsed time: ' + elapsed.to_s + ' seconds'
elapsed.to_s
end
end
init()
do_it()