Skip to content

Commit

Permalink
Merge pull request #125 from sahilda/fix/slack_templates
Browse files Browse the repository at this point in the history
Add specific pr and branch templates for slack
  • Loading branch information
BanzaiMan committed Apr 3, 2019
2 parents da14b47 + b25088b commit 93091e7
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/travis/addons/slack/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def message(channel)
end

def message_text
lines = Array(template_from_config || default_template)
lines = notification_template
lines.map {|line| Util::Template.new(line, payload, source: :slack).interpolate}.join("\n")
end

Expand All @@ -81,21 +81,23 @@ def color
end
end

def template_from_config
slack_config.is_a?(Hash) ? slack_config[:template] : nil
end

def slack_config
build[:config].try(:[], :notifications).try(:[], :slack) || {}
end

def default_template
if pull_request?
PULL_REQUEST_MESSAGE_TEMPLATE
def notification_template
if template_from_config(:template)
Array(template_from_config(:template))
elsif pull_request?
Array(template_from_config(:pr_template) || PULL_REQUEST_MESSAGE_TEMPLATE)
else
BRANCH_BUILD_MESSAGE_TEMPLATE
Array(template_from_config(:branch_template) || BRANCH_BUILD_MESSAGE_TEMPLATE)
end
end

def template_from_config(key)
slack_config.is_a?(Hash) ? slack_config[key] : nil
end
end
end
end
Expand Down

0 comments on commit 93091e7

Please sign in to comment.