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

Added support more channels #33

Merged
merged 1 commit into from
Jan 26, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ As with the other tasks, it is also possible to notify failures manually:

Any of the defaults can be over-ridden in `config/deploy.rb`:

set :slack_channel, '#devops'
set :slack_channel, ['#devops', '#other-channel']
set :slack_username, 'Deploybot'
set :slack_emoji, ':trollface:'
set :slack_user, ENV['GIT_AUTHOR_NAME']
Expand Down
2 changes: 1 addition & 1 deletion capistrano-slackify.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |spec|
spec.name = 'capistrano-slackify'
spec.version = '2.9.0'
spec.version = '2.10.0'
spec.authors = ['seenmyfate']
spec.email = ['[email protected]']
spec.summary = %q{Publish deployment notifications to Slack via the incoming webhooks integration}
Expand Down
30 changes: 17 additions & 13 deletions lib/capistrano/tasks/slackify.cap
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ namespace :slack do

if fetch(:slack_notify_events).include? :started
info 'Notifying Slack of deploy starting'

execute :curl, '-X POST', '-s', '--data-urlencode',
Slackify::Payload.build(self, :starting),
fetch(:slack_url)
Array(fetch(:slack_channel)).each {|channel|
execute :curl, '-X POST', '-s', '--data-urlencode',
Slackify::Payload.build(self, :starting, channel),
fetch(:slack_url)
}
end
end
end
Expand All @@ -24,11 +25,12 @@ namespace :slack do

if fetch(:slack_notify_events).include? :finished
info 'Notifying Slack of deploy finished'

execute :curl, '-X POST', '-s', '--data-urlencode',
Slackify::Payload.build(self, :success),
fetch(:slack_url)
end
Array(fetch(:slack_channel)).each {|channel|
execute :curl, '-X POST', '-s', '--data-urlencode',
Slackify::Payload.build(self, :success, channel),
fetch(:slack_url)
}
end
end
end
after 'deploy:finished', 'slack:notify_finished'
Expand All @@ -42,9 +44,11 @@ namespace :slack do
if fetch(:slack_notify_events).include? :failed
info 'Notifying Slack of deploy failed'

execute :curl, '-X POST', '-s', '--data-urlencode',
Slackify::Payload.build(self, :failed),
fetch(:slack_url)
Array(fetch(:slack_channel)).each {|channel|
execute :curl, '-X POST', '-s', '--data-urlencode',
Slackify::Payload.build(self, :failed, channel),
fetch(:slack_url)
}
end
end
end
Expand All @@ -53,7 +57,7 @@ end

namespace :load do
task :defaults do
set :slack_channel, '#general'
set :slack_channel, ['#general']
set :slack_username, 'Capistrano'
set :slack_emoji, ':ghost:'
set :slack_parse, 'default'
Expand Down
12 changes: 6 additions & 6 deletions lib/slackify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ def initialize(context, status)
@status = status
end

def self.build(context, status)
new(context, status).build
def self.build(context, status, channel)
new(context, status).build(channel)
end

def build
"'payload=#{payload}'"
def build(channel)
"'payload=#{payload(channel)}'"
end

def payload
def payload(channel)
fields = fetch(:slack_fields).each_with_object([]) { |field, fields|
if fields_map[field].fetch(:value).respond_to?(:call)
field_data = fields_map[field]
Expand All @@ -29,7 +29,7 @@ def payload

MultiJson.dump(
{
channel: fetch(:slack_channel),
channel: channel,
username: fetch(:slack_username),
icon_emoji: fetch(:slack_emoji),
parse: fetch(:slack_parse),
Expand Down
8 changes: 6 additions & 2 deletions spec/lib/slackify_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Slackify
let(:context) {
{
slack_channel: '#general',
slack_username:'Capistrano',
slack_username: 'Capistrano',
slack_emoji: ':ghost:',
slack_parse: 'default',
slack_user: 'You',
Expand Down Expand Up @@ -42,7 +42,11 @@ module Slackify
let(:text) { context.fetch(:slack_text) }

let(:builded_payload) {
Payload.build(context, :success)
Payload.build(context, :success, slack_channel)
}

let(:slack_channel) {
context.fetch(:slack_channel)
}

it 'returns the payload with the specified text' do
Expand Down