Class: IssuePrinter
- Inherits:
-
Object
- Object
- IssuePrinter
- Defined in:
- lib/jirametrics/issue_printer.rb
Instance Method Summary collapse
- #create_change_message(change:, issue:) ⇒ Object
- #format_change_values(change:, issue:) ⇒ Object
-
#initialize(issue) ⇒ IssuePrinter
constructor
A new instance of IssuePrinter.
- #sort_history!(history) ⇒ 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
#create_change_message(change:, issue:) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/jirametrics/issue_printer.rb', line 50 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 |
#format_change_values(change:, issue:) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/jirametrics/issue_printer.rb', line 64 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 |
#sort_history!(history) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/jirametrics/issue_printer.rb', line 82 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 |
#to_s ⇒ Object
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 |
# File 'lib/jirametrics/issue_printer.rb', line 8 def to_s issue = @issue result = +'' result << "#{issue.key} (#{issue.type}): #{issue.compact_text issue.summary, max: 200}\n" assignee = issue.raw['fields']['assignee'] result << " [assignee] #{assignee['name'].inspect} <#{assignee['emailAddress']}>\n" unless assignee.nil? 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 history = [] # time, type, detail if issue.board.cycletime started_at, stopped_at = issue.started_stopped_times history << [started_at, nil, 'vvvv Started here vvvv', true] if started_at history << [stopped_at, nil, '^^^^ Finished here ^^^^', true] if stopped_at else result << " Unable to determine start/end times as board #{issue.board.id} has no cycletime specified\n" end issue.discarded_change_times&.each do |time| history << [time, nil, '^^^^ Changes discarded ^^^^', true] end (issue.changes + (issue.discarded_changes || [])).each do |change| history << [change.time, change.field, (change: change, issue: issue), change.artificial?] end result << " History:\n" type_width = history.collect { |_time, type, _detail, _artificial| type&.length || 0 }.max sort_history!(history) history.each do |time, type, detail, _artificial| type = type.nil? ? '-' * type_width : type.rjust(type_width) result << " #{time.strftime '%Y-%m-%d %H:%M:%S %z'} [#{type}] #{detail}\n" end result end |