Class: Issue
- Inherits:
-
Object
show all
- Defined in:
- lib/jirametrics/issue.rb
Defined Under Namespace
Classes: SprintMembership, TrackedSprint
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#<=>(other) ⇒ Object
-
#all_subtask_activity_times ⇒ Object
-
#artificial? ⇒ Boolean
It's artificial if it wasn't downloaded from a Jira instance.
-
#assigned_to ⇒ Object
-
#assigned_to_icon_url ⇒ Object
-
#author ⇒ Object
-
#blocked_on_date?(date, end_time:) ⇒ Boolean
-
#blocked_stalled_by_date(date_range:, chart_end_time:, settings: nil) ⇒ Object
For any day in the day range...
-
#blocked_stalled_changes(end_time:, settings: nil) ⇒ Object
-
#compact_text(text, max: 60) ⇒ Object
-
#component_names ⇒ Object
-
#counts_as_sprint_start?(membership) ⇒ Boolean
Being added to a sprint only counts as a "start" if that sprint had actually started and the issue wasn't already done when it did.
-
#created ⇒ Object
-
#currently_in_status(*status_names) ⇒ Object
Are we currently in this status? If yes, then return the most recent status change.
-
#currently_in_status_category(*category_names) ⇒ Object
Are we currently in this status category? If yes, then return the most recent status change.
-
#discard_changes_before(cutoff_time) ⇒ Object
-
#discardable_before?(change, cutoff_time) ⇒ Boolean
-
#done? ⇒ Boolean
-
#due_date ⇒ Object
-
#dump ⇒ Object
-
#expedited? ⇒ Boolean
-
#expedited_on_date?(date) ⇒ Boolean
-
#expedited_ranges ⇒ Object
The date ranges during which this issue sat at an expedited priority.
-
#find_or_create_status(id:, name:) ⇒ Object
-
#find_sprint_start_end(sprint_id:, change:) ⇒ Object
-
#first_resolution ⇒ Object
-
#first_status_change_after_created ⇒ Object
-
#first_time_added_to_active_sprint ⇒ Object
If this issue is ever in an active sprint, returns the change where it was first added to that sprint (whether or not the sprint was active at that moment).
-
#first_time_in_or_right_of_column(column_name) ⇒ Object
-
#first_time_in_status(*status_names) ⇒ Object
-
#first_time_in_status_category(*category_names) ⇒ Object
-
#first_time_label_added(*labels) ⇒ Object
-
#first_time_not_in_status(*status_names) ⇒ Object
-
#first_time_visible_on_board ⇒ Object
-
#fix_versions ⇒ Object
-
#flow_efficiency_numbers(end_time:, settings: @board.project_config.settings) ⇒ Object
return [number of active seconds, total seconds] that this issue had up to the end_time.
-
#in_done_status_at?(time) ⇒ Boolean
Was the issue sitting in a done-category status at the given moment? Keys off the status category (not the status name), so a status merely called "Done" that Jira categorises otherwise won't count.
-
#in_initial_query? ⇒ Boolean
-
#initialize(raw:, board:, timezone_offset: '+00:00') ⇒ Issue
constructor
-
#inspect ⇒ Object
Many test failures are simply unreadable because the default inspect on this class goes on for pages.
-
#issue_links ⇒ Object
-
#key ⇒ Object
-
#key_as_i ⇒ Object
-
#labels ⇒ Object
-
#last_activity(now: Time.now) ⇒ Object
Return the last time there was any activity on this ticket.
-
#last_resolution ⇒ Object
-
#looks_like_issue_key?(key) ⇒ Boolean
-
#most_recent_status_change ⇒ Object
-
#parent_from_custom_fields(fields, project_config) ⇒ Object
-
#parent_key(project_config: @board.project_config) ⇒ Object
-
#parse_time(text) ⇒ Object
-
#priority_name ⇒ Object
-
#priority_url ⇒ Object
-
#raw_fields ⇒ Object
'fields' is the one part of the issue JSON that must always be present -- its absence means the payload is malformed.
-
#reasons_not_visible_on_board ⇒ Object
-
#resolution ⇒ Object
-
#sprint_entries_while_in_visible_status(visible_status_ids) ⇒ Object
-
#sprint_times_from_board(sprint_id) ⇒ Object
First look in the actual sprints json.
-
#sprint_times_from_issue(sprint_id, change) ⇒ Object
Then look at the sprints inside the issue.
-
#sprints ⇒ Object
-
#started_sprints ⇒ Object
-
#started_stopped_dates ⇒ Object
-
#started_stopped_times ⇒ Object
-
#status_changes ⇒ Object
-
#status_resolution_at_done ⇒ Object
-
#still_in_or_right_of_column(column_name) ⇒ Object
-
#still_in_status(*status_names) ⇒ Object
If it ever entered one of these statuses and it's still there then what was the last time it entered.
-
#still_in_status_category(*category_names) ⇒ Object
If it ever entered one of these categories and it's still there then what was the last time it entered.
-
#summary ⇒ Object
-
#time_created ⇒ Object
-
#type ⇒ Object
-
#type_icon_url ⇒ Object
-
#updated ⇒ Object
-
#url ⇒ Object
-
#visible_on_board? ⇒ Boolean
-
#visible_status_changes_in_active_sprint(visible_status_ids) ⇒ Object
Constructor Details
#initialize(raw:, board:, timezone_offset: '+00:00') ⇒ Issue
Returns a new instance of Issue.
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
|
# File 'lib/jirametrics/issue.rb', line 9
def initialize raw:, board:, timezone_offset: '+00:00'
@raw = raw
@timezone_offset = timezone_offset
@subtasks = []
@changes = []
@github_prs = []
@board = board
raise "No board for issue #{key}" if board.nil?
load_history_into_changes if @raw['changelog']
return unless @raw['fields']
if raw_fields['comment']
sort_changes!
@changes = [
fabricate_change(field_name: 'status'),
fabricate_change(field_name: 'priority'),
fabricate_sprint_change
].compact + @changes
rescue raise "Unable to initialize #{raw['key']}"
end
|
Instance Attribute Details
#board ⇒ Object
Returns the value of attribute board.
6
7
8
|
# File 'lib/jirametrics/issue.rb', line 6
def board
@board
end
|
#changes ⇒ Object
Returns the value of attribute changes.
6
7
8
|
# File 'lib/jirametrics/issue.rb', line 6
def changes
@changes
end
|
#discarded_change_times ⇒ Object
Returns the value of attribute discarded_change_times.
6
7
8
|
# File 'lib/jirametrics/issue.rb', line 6
def discarded_change_times
@discarded_change_times
end
|
#discarded_changes ⇒ Object
Returns the value of attribute discarded_changes.
6
7
8
|
# File 'lib/jirametrics/issue.rb', line 6
def discarded_changes
@discarded_changes
end
|
#github_prs ⇒ Object
Returns the value of attribute github_prs.
7
8
9
|
# File 'lib/jirametrics/issue.rb', line 7
def github_prs
@github_prs
end
|
#parent ⇒ Object
Returns the value of attribute parent.
7
8
9
|
# File 'lib/jirametrics/issue.rb', line 7
def parent
@parent
end
|
#raw ⇒ Object
Returns the value of attribute raw.
6
7
8
|
# File 'lib/jirametrics/issue.rb', line 6
def raw
@raw
end
|
#status ⇒ Object
70
71
72
73
|
# File 'lib/jirametrics/issue.rb', line 70
def status
@status ||= Status.from_raw(raw_fields['status'])
@status
end
|
#subtasks ⇒ Object
Returns the value of attribute subtasks.
6
7
8
|
# File 'lib/jirametrics/issue.rb', line 6
def subtasks
@subtasks
end
|
Instance Method Details
#<=>(other) ⇒ Object
556
557
558
559
560
561
562
|
# File 'lib/jirametrics/issue.rb', line 556
def <=> other
/(?<project_code1>[^-]+)-(?<id1>.+)/ =~ key
/(?<project_code2>[^-]+)-(?<id2>.+)/ =~ other.key
comparison = project_code1 <=> project_code2
comparison = id1.to_i <=> id2.to_i if comparison.zero?
comparison
end
|
#all_subtask_activity_times ⇒ Object
434
435
436
437
438
439
440
|
# File 'lib/jirametrics/issue.rb', line 434
def all_subtask_activity_times
subtask_activity_times = []
@subtasks.each do |subtask|
subtask_activity_times += subtask.changes.collect(&:time)
end
subtask_activity_times
end
|
#artificial? ⇒ Boolean
It's artificial if it wasn't downloaded from a Jira instance.
551
552
553
|
# File 'lib/jirametrics/issue.rb', line 551
def artificial?
@raw['exporter'].nil?
end
|
#assigned_to ⇒ Object
377
378
379
|
# File 'lib/jirametrics/issue.rb', line 377
def assigned_to
raw_fields['assignee']&.[]('displayName')
end
|
#assigned_to_icon_url ⇒ Object
381
382
383
|
# File 'lib/jirametrics/issue.rb', line 381
def assigned_to_icon_url
raw_fields['assignee']&.[]('avatarUrls')&.[]('16x16')
end
|
#author ⇒ Object
66
|
# File 'lib/jirametrics/issue.rb', line 66
def author = raw_fields['creator']&.[]('displayName') || ''
|
#blocked_on_date?(date, end_time:) ⇒ Boolean
391
392
393
|
# File 'lib/jirametrics/issue.rb', line 391
def blocked_on_date? date, end_time:
(blocked_stalled_by_date date_range: date..date, chart_end_time: end_time)[date].blocked?
end
|
#blocked_stalled_by_date(date_range:, chart_end_time:, settings: nil) ⇒ Object
For any day in the day range...
If the issue was blocked at any point in this day, the whole day is blocked.
If the issue was active at any point in this day, the whole day is active
If the day was stalled for the entire day then it's stalled
If there was no activity at all on this day then the last change from the previous day carries over
400
401
402
403
404
405
|
# File 'lib/jirametrics/issue.rb', line 400
def blocked_stalled_by_date date_range:, chart_end_time:, settings: nil
BlockedStalledByDateBuilder.new(
blocked_stalled_changes: blocked_stalled_changes(end_time: chart_end_time, settings: settings),
date_range: date_range
).build
end
|
#blocked_stalled_changes(end_time:, settings: nil) ⇒ Object
407
408
409
410
411
412
413
414
415
416
417
|
# File 'lib/jirametrics/issue.rb', line 407
def blocked_stalled_changes end_time:, settings: nil
settings ||= @board.project_config.settings
BlockedStalledChangeStreamBuilder.new(
changes: changes,
settings: settings,
created: created,
key: key,
subtask_activity_times: all_subtask_activity_times,
atlassian_document_format: @board.project_config.atlassian_document_format
).build(end_time: end_time)
end
|
#compact_text(text, max: 60) ⇒ Object
641
642
643
644
645
646
647
648
|
# File 'lib/jirametrics/issue.rb', line 641
def compact_text text, max: 60
return '' if text.nil?
text = @board.project_config.atlassian_document_format.to_text(text) if text.is_a? Hash
text = text.gsub(/\s+/, ' ').strip
text = "#{text[0...max]}..." if text.length > max
text
end
|
#component_names ⇒ Object
91
92
93
|
# File 'lib/jirametrics/issue.rb', line 91
def component_names
raw_fields['components']&.collect { |component| component['name'] } || []
end
|
#counts_as_sprint_start?(membership) ⇒ Boolean
Being added to a sprint only counts as a "start" if that sprint had actually started and the issue
wasn't already done when it did. Joining a sprint you've already finished (e.g. a done issue swept
into a later sprint) is bookkeeping on completed work, not the moment work began.
297
298
299
300
301
|
# File 'lib/jirametrics/issue.rb', line 297
def counts_as_sprint_start? membership
return false if membership.sprint_start.nil?
!in_done_status_at?(membership.sprint_start)
end
|
#created ⇒ Object
355
356
357
358
359
|
# File 'lib/jirametrics/issue.rb', line 355
def created
created_text = raw_fields['created']
parse_time created_text if created_text
end
|
#currently_in_status(*status_names) ⇒ Object
Are we currently in this status? If yes, then return the most recent status change.
161
162
163
164
165
166
|
# File 'lib/jirametrics/issue.rb', line 161
def currently_in_status *status_names
change = most_recent_status_change
return nil if change.nil?
change if change.current_status_matches(*status_names)
end
|
#currently_in_status_category(*category_names) ⇒ Object
Are we currently in this status category? If yes, then return the most recent status change.
169
170
171
172
173
174
175
176
177
|
# File 'lib/jirametrics/issue.rb', line 169
def currently_in_status_category *category_names
category_ids = find_status_category_ids_by_names category_names
change = most_recent_status_change
return nil if change.nil?
status = find_or_create_status id: change.value_id, name: change.value
change if status && category_ids.include?(status.category.id)
end
|
#discard_changes_before(cutoff_time) ⇒ Object
564
565
566
567
568
569
570
571
572
573
574
|
# File 'lib/jirametrics/issue.rb', line 564
def discard_changes_before cutoff_time
rejected_any = false
@changes.reject! do |change|
next false unless discardable_before? change, cutoff_time
(@discarded_changes ||= []) << change
rejected_any = true
end
(@discarded_change_times ||= []) << cutoff_time if rejected_any
end
|
#discardable_before?(change, cutoff_time) ⇒ Boolean
576
577
578
|
# File 'lib/jirametrics/issue.rb', line 576
def discardable_before? change, cutoff_time
change.status? && change.time <= cutoff_time && change.artificial? == false
end
|
#done? ⇒ Boolean
584
585
586
587
588
589
590
591
592
|
# File 'lib/jirametrics/issue.rb', line 584
def done?
if artificial? || board.cycletime.nil?
status.category.done?
else
board.cycletime.done? self
end
end
|
#due_date ⇒ Object
77
78
79
80
|
# File 'lib/jirametrics/issue.rb', line 77
def due_date
text = raw_fields['duedate']
text.nil? ? nil : Date.parse(text)
end
|
#dump ⇒ Object
580
581
582
|
# File 'lib/jirametrics/issue.rb', line 580
def dump
IssuePrinter.new(self).to_s
end
|
#expedited? ⇒ Boolean
442
443
444
445
446
447
448
|
# File 'lib/jirametrics/issue.rb', line 442
def expedited?
names = @board.project_config.settings['expedited_priority_names']
return false unless names
current_priority = raw['fields']['priority']&.[]('name')
names.include? current_priority
end
|
#expedited_on_date?(date) ⇒ Boolean
450
451
452
453
454
|
# File 'lib/jirametrics/issue.rb', line 450
def expedited_on_date? date
return false unless @board&.project_config
expedited_ranges.any? { |range| range.cover?(date) }
end
|
#expedited_ranges ⇒ Object
The date ranges during which this issue sat at an expedited priority. A range that never closes
(the issue was never de-prioritised) is endless.
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
|
# File 'lib/jirametrics/issue.rb', line 458
def expedited_ranges
expedited_names = @board.project_config.settings['expedited_priority_names']
ranges = []
started_on = nil
changes.each do |change|
next unless change.priority?
if expedited_names.include? change.value
started_on ||= change.time.to_date
elsif started_on
ranges << (started_on..change.time.to_date)
started_on = nil
end
end
ranges << (started_on..) if started_on
ranges
end
|
#find_or_create_status(id:, name:) ⇒ Object
179
180
181
182
|
# File 'lib/jirametrics/issue.rb', line 179
def find_or_create_status id:, name:
board.possible_statuses.find_by_id(id) ||
board.possible_statuses.fabricate_status_for(id: id, name: name, example_issue_key: key)
end
|
#find_sprint_start_end(sprint_id:, change:) ⇒ Object
312
313
314
315
316
317
318
319
320
321
322
323
|
# File 'lib/jirametrics/issue.rb', line 312
def find_sprint_start_end sprint_id:, change:
times = sprint_times_from_board(sprint_id) || sprint_times_from_issue(sprint_id, change)
times || [nil, nil]
end
|
#first_resolution ⇒ Object
369
370
371
|
# File 'lib/jirametrics/issue.rb', line 369
def first_resolution
@changes.find(&:resolution?)
end
|
#first_status_change_after_created ⇒ Object
184
185
186
|
# File 'lib/jirametrics/issue.rb', line 184
def first_status_change_after_created
status_changes.find { |change| change.artificial? == false }
end
|
#first_time_added_to_active_sprint ⇒ Object
If this issue is ever in an active sprint, returns the change where it was first added to that
sprint (whether or not the sprint was active at that moment). It's a reasonable proxy for 'ready'
when a team has no explicit 'ready' status -- you'd be better off with one, but sometimes that's
not an option. Only valid for Scrum boards.
rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
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
|
# File 'lib/jirametrics/issue.rb', line 249
def first_time_added_to_active_sprint
unless board.scrum?
raise 'first_time_added_to_active_sprint() can only be used with Scrum boards: ' \
"issue=#{key}, board=#{board.inspect}"
end
matching_changes = []
memberships = []
@changes.each do |change|
next unless change.sprint?
added_sprint_ids = change.value_id - change.old_value_id
added_sprint_ids.each do |id|
sprint_start = find_sprint_start_end(sprint_id: id, change: change).first
memberships << SprintMembership.new(sprint_id: id, sprint_start:, change:)
end
removed_sprint_ids = change.old_value_id - change.value_id
removed_sprint_ids.each do |id|
membership = memberships.find { |m| m.sprint_id == id }
next unless membership
memberships.delete(membership)
next unless counts_as_sprint_start? membership
next if membership.sprint_start >= change.time
matching_changes << membership.change
end
end
memberships.each do |membership|
matching_changes << membership.change if counts_as_sprint_start? membership
end
matching_changes.min_by(&:time)
end
|
#first_time_in_or_right_of_column(column_name) ⇒ Object
103
104
105
|
# File 'lib/jirametrics/issue.rb', line 103
def first_time_in_or_right_of_column column_name
first_time_in_status(*board.status_ids_in_or_right_of_column(column_name))
end
|
#first_time_in_status(*status_names) ⇒ Object
95
96
97
|
# File 'lib/jirametrics/issue.rb', line 95
def first_time_in_status *status_names
@changes.find { |change| change.current_status_matches(*status_names) }
end
|
#first_time_in_status_category(*category_names) ⇒ Object
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/jirametrics/issue.rb', line 188
def first_time_in_status_category *category_names
category_ids = find_status_category_ids_by_names category_names
status_changes.each do |change|
to_status = find_or_create_status(id: change.value_id, name: change.value)
id = to_status.category.id
return change if category_ids.include? id
end
nil
end
|
#first_time_label_added(*labels) ⇒ Object
107
108
109
110
111
112
113
114
115
|
# File 'lib/jirametrics/issue.rb', line 107
def first_time_label_added *labels
@changes.each do |change|
next unless change.labels?
change_labels = change.value.split
return change if change_labels.intersect?(labels)
end
nil
end
|
#first_time_not_in_status(*status_names) ⇒ Object
99
100
101
|
# File 'lib/jirametrics/issue.rb', line 99
def first_time_not_in_status *status_names
@changes.find { |change| change.status? && status_names.include?(change.value) == false }
end
|
#first_time_visible_on_board ⇒ Object
199
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/jirametrics/issue.rb', line 199
def first_time_visible_on_board
visible_status_ids = board.visible_columns.collect(&:status_ids).flatten
return first_time_in_status(*visible_status_ids) unless board.scrum?
candidates = visible_status_changes_in_active_sprint(visible_status_ids) +
sprint_entries_while_in_visible_status(visible_status_ids)
candidates.min_by(&:time)
end
|
#fix_versions ⇒ Object
502
503
504
505
506
507
508
509
|
# File 'lib/jirametrics/issue.rb', line 502
def fix_versions
if @fix_versions.nil?
@fix_versions = raw_fields['fixVersions']&.collect do |fix_version|
FixVersion.new fix_version
end || []
end
@fix_versions
end
|
#flow_efficiency_numbers(end_time:, settings: @board.project_config.settings) ⇒ Object
return [number of active seconds, total seconds] that this issue had up to the end_time.
It does not include data before issue start or after issue end
421
422
423
424
425
426
427
428
429
430
431
432
|
# File 'lib/jirametrics/issue.rb', line 421
def flow_efficiency_numbers end_time:, settings: @board.project_config.settings
issue_start, issue_stop = started_stopped_times
return [0.0, 0.0] if !issue_start || issue_start > end_time
end_time = issue_stop if issue_stop && issue_stop < end_time
FlowEfficiencyCalculator.new(
blocked_stalled_changes: blocked_stalled_changes(end_time: end_time, settings: settings),
issue_start: issue_start,
end_time: end_time
).calculate
end
|
#in_done_status_at?(time) ⇒ Boolean
Was the issue sitting in a done-category status at the given moment? Keys off the status category
(not the status name), so a status merely called "Done" that Jira categorises otherwise won't count.
305
306
307
308
309
310
|
# File 'lib/jirametrics/issue.rb', line 305
def in_done_status_at? time
last = status_changes.reverse.find { |change| change.time <= time }
return false unless last
find_or_create_status(id: last.value_id, name: last.value).category.done?
end
|
#in_initial_query? ⇒ Boolean
546
547
548
|
# File 'lib/jirametrics/issue.rb', line 546
def in_initial_query?
@raw['exporter'].nil? || @raw['exporter']['in_initial_query']
end
|
#inspect ⇒ Object
Many test failures are simply unreadable because the default inspect on this class goes
on for pages. Shorten it up.
387
388
389
|
# File 'lib/jirametrics/issue.rb', line 387
def inspect
"Issue(#{key.inspect})"
end
|
#issue_links ⇒ Object
493
494
495
496
497
498
499
500
|
# File 'lib/jirametrics/issue.rb', line 493
def issue_links
if @issue_links.nil?
@issue_links = raw_fields['issuelinks']&.collect do |issue_link|
IssueLink.new origin: self, raw: issue_link
end || []
end
@issue_links
end
|
#key ⇒ Object
47
|
# File 'lib/jirametrics/issue.rb', line 47
def key = @raw['key']
|
#key_as_i ⇒ Object
87
88
89
|
# File 'lib/jirametrics/issue.rb', line 87
def key_as_i
/-(?<number>\d+)$/ =~ key ? number.to_i : 0
end
|
#labels ⇒ Object
64
|
# File 'lib/jirametrics/issue.rb', line 64
def labels = raw_fields['labels'] || []
|
#last_activity(now: Time.now) ⇒ Object
Return the last time there was any activity on this ticket. Starting from "now" and going backwards
Returns nil if there was no activity before that time.
479
480
481
482
483
484
485
486
487
488
489
490
491
|
# File 'lib/jirametrics/issue.rb', line 479
def last_activity now: Time.now
result = @changes.reverse.find { |change| change.time <= now }&.time
return nil if result.nil?
@subtasks.each do |subtask|
subtask_last_activity = subtask.last_activity now: now
result = subtask_last_activity if subtask_last_activity && subtask_last_activity > result
end
result
end
|
#last_resolution ⇒ Object
373
374
375
|
# File 'lib/jirametrics/issue.rb', line 373
def last_resolution
@changes.reverse.find(&:resolution?)
end
|
#looks_like_issue_key?(key) ⇒ Boolean
511
512
513
|
# File 'lib/jirametrics/issue.rb', line 511
def looks_like_issue_key? key
!!(key.is_a?(String) && key =~ /^[^-]+-\d+$/)
end
|
#most_recent_status_change ⇒ Object
153
154
155
156
157
158
|
# File 'lib/jirametrics/issue.rb', line 153
def most_recent_status_change
status_changes.last
end
|
#parent_from_custom_fields(fields, project_config) ⇒ Object
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
|
# File 'lib/jirametrics/issue.rb', line 528
def parent_from_custom_fields fields, project_config
custom_field_names = project_config.settings['customfield_parent_links']
custom_field_names = [custom_field_names] if custom_field_names.is_a? String
custom_field_names&.each do |field_name|
parent = fields[field_name]
next if parent.nil?
return parent if looks_like_issue_key? parent
project_config.file_system.log(
"Custom field #{field_name.inspect} should point to a parent id but found #{parent.inspect}"
)
end
nil
end
|
#parent_key(project_config: @board.project_config) ⇒ Object
515
516
517
518
519
520
521
522
523
524
525
526
|
# File 'lib/jirametrics/issue.rb', line 515
def parent_key project_config: @board.project_config
fields = raw_fields
parent = fields['parent']&.[]('key') || fields['epic']&.[]('key')
parent ||= parent_from_custom_fields(fields, project_config) if project_config
parent
end
|
#parse_time(text) ⇒ Object
345
346
347
348
349
350
351
352
353
|
# File 'lib/jirametrics/issue.rb', line 345
def parse_time text
if text.nil?
nil
elsif text.is_a? String
Time.parse(text).getlocal(@timezone_offset)
else
Time.at(text / 1000).getlocal(@timezone_offset)
end
end
|
#priority_name ⇒ Object
59
|
# File 'lib/jirametrics/issue.rb', line 59
def priority_name = @raw.dig('fields', 'priority', 'name')
|
#priority_url ⇒ Object
60
|
# File 'lib/jirametrics/issue.rb', line 60
def priority_url = @raw.dig('fields', 'priority', 'iconUrl')
|
#raw_fields ⇒ Object
'fields' is the one part of the issue JSON that must always be present -- its absence means the
payload is malformed. (Linked-issue fragments legitimately have no fields; that case is guarded in
initialize, which returns before any of the fields-based accessors below can run.)
52
53
54
|
# File 'lib/jirametrics/issue.rb', line 52
def raw_fields
@raw['fields'] || raise("Issue(#{@raw['key']}) has no 'fields'; is this an Issue JSON?")
end
|
#reasons_not_visible_on_board ⇒ Object
223
224
225
226
227
228
229
230
|
# File 'lib/jirametrics/issue.rb', line 223
def reasons_not_visible_on_board
reasons = []
reasons << 'Not in an active sprint' if board.scrum? && sprints.none?(&:active?)
unless board.visible_columns.any? { |c| c.status_ids.include?(status.id) }
reasons << 'Status is not configured for any visible column on the board'
end
reasons
end
|
#resolution ⇒ Object
68
|
# File 'lib/jirametrics/issue.rb', line 68
def resolution = raw_fields['resolution']&.[]('name')
|
#sprint_entries_while_in_visible_status(visible_status_ids) ⇒ Object
217
218
219
220
221
|
# File 'lib/jirametrics/issue.rb', line 217
def sprint_entries_while_in_visible_status visible_status_ids
sprint_entry_events.filter_map do |effective_time, representative_change|
representative_change if in_visible_status_at?(effective_time, visible_status_ids)
end
end
|
#sprint_times_from_board(sprint_id) ⇒ Object
First look in the actual sprints json. If any issues are in this sprint then it should be here.
326
327
328
329
330
331
332
|
# File 'lib/jirametrics/issue.rb', line 326
def sprint_times_from_board sprint_id
sprint = board.sprints.find { |s| s.id == sprint_id }
return nil unless sprint
return [nil, nil] if sprint.future?
[sprint.start_time, sprint.completed_time]
end
|
#sprint_times_from_issue(sprint_id, change) ⇒ Object
Then look at the sprints inside the issue. Even though the field id may be specified, that custom
field may not be present. This happens if it was in that sprint but was then removed, whether or
not that sprint had ever started.
337
338
339
340
341
342
343
|
# File 'lib/jirametrics/issue.rb', line 337
def sprint_times_from_issue sprint_id, change
sprint_data = raw['fields'][change.field_id]&.find { |sd| sd['id'].to_i == sprint_id }
return nil unless sprint_data
return [nil, nil] if sprint_data['state'] == 'future'
[parse_time(sprint_data['startDate']), parse_time(sprint_data['completeDate'])]
end
|
#sprints ⇒ Object
624
625
626
627
628
629
630
631
632
633
634
635
|
# File 'lib/jirametrics/issue.rb', line 624
def sprints
sprint_ids = []
changes.each do |change|
next unless change.sprint?
sprint_ids << change.raw['to'].split(/\s*,\s*/).collect(&:to_i)
end
sprint_ids.flatten!
board.sprints.select { |s| sprint_ids.include? s.id }
end
|
#started_sprints ⇒ Object
637
638
639
|
# File 'lib/jirametrics/issue.rb', line 637
def started_sprints
sprints.reject(&:future?)
end
|
#started_stopped_dates ⇒ Object
598
599
600
|
# File 'lib/jirametrics/issue.rb', line 598
def started_stopped_dates
board.cycletime.started_stopped_dates(self)
end
|
#started_stopped_times ⇒ Object
594
595
596
|
# File 'lib/jirametrics/issue.rb', line 594
def started_stopped_times
board.cycletime.started_stopped_times(self)
end
|
#status_changes ⇒ Object
602
603
604
|
# File 'lib/jirametrics/issue.rb', line 602
def status_changes
@changes.select(&:status?)
end
|
#status_resolution_at_done ⇒ Object
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
|
# File 'lib/jirametrics/issue.rb', line 606
def status_resolution_at_done
done_time = started_stopped_times.last
return [nil, nil] if done_time.nil?
status_change = nil
resolution = nil
@changes.each do |change|
break if change.time > done_time
status_change = change if change.status?
resolution = change.value if change.resolution?
end
status = status_change ? find_or_create_status(id: status_change.value_id, name: status_change.value) : nil
[status, resolution]
end
|
#still_in_or_right_of_column(column_name) ⇒ Object
117
118
119
|
# File 'lib/jirametrics/issue.rb', line 117
def still_in_or_right_of_column column_name
still_in_status(*board.status_ids_in_or_right_of_column(column_name))
end
|
#still_in_status(*status_names) ⇒ Object
If it ever entered one of these statuses and it's still there then what was the last time it entered
137
138
139
140
141
|
# File 'lib/jirametrics/issue.rb', line 137
def still_in_status *status_names
still_in do |change|
status_names.include?(change.value) || status_names.include?(change.value_id)
end
end
|
#still_in_status_category(*category_names) ⇒ Object
If it ever entered one of these categories and it's still there then what was the last time it entered
144
145
146
147
148
149
150
151
|
# File 'lib/jirametrics/issue.rb', line 144
def still_in_status_category *category_names
category_ids = find_status_category_ids_by_names category_names
still_in do |change|
status = find_or_create_status id: change.value_id, name: change.value
category_ids.include? status.category.id
end
end
|
#summary ⇒ Object
62
|
# File 'lib/jirametrics/issue.rb', line 62
def summary = raw_fields['summary']
|
#time_created ⇒ Object
361
362
363
|
# File 'lib/jirametrics/issue.rb', line 361
def time_created
@changes.first
end
|
#type ⇒ Object
56
|
# File 'lib/jirametrics/issue.rb', line 56
def type = raw_fields['issuetype']['name']
|
#type_icon_url ⇒ Object
57
|
# File 'lib/jirametrics/issue.rb', line 57
def type_icon_url = raw_fields['issuetype']['iconUrl']
|
#updated ⇒ Object
365
366
367
|
# File 'lib/jirametrics/issue.rb', line 365
def updated
parse_time raw_fields['updated']
end
|
#url ⇒ Object
82
83
84
85
|
# File 'lib/jirametrics/issue.rb', line 82
def url
"#{@board.server_url_prefix}/browse/#{key}"
end
|
#visible_on_board? ⇒ Boolean
232
233
234
|
# File 'lib/jirametrics/issue.rb', line 232
def visible_on_board?
reasons_not_visible_on_board.empty?
end
|
#visible_status_changes_in_active_sprint(visible_status_ids) ⇒ Object
211
212
213
214
215
|
# File 'lib/jirametrics/issue.rb', line 211
def visible_status_changes_in_active_sprint visible_status_ids
status_changes.select do |change|
visible_status_ids.include?(change.value_id) && in_active_sprint_at?(change.time)
end
end
|