Class: PuppetWebhook::Chatops::Rocketchat

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

Overview

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Rocketchat.



7
8
9
10
11
12
13
# File 'lib/plugins/chatops/rocketchat.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/rocketchat.rb', line 15

def notify
  notifier = RocketChat::Notifier.new @url, http_options: @options[:http_options]
  notifier.username = @user
  notifier.channel = @channel

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

  msg = "r10k deployment of Puppet environment/module #{target} started..."

  attachment = format_attachment(target)

  notifier.ping(msg, icon_emoji: @options[:icon_emoji], attachments: [attachment])
end