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.



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

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_cancellationObject



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

def notify_cancellation
  if @definition.notify_cancellation
    send_attachment_message_to_slack(
      level: 'WARNING',
      text: message_builder.failure_text,
      body: @instance.logs.last(2).first.message,
    )
  end
end

#notify_criticalObject



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

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



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

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



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

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

#notify_long_elapsed_timeObject



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

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

#notify_workingObject



21
22
23
# File 'lib/autoload/kuroko2/workflow/notifier/slack.rb', line 21

def notify_working
  # do nothing
end