Class: Jackal::Stacks::Formatter::Slack

Inherits:
Formatter
  • Object
show all
Defined in:
lib/jackal-stacks/formatter/slack.rb

Overview

Format result for slack notification

Constant Summary collapse

SOURCE =

Source service

'stacks'
DESTINATION =

Destination service

'slack'
NOTIFY_ON =
%w(created updated destroyed)

Instance Method Summary collapse

Instance Method Details

#format(payload) ⇒ Object

Format payload

Parameters:

  • payload (Smash)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jackal-stacks/formatter/slack.rb', line 19

def format(payload)
  if(payload.get(:data, :stacks))
    unless((notify = payload.fetch(:data, :stacks, {}).keys & NOTIFY_ON).empty?)
      msgs = payload.fetch(:data, :slack, :messages, [])
      msgs << Smash.new(
        :description => "Stacks result: #{notify.first}",
        :message => [
          "Stack has been #{notify.first} [name: #{payload.get(:data, :stacks, :name)}]",
          "* Template: #{payload.get(:data, :stacks, :template)}",
          "* Repository: #{payload.get(:data, :code_fetcher, :info, :owner)}/#{payload.get(:data, :code_fetcher, :info, :name)}",
          "* Reference: #{payload.get(:data, :code_fetcher, :info, :reference)}",
          "* SHA: #{payload.get(:data, :code_fetcher, :info, :commit_sha)}"
        ].join("\n"),
        :color => :good
      )
      payload.set(:data, :slack, :messages, msgs)
    end
  end
end