class OpsDeploy::CLI::Notifier::Slack

A notification class for Slack

Attributes

options[RW]
slack_notifier[RW]

Public Class Methods

new(stack, options) click to toggle source
# File lib/ops_deploy/cli/notifier.rb, line 74
def initialize(stack, options)
  @stack = stack
  @options = options
  @options[:username] = 'OpsDeploy' unless @options[:username]
  @slack_notifier = Slack::Notifier.new @options[:webhook_url], @options
end

Public Instance Methods

failure_notify(message) click to toggle source
# File lib/ops_deploy/cli/notifier.rb, line 112
def failure_notify(message)
  message = message.gsub(/\[[0-9;]+?m/, '')

  recipients.each do |recipient|
    @slack_notifier.ping '', channel: recipient, attachments: [
      {
        fallback: message,
        text: "#{message} <!channel>",
        author_name: @stack.name,
        author_link: stack_link(@stack),
        color: 'danger'
      }
    ]
  end
end
notify(message) click to toggle source
# File lib/ops_deploy/cli/notifier.rb, line 81
def notify(message)
  message = message.gsub(/\[[0-9;]+?m/, '')

  recipients.each do |recipient|
    @slack_notifier.ping '', channel: recipient, attachments: [
      {
        fallback: message,
        author_name: @stack.name,
        author_link: stack_link(@stack),
        text: message
      }
    ]
  end
end
success_notify(message) click to toggle source
# File lib/ops_deploy/cli/notifier.rb, line 96
def success_notify(message)
  message = message.gsub(/\[[0-9;]+?m/, '')

  recipients.each do |recipient|
    @slack_notifier.ping '', channel: recipient, attachments: [
      {
        fallback: message,
        text: message,
        author_name: @stack.name,
        author_link: stack_link(@stack),
        color: 'good'
      }
    ]
  end
end

Private Instance Methods

recipients() click to toggle source
# File lib/ops_deploy/cli/notifier.rb, line 130
def recipients
  names = [options[:channel]]
  names << "@#{options[:notify_user]}" if options[:notify_user]
  names
end