Class: Issue
- Inherits:
-
Object
- Object
- Issue
- Defined in:
- lib/jirametrics/issue.rb
Instance Attribute Summary collapse
-
#board ⇒ Object
readonly
Returns the value of attribute board.
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#discarded_change_times ⇒ Object
readonly
Returns the value of attribute discarded_change_times.
-
#discarded_changes ⇒ Object
readonly
Returns the value of attribute discarded_changes.
-
#github_prs ⇒ Object
Returns the value of attribute github_prs.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#subtasks ⇒ Object
readonly
Returns the value of attribute subtasks.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Sort by key.
- #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
- #blocked_stalled_changes_flag_logic(change) ⇒ Object
- #check_for_stalled(change_time:, previous_change_time:, stalled_threshold:, blocking_stalled_changes:) ⇒ Object
- #compact_text(text, max: 60) ⇒ Object
- #component_names ⇒ Object
- #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
- #done? ⇒ Boolean
- #due_date ⇒ Object
- #dump ⇒ Object
- #expedited? ⇒ Boolean
- #expedited_on_date?(date) ⇒ Boolean
- #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 will ever be in an active sprint then return the time that it was first added to that sprint, whether or not the sprint was active at that time.
- #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_initial_query? ⇒ Boolean
-
#initialize(raw:, board:, timezone_offset: '+00:00') ⇒ Issue
constructor
A new instance of Issue.
-
#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_key(project_config: @board.project_config) ⇒ Object
- #parse_time(text) ⇒ Object
- #priority_name ⇒ Object
- #priority_url ⇒ Object
- #reasons_not_visible_on_board ⇒ Object
- #resolution ⇒ Object
- #sprints ⇒ Object
- #started_sprints ⇒ Object
- #started_stopped_dates ⇒ Object
- #started_stopped_times ⇒ Object
- #status ⇒ Object
- #status=(status) ⇒ 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
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 |
# 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 # We only check for this here because if a board isn't passed in then things will fail much # later and be hard to find. Let's find out early. raise "No board for issue #{key}" if board.nil? # There are cases where we create an Issue of fragments like linked issues and those won't have # changelogs. load_history_into_changes if @raw['changelog'] # As above with fragments, there may not be a fields section return unless @raw['fields'] # If this is an older pull of data then comments may not be there. load_comments_into_changes if @raw['fields']['comment'] # It might appear that Jira already returns these in order but we've found different # versions of Server/Cloud return the changelog in different orders so we sort them. sort_changes! # It's possible to have a ticket created with certain things already set and therefore # not showing up in the change log. Create some artificial entries to capture those. @changes = [ fabricate_change(field_name: 'status'), fabricate_change(field_name: 'priority') ].compact + @changes rescue # rubocop:disable Style/RescueStandardError # All we're doing is adding information to the existing exception and letting it propogate up raise "Unable to initialize #{raw['key']}" end |
Instance Attribute Details
#board ⇒ Object (readonly)
Returns the value of attribute board.
6 7 8 |
# File 'lib/jirametrics/issue.rb', line 6 def board @board end |
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
6 7 8 |
# File 'lib/jirametrics/issue.rb', line 6 def changes @changes end |
#discarded_change_times ⇒ Object (readonly)
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 (readonly)
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 (readonly)
Returns the value of attribute raw.
6 7 8 |
# File 'lib/jirametrics/issue.rb', line 6 def raw @raw end |
#subtasks ⇒ Object (readonly)
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
Sort by key
721 722 723 724 725 726 727 |
# File 'lib/jirametrics/issue.rb', line 721 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
600 601 602 603 604 605 606 |
# File 'lib/jirametrics/issue.rb', line 600 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.
716 717 718 |
# File 'lib/jirametrics/issue.rb', line 716 def artificial? @raw['exporter'].nil? end |
#assigned_to ⇒ Object
344 345 346 |
# File 'lib/jirametrics/issue.rb', line 344 def assigned_to @raw['fields']['assignee']&.[]('displayName') end |
#assigned_to_icon_url ⇒ Object
348 349 350 |
# File 'lib/jirametrics/issue.rb', line 348 def assigned_to_icon_url @raw['fields']['assignee']&.[]('avatarUrls')&.[]('16x16') end |
#author ⇒ Object
58 |
# File 'lib/jirametrics/issue.rb', line 58 def = @raw['fields']['creator']&.[]('displayName') || '' |
#blocked_on_date?(date, end_time:) ⇒ Boolean
358 359 360 |
# File 'lib/jirametrics/issue.rb', line 358 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
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'lib/jirametrics/issue.rb', line 367 def blocked_stalled_by_date date_range:, chart_end_time:, settings: nil results = {} current_date = nil blocked_stalled_changes = blocked_stalled_changes(end_time: chart_end_time, settings: settings) blocked_stalled_changes.each do |change| current_date = change.time.to_date winning_change, _last_change = results[current_date] if winning_change.nil? || change.blocked? || (change.active? && (winning_change.active? || winning_change.stalled?)) || (change.stalled? && winning_change.stalled?) winning_change = change end results[current_date] = [winning_change, change] end last_populated_date = nil (results.keys.min..results.keys.max).each do |date| if results.key? date last_populated_date = date else _winner, last = results[last_populated_date] results[date] = [last, last] end end results = results.transform_values(&:first) # The requested date range may span outside the actual changes we find in the changelog date_of_first_change = blocked_stalled_changes[0].time.to_date date_of_last_change = blocked_stalled_changes[-1].time.to_date date_range.each do |date| results[date] = blocked_stalled_changes[0] if date < date_of_first_change results[date] = blocked_stalled_changes[-1] if date > date_of_last_change end # To make the code simpler, we've been accumulating data for every date. Now remove anything # that isn't in the requested date_range results.select! { |date, _value| date_range.include? date } results end |
#blocked_stalled_changes(end_time:, settings: nil) ⇒ Object
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
# File 'lib/jirametrics/issue.rb', line 412 def blocked_stalled_changes end_time:, settings: nil settings ||= @board.project_config.settings blocked_statuses = settings['blocked_statuses'] stalled_statuses = settings['stalled_statuses'] blocked_link_texts = settings['blocked_link_text'] stalled_threshold = settings['stalled_threshold_days'] flagged_means_blocked = !!settings['flagged_means_blocked'] # rubocop:disable Style/DoubleNegation blocking_issue_keys = [] result = [] previous_was_active = false # Must start as false so that the creation will insert an :active previous_change_time = created blocking_status = nil blocking_is_blocked = false flag = nil flag_reason = nil # This mock change is to force the writing of one last entry at the end of the time range. # By doing this, we're able to eliminate a lot of duplicated code in charts. mock_change = ChangeItem.new time: end_time, artificial: true, raw: { 'field' => '' }, author_raw: nil (changes + [mock_change]).each do |change| previous_was_active = false if check_for_stalled( change_time: change.time, previous_change_time: previous_change_time, stalled_threshold: stalled_threshold, blocking_stalled_changes: result ) if change.flagged? && flagged_means_blocked flag, flag_reason = blocked_stalled_changes_flag_logic change elsif change.status? blocking_status = nil blocking_is_blocked = false if blocked_statuses.find_by_id(change.value_id) blocking_status = change.value blocking_is_blocked = true elsif stalled_statuses.find_by_id(change.value_id) blocking_status = change.value end elsif change.link? # Example: "This issue is satisfied by ANON-30465" unless /^This (?<_>issue|work item) (?<link_text>.+) (?<issue_key>.+)$/ =~ (change.value || change.old_value) puts "Issue(#{key}) Can't parse link text: #{change.value || change.old_value}" next end if blocked_link_texts.include? link_text if change.value blocking_issue_keys << issue_key else blocking_issue_keys.delete issue_key end end end new_change = BlockedStalledChange.new( flagged: flag, flag_reason: flag_reason, status: blocking_status, status_is_blocking: blocking_status.nil? || blocking_is_blocked, blocking_issue_keys: (blocking_issue_keys.empty? ? nil : blocking_issue_keys.dup), time: change.time ) # We don't want to dump two actives in a row as that would just be noise. Unless this is # the mock change, which we always want to dump result << new_change if !new_change.active? || !previous_was_active || change == mock_change previous_was_active = new_change.active? previous_change_time = change.time end if result.size >= 2 # The existence of the mock entry will mess with the stalled count as it will wake everything # back up. This hack will clean up appropriately. hack = result.pop result << BlockedStalledChange.new( flagged: hack.flag, flag_reason: hack.flag_reason, status: hack.status, status_is_blocking: hack.status_is_blocking, blocking_issue_keys: hack.blocking_issue_keys, time: hack.time, stalled_days: result[-1].stalled_days ) end result end |
#blocked_stalled_changes_flag_logic(change) ⇒ Object
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 |
# File 'lib/jirametrics/issue.rb', line 507 def blocked_stalled_changes_flag_logic change flag = change.value flag = nil if change.value == '' if flag # When the user is adding a comment to explain why a flag was set, the flag is set immediately # and the comment is inserted after the user hits enter, which means that there is some time # gap. If a comment happened shortly after the flag was set, we assume they're linked. This # won't always be true and so there will be false positives, but it's a reasonable assumption. max_seconds_between_flag_and_comment = 30 comment_change = changes.find do |c| c.comment? && c.time >= change.time && (c.time - change.time) <= max_seconds_between_flag_and_comment end flag_reason = comment_change && @board.project_config.atlassian_document_format.to_text(comment_change.value) # Newer Jira instances may add this extra text but older instances did not. Strip it out if found. flag_reason = flag_reason&.sub(/\A:flag_on: Flag added\s*/m, '')&.strip flag_reason = nil if flag_reason&.empty? else flag_reason = nil end [flag, flag_reason] end |
#check_for_stalled(change_time:, previous_change_time:, stalled_threshold:, blocking_stalled_changes:) ⇒ Object
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
# File 'lib/jirametrics/issue.rb', line 529 def check_for_stalled change_time:, previous_change_time:, stalled_threshold:, blocking_stalled_changes: stalled_threshold_seconds = stalled_threshold * 60 * 60 * 24 # The most common case will be nothing to split so quick escape. return false if (change_time - previous_change_time).to_i < stalled_threshold_seconds # If the last identified change was blocked then it doesn't matter now long we've waited, we're still blocked. return false if blocking_stalled_changes[-1]&.blocked? list = [previous_change_time..change_time] all_subtask_activity_times.each do |time| matching_range = list.find { |range| time >= range.begin && time <= range.end } next unless matching_range list.delete matching_range list << ((matching_range.begin)..time) list << (time..(matching_range.end)) end inserted_stalled = false list.sort_by(&:begin).each do |range| seconds = (range.end - range.begin).to_i next if seconds < stalled_threshold_seconds an_hour_later = range.begin + (60 * 60) blocking_stalled_changes << BlockedStalledChange.new(stalled_days: seconds / (24 * 60 * 60), time: an_hour_later) inserted_stalled = true end inserted_stalled end |
#compact_text(text, max: 60) ⇒ Object
804 805 806 807 808 809 810 811 812 813 814 815 |
# File 'lib/jirametrics/issue.rb', line 804 def compact_text text, max: 60 return '' if text.nil? text = if text.is_a? Hash @board.project_config.atlassian_document_format.to_text(text) else text end text = text.gsub(/\s+/, ' ').strip text = "#{text[0...max]}..." if text.length > max text end |
#component_names ⇒ Object
85 86 87 |
# File 'lib/jirametrics/issue.rb', line 85 def component_names @raw['fields']['components']&.collect { |component| component['name'] } || [] end |
#created ⇒ Object
323 324 325 326 |
# File 'lib/jirametrics/issue.rb', line 323 def created # This nil check shouldn't be necessary and yet we've seen one case where it was. parse_time @raw['fields']['created'] if @raw['fields']['created'] end |
#currently_in_status(*status_names) ⇒ Object
Are we currently in this status? If yes, then return the most recent status change.
155 156 157 158 159 160 |
# File 'lib/jirametrics/issue.rb', line 155 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.
163 164 165 166 167 168 169 170 171 |
# File 'lib/jirametrics/issue.rb', line 163 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
729 730 731 732 733 734 735 736 737 738 739 740 741 |
# File 'lib/jirametrics/issue.rb', line 729 def discard_changes_before cutoff_time rejected_any = false @changes.reject! do |change| reject = change.status? && change.time <= cutoff_time && change.artificial? == false if reject (@discarded_changes ||= []) << change rejected_any = true end reject end (@discarded_change_times ||= []) << cutoff_time if rejected_any end |
#done? ⇒ Boolean
747 748 749 750 751 752 753 754 755 |
# File 'lib/jirametrics/issue.rb', line 747 def done? if artificial? || board.cycletime.nil? # This was probably loaded as a linked issue, which means we don't know what board it really # belonged to. The best we can do is look at the status key status.category.done? else board.cycletime.done? self end end |
#due_date ⇒ Object
71 72 73 74 |
# File 'lib/jirametrics/issue.rb', line 71 def due_date text = @raw['fields']['duedate'] text.nil? ? nil : Date.parse(text) end |
#dump ⇒ Object
743 744 745 |
# File 'lib/jirametrics/issue.rb', line 743 def dump IssuePrinter.new(self).to_s end |
#expedited? ⇒ Boolean
608 609 610 611 612 613 614 |
# File 'lib/jirametrics/issue.rb', line 608 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
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 |
# File 'lib/jirametrics/issue.rb', line 616 def expedited_on_date? date expedited_start = nil return false unless @board&.project_config expedited_names = @board.project_config.settings['expedited_priority_names'] changes.each do |change| next unless change.priority? if expedited_names.include? change.value expedited_start = change.time.to_date if expedited_start.nil? else return true if expedited_start && (expedited_start..change.time.to_date).cover?(date) expedited_start = nil end end return false if expedited_start.nil? expedited_start <= date end |
#find_or_create_status(id:, name:) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/jirametrics/issue.rb', line 173 def find_or_create_status id:, name: status = board.possible_statuses.find_by_id(id) unless status # Have to pull this list before the call to fabricate or else the warning will incorrectly # list this status as one it actually found found_statuses = board.possible_statuses.to_s status = board.possible_statuses.fabricate_status_for id: id, name: name = +'The history for issue ' << key << ' references the status (' << "#{name.inspect}:#{id.inspect}" << ') that can\'t be found. We are guessing that this belongs to the ' << status.category.to_s << ' status category but that may be wrong. See https://jirametrics.org/faq/#q1 for more ' << 'details on defining statuses.' board.project_config.file_system.warning , more: "The statuses we did find are: #{found_statuses}" end status end |
#find_sprint_start_end(sprint_id:, change:) ⇒ Object
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 309 310 311 |
# File 'lib/jirametrics/issue.rb', line 280 def find_sprint_start_end sprint_id:, change: # There are two different places that sprint data could be found. In theory all # sprints would be found in both places. In practice, sometimes what we need is # in one or the other but not both. # First look in the actual sprints json. If any issues are in this sprint then it should # be here. sprint = board.sprints.find { |s| s.id == sprint_id } if sprint return [nil, nil] if sprint.future? return [sprint.start_time, sprint.completed_time] end # 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. sprint_data = raw['fields'][change.field_id]&.find { |sd| sd['id'].to_i == sprint_id } if sprint_data return [nil, nil] if sprint_data['state'] == 'future' start = parse_time(sprint_data['startDate']) stop = parse_time(sprint_data['completeDate']) return [start, stop] end # If we got this far then the sprint can't be found anywhere, so we pretend that it never # started. Is this guaranteed to be true? No. In theory if all issues were removed from # an active sprint then it would also disappear, even though it had started. Nothing we # can do to detect that edge-case though. [nil, nil] end |
#first_resolution ⇒ Object
336 337 338 |
# File 'lib/jirametrics/issue.rb', line 336 def first_resolution @changes.find { |change| change.resolution? } end |
#first_status_change_after_created ⇒ Object
197 198 199 |
# File 'lib/jirametrics/issue.rb', line 197 def first_status_change_after_created status_changes.find { |change| change.artificial? == false } end |
#first_time_added_to_active_sprint ⇒ Object
If this issue will ever be in an active sprint then return the time that it was first added to that sprint, whether or not the sprint was active at that time. Although it seems like an odd thing to calculate, it’s a reasonable proxy for ‘ready’ in cases where the team doesn’t have an explicit ‘ready’ status. You’d be better off with an explicit ‘ready’ but sometimes that’s not an option.
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 |
# File 'lib/jirametrics/issue.rb', line 235 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 data_clazz = Struct.new(:sprint_id, :sprint_start, :sprint_stop, :change) matching_changes = [] all_datas = [] @changes.each do |change| next unless change.sprint? added_sprint_ids = change.value_id - change.old_value_id added_sprint_ids.each do |id| data = data_clazz.new data.sprint_id = id data.change = change data.sprint_start, data.sprint_stop = find_sprint_start_end(sprint_id: id, change: change) all_datas << data end removed_sprint_ids = change.old_value_id - change.value_id removed_sprint_ids.each do |id| data = all_datas.find { |d| d.sprint_id == id } # It's possible for an issue to be created inside a sprint and therefore for # that add-to-sprint not show in the history. next unless data all_datas.delete(data) next if data.sprint_start.nil? || data.sprint_start >= change.time matching_changes << data.change end end # There can't be any more removes so whatever is left is a valid option # Now all we care about is if the sprint has started. all_datas.each do |data| matching_changes << data.change if data.sprint_start end matching_changes.min_by(&:time) end |
#first_time_in_or_right_of_column(column_name) ⇒ Object
97 98 99 |
# File 'lib/jirametrics/issue.rb', line 97 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
89 90 91 |
# File 'lib/jirametrics/issue.rb', line 89 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
201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/jirametrics/issue.rb', line 201 def first_time_in_status_category *category_names category_ids = find_status_category_ids_by_names category_names status_changes.each do |change| puts "Debugging #{self.key} #{change.inspect}" if change.value_id.nil? 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
101 102 103 104 105 106 107 108 109 |
# File 'lib/jirametrics/issue.rb', line 101 def first_time_label_added *labels @changes.each do |change| next unless change.labels? change_labels = change.value.split return change if change_labels.any? { |l| labels.include?(l) } end nil end |
#first_time_not_in_status(*status_names) ⇒ Object
93 94 95 |
# File 'lib/jirametrics/issue.rb', line 93 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
213 214 215 |
# File 'lib/jirametrics/issue.rb', line 213 def first_time_visible_on_board first_time_in_status(*board.visible_columns.collect(&:status_ids).flatten) end |
#fix_versions ⇒ Object
664 665 666 667 668 669 670 671 |
# File 'lib/jirametrics/issue.rb', line 664 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
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 |
# File 'lib/jirametrics/issue.rb', line 563 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 value_add_time = 0.0 end_time = issue_stop if issue_stop && issue_stop < end_time active_start = nil blocked_stalled_changes(end_time: end_time, settings: settings).each_with_index do |change, index| break if change.time > end_time if index.zero? active_start = change.time if change.active? next end # Already active and we just got another active. next if active_start && change.active? if change.active? active_start = change.time elsif active_start && change.time >= issue_start # Not active now but we have been. Record the active time. change_delta = change.time - [issue_start, active_start].max value_add_time += change_delta active_start = nil end end if active_start change_delta = end_time - [issue_start, active_start].max value_add_time += change_delta if change_delta.positive? end [value_add_time, end_time - issue_start] end |
#in_initial_query? ⇒ Boolean
711 712 713 |
# File 'lib/jirametrics/issue.rb', line 711 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.
354 355 356 |
# File 'lib/jirametrics/issue.rb', line 354 def inspect "Issue(#{key.inspect})" end |
#issue_links ⇒ Object
655 656 657 658 659 660 661 662 |
# File 'lib/jirametrics/issue.rb', line 655 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
46 |
# File 'lib/jirametrics/issue.rb', line 46 def key = @raw['key'] |
#key_as_i ⇒ Object
81 82 83 |
# File 'lib/jirametrics/issue.rb', line 81 def key_as_i key =~ /-(\d+)$/ ? $1.to_i : 0 end |
#labels ⇒ Object
56 |
# File 'lib/jirametrics/issue.rb', line 56 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.
641 642 643 644 645 646 647 648 649 650 651 652 653 |
# File 'lib/jirametrics/issue.rb', line 641 def last_activity now: Time.now result = @changes.reverse.find { |change| change.time <= now }&.time # The only condition where this could be nil is if "now" is before creation 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
340 341 342 |
# File 'lib/jirametrics/issue.rb', line 340 def last_resolution @changes.reverse.find { |change| change.resolution? } end |
#looks_like_issue_key?(key) ⇒ Boolean
673 674 675 |
# File 'lib/jirametrics/issue.rb', line 673 def looks_like_issue_key? key !!(key.is_a?(String) && key =~ /^[^-]+-\d+$/) end |
#most_recent_status_change ⇒ Object
147 148 149 150 151 152 |
# File 'lib/jirametrics/issue.rb', line 147 def most_recent_status_change # Any issue that we loaded from its own file will always have a status as we artificially insert a status # change to represent creation. Issues that were just fragments referenced from a main issue (ie a linked issue) # may not have any status changes as we have no idea when it was created. This will be nil in that case status_changes.last end |
#parent_key(project_config: @board.project_config) ⇒ Object
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 |
# File 'lib/jirametrics/issue.rb', line 677 def parent_key project_config: @board.project_config # Although Atlassian is trying to standardize on one way to determine the parent, today it's a mess. # We try a variety of ways to get the parent and hopefully one of them will work. See this link: # https://community.developer.atlassian.com/t/deprecation-of-the-epic-link-parent-link-and-other-related-fields-in-rest-apis-and-webhooks/54048 fields = @raw['fields'] # At some point in the future, this will be the only way to retrieve the parent so we try this first. parent = fields['parent']&.[]('key') # The epic field parent = fields['epic']&.[]('key') if parent.nil? # Otherwise the parent link will be stored in one of the custom fields. We've seen different custom fields # used for parent_link vs epic_link so we have to support more than one. if parent.nil? && 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? break 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}" ) parent = nil end end parent end |
#parse_time(text) ⇒ Object
313 314 315 316 317 318 319 320 321 |
# File 'lib/jirametrics/issue.rb', line 313 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
51 |
# File 'lib/jirametrics/issue.rb', line 51 def priority_name = @raw['fields']['priority']['name'] |
#priority_url ⇒ Object
52 |
# File 'lib/jirametrics/issue.rb', line 52 def priority_url = @raw['fields']['priority']['iconUrl'] |
#reasons_not_visible_on_board ⇒ Object
217 218 219 220 221 222 223 224 |
# File 'lib/jirametrics/issue.rb', line 217 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
60 |
# File 'lib/jirametrics/issue.rb', line 60 def resolution = @raw['fields']['resolution']&.[]('name') |
#sprints ⇒ Object
787 788 789 790 791 792 793 794 795 796 797 798 |
# File 'lib/jirametrics/issue.rb', line 787 def sprints sprint_ids = [] changes.each do |change| next unless change.sprint? sprint_ids << change.raw['to'].split(/\s*,\s*/).collect { |id| id.to_i } end sprint_ids.flatten! board.sprints.select { |s| sprint_ids.include? s.id } end |
#started_sprints ⇒ Object
800 801 802 |
# File 'lib/jirametrics/issue.rb', line 800 def started_sprints sprints.reject { |sprint| sprint.future? } end |
#started_stopped_dates ⇒ Object
761 762 763 |
# File 'lib/jirametrics/issue.rb', line 761 def started_stopped_dates board.cycletime.started_stopped_dates(self) end |
#started_stopped_times ⇒ Object
757 758 759 |
# File 'lib/jirametrics/issue.rb', line 757 def started_stopped_times board.cycletime.started_stopped_times(self) end |
#status ⇒ Object
62 63 64 65 |
# File 'lib/jirametrics/issue.rb', line 62 def status @status = Status.from_raw(@raw['fields']['status']) unless @status @status end |
#status=(status) ⇒ Object
67 68 69 |
# File 'lib/jirametrics/issue.rb', line 67 def status= status @status = status end |
#status_changes ⇒ Object
765 766 767 |
# File 'lib/jirametrics/issue.rb', line 765 def status_changes @changes.select { |change| change.status? } end |
#status_resolution_at_done ⇒ Object
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 |
# File 'lib/jirametrics/issue.rb', line 769 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
111 112 113 |
# File 'lib/jirametrics/issue.rb', line 111 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
131 132 133 134 135 |
# File 'lib/jirametrics/issue.rb', line 131 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
138 139 140 141 142 143 144 145 |
# File 'lib/jirametrics/issue.rb', line 138 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
54 |
# File 'lib/jirametrics/issue.rb', line 54 def summary = @raw['fields']['summary'] |
#time_created ⇒ Object
328 329 330 |
# File 'lib/jirametrics/issue.rb', line 328 def time_created @changes.first end |
#type ⇒ Object
48 |
# File 'lib/jirametrics/issue.rb', line 48 def type = @raw['fields']['issuetype']['name'] |
#type_icon_url ⇒ Object
49 |
# File 'lib/jirametrics/issue.rb', line 49 def type_icon_url = @raw['fields']['issuetype']['iconUrl'] |
#updated ⇒ Object
332 333 334 |
# File 'lib/jirametrics/issue.rb', line 332 def updated parse_time @raw['fields']['updated'] end |
#url ⇒ Object
76 77 78 79 |
# File 'lib/jirametrics/issue.rb', line 76 def url # Strangely, the URL isn't anywhere in the returned data so we have to fabricate it. "#{@board.server_url_prefix}/browse/#{key}" end |
#visible_on_board? ⇒ Boolean
226 227 228 |
# File 'lib/jirametrics/issue.rb', line 226 def visible_on_board? reasons_not_visible_on_board.empty? end |