Class: Dug::MessageProcessor
- Inherits:
-
Object
- Object
- Dug::MessageProcessor
- Includes:
- Logger
- Defined in:
- lib/dug/message_processor.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(message_id, servicer) ⇒ MessageProcessor
constructor
A new instance of MessageProcessor.
Methods included from Logger
Constructor Details
#initialize(message_id, servicer) ⇒ MessageProcessor
Returns a new instance of MessageProcessor.
6 7 8 9 |
# File 'lib/dug/message_processor.rb', line 6 def initialize(, servicer) @servicer = servicer @message = NotificationDecorator.new(servicer.('me', )) end |
Instance Method Details
#execute ⇒ Object
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 |
# File 'lib/dug/message_processor.rb', line 11 def execute %w(organization repository reason).each do |type| if = .public_send(type) opts = type == 'repository' ? { remote: .public_send(:organization) } : {} label = Dug.configuration.label_for(type, , opts) labels_to_add << label if label end end %w(merged closed).each do |state| if .public_send("indicates_#{state}?") label = Dug.configuration.label_for(:state, state) labels_to_add << label if label end end if .indicates_reopened? label = Dug.configuration.label_for(:state, 'closed') reopened_label = Dug.configuration.label_for(:state, 'reopened') labels_to_remove << label if label labels_to_add << reopened_label if reopened_label end info = "Processing message:" info << "\n ID: #{.id}" %w(Date From Subject).each do |header| info << "\n #{header}: #{.headers[header]}" end info << "\n * Applying labels: #{labels_to_add.join(' | ')} *" info << "\n * Removing labels: #{labels_to_remove.join(' | ')} *" log(info) servicer.add_labels_by_name(, labels_to_add) servicer.remove_labels_by_name(, labels_to_remove, entire_thread: modify_entire_thread?) end |