Class: PuppetWebhook::Chatops::Slack

Inherits:
Object
  • Object
show all
Defined in:
lib/plugins/chatops/slack.rb

Overview

Sets up Slack object that will send notifications to Slack via a webhook.

Instance Method Summary collapse

Constructor Details

#initialize(channel, url, user, message, options = {}) ⇒ Slack

Returns a new instance of Slack.



7
8
9
10
11
12
13
# File 'lib/plugins/chatops/slack.rb', line 7

def initialize(channel, url, user, message, options = {})
  @channel = channel
  @url = url
  @user = user
  @message = message
  @options = options
end

Instance Method Details

#notifyObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/plugins/chatops/slack.rb', line 15

def notify
  notifier = ::Slack::Notifier.new @url, http_options: @options[:http_options]

  target = if @message[:branch]
             @message[:branch]
           elsif @message[:module]
             @message[:module]
           end

  msg = format_message(target)

  notifier.post text: msg[:fallback],
                channel: @channel,
                username: @user,
                icon_emoji: @options[:icon_emoji],
                attachments: [msg]
end