Class: Kuroko2::Workflow::Notifier::Hipchat

Inherits:
Object
  • Object
show all
Defined in:
lib/autoload/kuroko2/workflow/notifier/hipchat.rb

Constant Summary collapse

USER_NAME =
'kuroko2'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance) ⇒ Hipchat

Returns a new instance of Hipchat.



9
10
11
12
13
14
# File 'lib/autoload/kuroko2/workflow/notifier/hipchat.rb', line 9

def initialize(instance)
  @instance   = instance
  @definition = instance.job_definition
  @hipchat    = Kuroko2.config.notifiers.hipchat.api_token
  @message_builder = Workflow::Notifier::Concerns::ChatMessageBuilder.new(instance)
end

Instance Attribute Details

#hipchatObject (readonly)

Returns the value of attribute hipchat.



5
6
7
# File 'lib/autoload/kuroko2/workflow/notifier/hipchat.rb', line 5

def hipchat
  @hipchat
end

#message_builderObject (readonly)

Returns the value of attribute message_builder.



5
6
7
# File 'lib/autoload/kuroko2/workflow/notifier/hipchat.rb', line 5

def message_builder
  @message_builder
end

Instance Method Details

#notify_cancellationObject



46
47
48
49
50
51
52
53
54
# File 'lib/autoload/kuroko2/workflow/notifier/hipchat.rb', line 46

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_criticalObject



65
66
67
68
69
70
71
72
# File 'lib/autoload/kuroko2/workflow/notifier/hipchat.rb', line 65

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_failureObject



56
57
58
59
60
61
62
63
# File 'lib/autoload/kuroko2/workflow/notifier/hipchat.rb', line 56

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_finishedObject



74
75
76
77
78
79
# File 'lib/autoload/kuroko2/workflow/notifier/hipchat.rb', line 74

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_launchObject



16
17
18
19
20
21
22
23
24
# File 'lib/autoload/kuroko2/workflow/notifier/hipchat.rb', line 16

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_timeObject



81
82
83
84
# File 'lib/autoload/kuroko2/workflow/notifier/hipchat.rb', line 81

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_retryingObject



26
27
28
29
30
31
32
33
34
# File 'lib/autoload/kuroko2/workflow/notifier/hipchat.rb', line 26

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_skippingObject



36
37
38
39
40
41
42
43
44
# File 'lib/autoload/kuroko2/workflow/notifier/hipchat.rb', line 36

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