class Kuroko2::Workflow::Notifier::Hipchat

Constants

USER_NAME

Attributes

hipchat[R]
message_builder[R]

Public Class Methods

new(instance) click to toggle source
# File lib/autoload/kuroko2/workflow/notifier/hipchat.rb, line 9
def initialize(instance)
  hipchat_options = Kuroko2.config.notifiers.hipchat.try!(:options).try!(:symbolize_keys) || {}
  @instance   = instance
  @definition = instance.job_definition
  @hipchat    = HipChat::Client.new(Kuroko2.config.notifiers.hipchat.api_token, hipchat_options)
  @message_builder = Workflow::Notifier::Concerns::ChatMessageBuilder.new(instance)
end

Public Instance Methods

notify_back_to_normal() click to toggle source
# File lib/autoload/kuroko2/workflow/notifier/hipchat.rb, line 82
def notify_back_to_normal
  message = build_message(level: 'SUCCESS', text: message_builder.back_to_normal_text)
  send_to_hipchat(message)
end
notify_cancellation() click to toggle source
# File lib/autoload/kuroko2/workflow/notifier/hipchat.rb, line 47
def notify_cancellation
  if @definition.notify_cancellation || @definition.hipchat_notify_finished?
    message = build_message(level: 'WARNING', text: message_builder.failure_text)
    message << "<br>"
    message << @instance.logs.reverse.detect{ |log| log.level == 'WARN' }.try!(:message)

    send_to_hipchat(message, color: 'yellow')
  end
end
notify_critical() click to toggle source
# File lib/autoload/kuroko2/workflow/notifier/hipchat.rb, line 66
def notify_critical
  message = build_message(level: 'CRITICAL', text: message_builder.failure_text)
  message << "<br>"
  message << @instance.logs.last(2).first.message

  send_to_hipchat(message, color: 'red', notify: true)
  send_additional_text_to_hipchat
end
notify_failure() click to toggle source
# File lib/autoload/kuroko2/workflow/notifier/hipchat.rb, line 57
def notify_failure
  message = build_message(level: 'FAILURE', text: message_builder.failure_text)
  message << "<br>"
  message << @instance.logs.last(2).first.message

  send_to_hipchat(message, color: 'red', notify: true)
  send_additional_text_to_hipchat
end
notify_finished() click to toggle source
# File lib/autoload/kuroko2/workflow/notifier/hipchat.rb, line 75
def notify_finished
  if @definition.hipchat_notify_finished?
    message = build_message(level: 'SUCCESS', text: message_builder.finished_text)
    send_to_hipchat(message)
  end
end
notify_launch() click to toggle source
# File lib/autoload/kuroko2/workflow/notifier/hipchat.rb, line 17
def notify_launch
  if @definition.hipchat_notify_finished?
    message = build_message(level: 'SUCCESS', text: message_builder.launched_text)
    message << "<br>"
    message << @instance.logs.reverse.detect{ |log| log.level == 'INFO' }.try!(:message)

    send_to_hipchat(message, color: 'yellow')
  end
end
notify_long_elapsed_time() click to toggle source
# File lib/autoload/kuroko2/workflow/notifier/hipchat.rb, line 87
def notify_long_elapsed_time
  message = build_message(level: 'WARNING', text: message_builder.long_elapsed_time_text)
  send_to_hipchat(message, color: 'red')
end
notify_retrying() click to toggle source
# File lib/autoload/kuroko2/workflow/notifier/hipchat.rb, line 27
def notify_retrying
  if @definition.hipchat_notify_finished
    message = build_message(level: 'SUCCESS', text: message_builder.retrying_text)
    message << "<br>"
    message << @instance.logs.last(2).first.message

    send_to_hipchat(message, color: 'yellow')
  end
end
notify_skipping() click to toggle source
# File lib/autoload/kuroko2/workflow/notifier/hipchat.rb, line 37
def notify_skipping
  if @definition.hipchat_notify_finished
    message = build_message(level: 'SUCCESS', text: message_builder.skipping_text)
    message << "<br>"
    message << @instance.logs.last(2).first.message

    send_to_hipchat(message, color: 'yellow')
  end
end

Private Instance Methods

build_message(level: , text:) click to toggle source
# File lib/autoload/kuroko2/workflow/notifier/hipchat.rb, line 101
def build_message(level: , text:)
  message = "<b>[#{level}]</b> "
  message << text
  message << "(<a href='#{message_builder.job_instance_path}'>Open</a>)"
end
notify_hipchat?() click to toggle source
# File lib/autoload/kuroko2/workflow/notifier/hipchat.rb, line 114
def notify_hipchat?
  @definition.hipchat_room.present?
end
send_additional_text_to_hipchat() click to toggle source
# File lib/autoload/kuroko2/workflow/notifier/hipchat.rb, line 107
def send_additional_text_to_hipchat
  if @definition.hipchat_additional_text.present?
    message = message_builder.additional_text
    send_to_hipchat(message, color: 'red', notify: true, format: 'text')
  end
end
send_to_hipchat(message, color: 'green', notify: false, format: 'html') click to toggle source
# File lib/autoload/kuroko2/workflow/notifier/hipchat.rb, line 94
def send_to_hipchat(message, color: 'green', notify: false, format: 'html')
  if notify_hipchat?

    hipchat[@definition.hipchat_room].send(USER_NAME, message, color: color, notify: notify, message_format: format)
  end
end