Class: IssuePrinter
- Inherits:
-
Object
- Object
- IssuePrinter
- Defined in:
- lib/jirametrics/issue_printer.rb
Instance Method Summary collapse
- #assignee_line ⇒ Object
-
#build_history ⇒ Object
Each history entry is [time, type, detail, artificial?].
- #change_entries ⇒ Object
- #create_change_message(change:, issue:) ⇒ Object
- #cycletime_warning ⇒ Object
- #discarded_change_entries ⇒ Object
- #format_change_values(change:, issue:) ⇒ Object
- #header_line ⇒ Object
- #history_section ⇒ Object
-
#initialize(issue) ⇒ IssuePrinter
constructor
A new instance of IssuePrinter.
- #links_section ⇒ Object
- #render_history(history) ⇒ Object
- #sort_history!(history) ⇒ Object
- #start_stop_entries ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(issue) ⇒ IssuePrinter
Returns a new instance of IssuePrinter.
4 5 6 |
# File 'lib/jirametrics/issue_printer.rb', line 4 def initialize issue @issue = issue end |
Instance Method Details
#assignee_line ⇒ Object
21 22 23 24 25 26 |
# File 'lib/jirametrics/issue_printer.rb', line 21 def assignee_line assignee = @issue.raw['fields']['assignee'] return '' if assignee.nil? " [assignee] #{assignee['name'].inspect} <#{assignee['emailAddress']}>\n" end |
#build_history ⇒ Object
Each history entry is [time, type, detail, artificial?].
52 53 54 |
# File 'lib/jirametrics/issue_printer.rb', line 52 def build_history start_stop_entries + discarded_change_entries + change_entries end |
#change_entries ⇒ Object
72 73 74 75 76 |
# File 'lib/jirametrics/issue_printer.rb', line 72 def change_entries (@issue.changes + (@issue.discarded_changes || [])).map do |change| [change.time, change.field, (change: change, issue: @issue), change.artificial?] end end |
#create_change_message(change:, issue:) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/jirametrics/issue_printer.rb', line 87 def change:, issue: value, old_value = format_change_values(change: change, issue: issue) = +'' << "#{old_value} -> " unless old_value.nil? || old_value.empty? << value if change.artificial? << ' (Artificial entry)' else << " (Author: #{change.})" end end |
#cycletime_warning ⇒ Object
45 46 47 48 49 |
# File 'lib/jirametrics/issue_printer.rb', line 45 def cycletime_warning return '' if @issue.board.cycletime " Unable to determine start/end times as board #{@issue.board.id} has no cycletime specified\n" end |
#discarded_change_entries ⇒ Object
66 67 68 69 70 |
# File 'lib/jirametrics/issue_printer.rb', line 66 def discarded_change_entries (@issue.discarded_change_times || []).map do |time| [time, nil, '^^^^ Changes discarded ^^^^', true] end end |
#format_change_values(change:, issue:) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/jirametrics/issue_printer.rb', line 101 def format_change_values change:, issue: if change.status? value = "#{change.value.inspect}:#{change.value_id.inspect}" old_value = change.old_value ? "#{change.old_value.inspect}:#{change.old_value_id.inspect}" : nil elsif change.sprint? added = change.value_id - change.old_value_id removed = change.old_value_id - change.value_id value = "#{change.value.inspect} #{change.value_id}" value << " (added: #{added})" unless added.empty? value << " (removed: #{removed})" unless removed.empty? old_value = nil else value = issue.compact_text(change.value).inspect old_value = change.old_value ? issue.compact_text(change.old_value).inspect : nil end [value, old_value] end |
#header_line ⇒ Object
17 18 19 |
# File 'lib/jirametrics/issue_printer.rb', line 17 def header_line "#{@issue.key} (#{@issue.type}): #{@issue.compact_text @issue.summary, max: 200}\n" end |
#history_section ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/jirametrics/issue_printer.rb', line 37 def history_section result = +'' result << cycletime_warning result << " History:\n" result << render_history(build_history) result end |
#links_section ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/jirametrics/issue_printer.rb', line 28 def links_section result = +'' @issue.raw['fields']['issuelinks']&.each do |link| result << " [link] #{link['type']['outward']} #{link['outwardIssue']['key']}\n" if link['outwardIssue'] result << " [link] #{link['type']['inward']} #{link['inwardIssue']['key']}\n" if link['inwardIssue'] end result end |
#render_history(history) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/jirametrics/issue_printer.rb', line 78 def render_history history type_width = history.collect { |_time, type, _detail, _artificial| type&.length || 0 }.max sort_history!(history) history.map do |time, type, detail, _artificial| type = type.nil? ? '-' * type_width : type.rjust(type_width) " #{time.strftime '%Y-%m-%d %H:%M:%S %z'} [#{type}] #{detail}\n" end.join end |
#sort_history!(history) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/jirametrics/issue_printer.rb', line 119 def sort_history! history history.sort! do |a, b| if a[0] == b[0] if a[1].nil? 1 elsif b[1].nil? -1 else a[1] <=> b[1] end else a[0] <=> b[0] end end end |
#start_stop_entries ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/jirametrics/issue_printer.rb', line 56 def start_stop_entries return [] unless @issue.board.cycletime started_at, stopped_at = @issue.started_stopped_times entries = [] entries << [started_at, nil, 'vvvv Started here vvvv', true] if started_at entries << [stopped_at, nil, '^^^^ Finished here ^^^^', true] if stopped_at entries end |
#to_s ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/jirametrics/issue_printer.rb', line 8 def to_s result = +'' result << header_line result << assignee_line result << links_section result << history_section result end |