Class: Kuroko2::Workflow::Notifier::Slack

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

Defined Under Namespace

Modules: LevelToColor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance) ⇒ Slack

Returns a new instance of Slack.



15
16
17
18
19
20
# File 'lib/autoload/kuroko2/workflow/notifier/slack.rb', line 15

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

Instance Attribute Details

#message_builderObject (readonly)

Returns the value of attribute message_builder.



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

def message_builder
  @message_builder
end

#webhook_urlObject (readonly)

Returns the value of attribute webhook_url.



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

def webhook_url
  @webhook_url
end

Instance Method Details

#notify_back_to_normalObject



91
92
93
94
95
96
# File 'lib/autoload/kuroko2/workflow/notifier/slack.rb', line 91

def notify_back_to_normal
  send_attachment_message_to_slack(
    level: 'SUCCESS',
    text: message_builder.back_to_normal_text,
  )
end

#notify_cancellationObject



52
53
54
55
56
57
58
59
60
# File 'lib/autoload/kuroko2/workflow/notifier/slack.rb', line 52

def notify_cancellation
  if @definition.notify_cancellation || @definition.hipchat_notify_finished?
    send_attachment_message_to_slack(
      level: 'WARNING',
      text: message_builder.failure_text,
      body: @instance.logs.reverse.detect{ |log| log.level == 'WARN' }.try!(:message),
    )
  end
end

#notify_criticalObject



72
73
74
75
76
77
78
79
80
# File 'lib/autoload/kuroko2/workflow/notifier/slack.rb', line 72

def notify_critical
  send_attachment_message_to_slack(
    level: 'CRITICAL',
    text: message_builder.failure_text,
    body: @instance.logs.last(2).first.message,
  )

  send_additional_text_to_slack
end

#notify_failureObject



62
63
64
65
66
67
68
69
70
# File 'lib/autoload/kuroko2/workflow/notifier/slack.rb', line 62

def notify_failure
  send_attachment_message_to_slack(
    level: 'FAILURE',
    text: message_builder.failure_text,
    body: @instance.logs.last(2).first.message,
  )

  send_additional_text_to_slack
end

#notify_finishedObject



82
83
84
85
86
87
88
89
# File 'lib/autoload/kuroko2/workflow/notifier/slack.rb', line 82

def notify_finished
  if @definition.hipchat_notify_finished?
    send_attachment_message_to_slack(
      level: 'SUCCESS',
      text: message_builder.finished_text,
    )
  end
end

#notify_launchObject



22
23
24
25
26
27
28
29
30
# File 'lib/autoload/kuroko2/workflow/notifier/slack.rb', line 22

def notify_launch
  if @definition.hipchat_notify_finished?
    send_attachment_message_to_slack(
      level: 'INFO',
      text: message_builder.launched_text,
      body: @instance.logs.reverse.detect{ |log| log.level == 'INFO' }.try!(:message),
    )
  end
end

#notify_long_elapsed_timeObject



98
99
100
101
102
103
# File 'lib/autoload/kuroko2/workflow/notifier/slack.rb', line 98

def notify_long_elapsed_time
  send_attachment_message_to_slack(
    level: 'WARNING',
    text: message_builder.long_elapsed_time_text,
  )
end

#notify_retryingObject



32
33
34
35
36
37
38
39
40
# File 'lib/autoload/kuroko2/workflow/notifier/slack.rb', line 32

def notify_retrying
  if @definition.hipchat_notify_finished?
    send_attachment_message_to_slack(
      level: 'INFO',
      text: message_builder.retrying_text,
      body: @instance.logs.last(2).first.message,
    )
  end
end

#notify_skippingObject



42
43
44
45
46
47
48
49
50
# File 'lib/autoload/kuroko2/workflow/notifier/slack.rb', line 42

def notify_skipping
  if @definition.hipchat_notify_finished?
    send_attachment_message_to_slack(
      level: 'INFO',
      text: message_builder.skipping_text,
      body: @instance.logs.last(2).first.message,
    )
  end
end