Class: OpsDeploy::CLI::Notifier::Slack

Inherits:
Generic
  • Object
show all
Defined in:
lib/ops_deploy/cli/notifier.rb

Overview

A notification class for Slack

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stack, options) ⇒ Slack

Returns a new instance of Slack.



74
75
76
77
78
79
# 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

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



72
73
74
# File 'lib/ops_deploy/cli/notifier.rb', line 72

def options
  @options
end

#slack_notifierObject

Returns the value of attribute slack_notifier.



71
72
73
# File 'lib/ops_deploy/cli/notifier.rb', line 71

def slack_notifier
  @slack_notifier
end

Instance Method Details

#failure_notify(message) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# 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) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# 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) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# 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