Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specific pr and branch templates for slack #125

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions lib/travis/addons/slack/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,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 @@ -76,21 +76,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)

This comment was marked as spam.

Copy link
Contributor

@BanzaiMan BanzaiMan Apr 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The precedence of the various templates seems a little strange. I would expect the preference of more specific ones (pull_request_template and branch_build_template) to the general one (template), but the current logic is the reverse.

Furthermore, while I neglected this PR, we added a couple of new event types (cron, api) that are on par with push and PR. It stands to reason that we support templates for these, too.

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_build_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