Class: Vidar::SlackNotification
- Inherits:
-
Object
- Object
- Vidar::SlackNotification
- Defined in:
- lib/vidar/slack_notification.rb
Class Method Summary collapse
Instance Method Summary collapse
- #configured? ⇒ Boolean
- #deliver(message:, color: default_color) ⇒ Object
- #failure ⇒ Object
-
#initialize(github:, revision:, revision_name:, deploy_config:, build_url: nil, connection: Faraday.new) ⇒ SlackNotification
constructor
A new instance of SlackNotification.
- #perform_with(data) ⇒ Object
- #success ⇒ Object
Constructor Details
#initialize(github:, revision:, revision_name:, deploy_config:, build_url: nil, connection: Faraday.new) ⇒ SlackNotification
Returns a new instance of SlackNotification.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/vidar/slack_notification.rb', line 13 def initialize(github:, revision:, revision_name:, deploy_config:, build_url: nil, connection: Faraday.new) @github = github @revision = revision @revision_name = revision_name @build_url = build_url @deploy_name = deploy_config.name @deploy_url = deploy_config.url @default_color = deploy_config.default_color @success_color = deploy_config.success_color @failure_color = deploy_config.failure_color @webhook_url = deploy_config.slack_webhook_url @connection = connection end |
Class Method Details
Instance Method Details
#configured? ⇒ Boolean
27 28 29 |
# File 'lib/vidar/slack_notification.rb', line 27 def configured? !webhook_url.to_s.empty? end |
#deliver(message:, color: default_color) ⇒ Object
47 48 49 |
# File 'lib/vidar/slack_notification.rb', line 47 def deliver(message:, color: default_color) perform_with data(message:, color:) end |
#failure ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/vidar/slack_notification.rb', line 31 def failure = [ "<!channel> Failed deploy of #{github_link} to #{deploy_link}.", build_link, ] perform_with data(message:, color: failure_color) end |
#perform_with(data) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/vidar/slack_notification.rb', line 51 def perform_with(data) connection.post do |req| req.url webhook_url req.headers['Content-Type'] = 'application/json' req.body = data.to_json end end |
#success ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/vidar/slack_notification.rb', line 39 def success = [ "Successful deploy of #{github_link} to #{deploy_link}.", build_link, ] perform_with data(message:, color: success_color) end |