lib/vidar/slack_notification.rb in vidar-1.0.0 vs lib/vidar/slack_notification.rb in vidar-1.1.0
- old
+ new
@@ -1,11 +1,13 @@
module Vidar
class SlackNotification
- def initialize(github:, revision:, revision_name:, deploy_config:)
+ def initialize(github:, revision:, revision_name:, deploy_config:, build_url: nil)
@github = github
@revision = revision
@revision_name = revision_name
+ @build_url = build_url
+ @build_hostname = URI(build_url || '').hostname
@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
@@ -16,16 +18,16 @@
def configured?
!webhook_url.to_s.empty?
end
def failure
- message = "Failed deploy of #{github_link} to #{deploy_link} :fire: <!channel>"
+ message = "Failed deploy of #{github_link} to #{deploy_link} :fire: <!channel> #{build_link}"
perform_with data(message: message, color: failure_color)
end
def success
- message = "Successful deploy of #{github_link} to #{deploy_link}"
+ message = "Successful deploy of #{github_link} to #{deploy_link}. #{build_link}"
perform_with data(message: message, color: success_color)
end
def deliver(message:, color: default_color)
perform_with data(message: message, color: color)
@@ -42,11 +44,11 @@
private
attr_reader :github, :revision, :revision_name,
:deploy_name, :deploy_url, :webhook_url,
:default_color, :success_color, :failure_color,
- :connection
+ :connection, :build_url, :build_hostname
def data(message:, color:)
{
"attachments": [
{
@@ -68,8 +70,12 @@
"<#{github_url}|#{revision_name}>"
end
def deploy_link
"<#{deploy_url}|#{deploy_name}>"
+ end
+
+ def build_link
+ build_url && "<#{build_url}|View the build on #{build_hostname}>"
end
end
end