Class: MergetrainCheck::TraintableFormatter
- Inherits:
-
Object
- Object
- MergetrainCheck::TraintableFormatter
- Defined in:
- lib/mergetrain_check/formatter.rb
Instance Method Summary collapse
- #format(body) ⇒ Object
-
#initialize(max_length, firstname_only) ⇒ TraintableFormatter
constructor
A new instance of TraintableFormatter.
Constructor Details
#initialize(max_length, firstname_only) ⇒ TraintableFormatter
Returns a new instance of TraintableFormatter.
5 6 7 8 |
# File 'lib/mergetrain_check/formatter.rb', line 5 def initialize(max_length, firstname_only) @max_length = max_length @firstname_only = firstname_only end |
Instance Method Details
#format(body) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mergetrain_check/formatter.rb', line 10 def format(body) values = [['St', 'Waiting', 'Running', 'MR', 'Pipe ID', 'User', 'Title']] body.each do |carriage| begin_time = date_from_string carriage['created_at'] pipeline_begin_time = date_from_string carriage['pipeline']['created_at'] end_time = carriage['merged_at'].nil? ? DateTime.now : date_from_string(carriage['merged_at']) values << [pipeline_status(carriage['status']), pretty_date_difference(begin_time, pipeline_begin_time), pretty_date_difference(pipeline_begin_time, end_time), carriage['merge_request']['iid'], carriage['pipeline']['id'], @firstname_only ? carriage['user']['name'].split.first : carriage['user']['name'], truncate_string(carriage['merge_request']['title'], @max_length)] end header = '' if has_train_finished? body header = "\n ✋ 🚉 The train is at the station: There are currently no running merge trains!\n\n" end header + values.to_table end |