lib/capistrano/tasks/slackify.cap in capistrano-slackify-2.0.1 vs lib/capistrano/tasks/slackify.cap in capistrano-slackify-2.1.0

- old
+ new

@@ -3,12 +3,12 @@ ':slack_subdomain and :slack_token must be set' task :notify_started do run_locally do info 'Notifying Slack of deploy starting' set :time_started, Time.now.to_i - execute :curl, '-X POST', - '--data-urlencode', Slackify::Payload.build(self, :start), + execute :curl, '-X POST', '--data-urlencode', + Slackify::Payload.build(self, fetch(:slack_deploy_starting_text)), fetch(:slack_url) end end before 'deploy:starting', 'slack:notify_started' @@ -16,16 +16,29 @@ ':slack_subdomain and :slack_token must be set' task :notify_finished do run_locally do info 'Notifying Slack of deploy finished' set :time_finished, Time.now.to_i - execute :curl, '-X POST', - '--data-urlencode', Slackify::Payload.build(self, :finish), + execute :curl, '-X POST', '--data-urlencode', + Slackify::Payload.build(self, fetch(:slack_text)), fetch(:slack_url) end end after 'deploy:finished', 'slack:notify_finished' + + desc 'Notify Slack of a deployment failure via the incoming webhooks ' \ + 'integration - :slack_subdomain and :slack_token must be set' + task :notify_failed do + run_locally do + info 'Notifying Slack of deploy failed' + set :time_finished, Time.now.to_i + execute :curl, '-X POST', '--data-urlencode', + Slackify::Payload.build(self, fetch(:slack_deploy_failed_text)), + fetch(:slack_url) + end + end + after 'deploy:failed', 'slack:notify_failed' end namespace :load do task :defaults do set :slack_channel, '#general' @@ -40,8 +53,11 @@ "#{fetch(:application)} deployed to #{fetch(:stage)} by #{fetch(:slack_user)} " \ "in #{time_elapsed} seconds." } set :slack_deploy_starting_text, -> { "#{fetch(:stage)} deploy starting with revision/branch #{fetch(:current_revision, fetch(:branch))} for #{fetch(:application)}" + } + set :slack_deploy_failed_text, -> { + "#{fetch(:stage)} deploy of #{fetch(:application)} with revision/branch #{fetch(:current_revision, fetch(:branch))} failed" } end end