lib/vidar/slack_notification.rb in vidar-1.2.0 vs lib/vidar/slack_notification.rb in vidar-1.3.0
- old
+ new
@@ -3,11 +3,10 @@
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.parse(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
@@ -18,16 +17,23 @@
def configured?
!webhook_url.to_s.empty?
end
def failure
- message = "Failed deploy of #{github_link} to #{deploy_link} :fire: <!channel> #{build_link}"
+ 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}. #{build_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)
@@ -44,21 +50,22 @@
private
attr_reader :github, :revision, :revision_name,
:deploy_name, :deploy_url, :webhook_url,
:default_color, :success_color, :failure_color,
- :connection, :build_url, :build_hostname
+ :connection, :build_url
def data(message:, color:)
+ text = [message].flatten.compact.join("\n")
{
"attachments": [
{
"title": github,
"title_link": github_url,
"color": color,
- "text": message,
- "fallback": message
+ "text": text,
+ "fallback": text,
}
]
}
end
@@ -73,9 +80,9 @@
def deploy_link
"<#{deploy_url}|#{deploy_name}>"
end
def build_link
- build_url && "<#{build_url}|View the build on #{build_hostname}>"
+ build_url && "<#{build_url}|View the build.>"
end
end
end