lib/slackistrano/tasks/slack.rake in slackistrano-0.1.8 vs lib/slackistrano/tasks/slack.rake in slackistrano-0.1.9

- old
+ new

@@ -1,8 +1,16 @@ - namespace :slack do namespace :deploy do + def make_attachments(stage, options={}) + attachments = options.merge({ + title: fetch(:"slack_title_#{stage}"), + pretext: fetch(:"slack_pretext_#{stage}"), + text: fetch(:"slack_msg_#{stage}"), + mrkdwn_in: [:text, :pretext] + }).reject{|k, v| v.nil? } + [attachments] + end task :starting do if fetch(:slack_run_starting) run_locally do Slackistrano.post( @@ -13,14 +21,11 @@ payload: { channel: fetch(:slack_channel_starting) || fetch(:slack_channel), username: fetch(:slack_username), icon_url: fetch(:slack_icon_url), icon_emoji: fetch(:slack_icon_emoji), - attachments: [{ - text: fetch(:slack_msg_starting), - mrkdwn_in: [:text] - }] + attachments: make_attachments(:starting) } ) end end end @@ -36,15 +41,11 @@ payload: { channel: fetch(:slack_channel_finished) || fetch(:slack_channel), username: fetch(:slack_username), icon_url: fetch(:slack_icon_url), icon_emoji: fetch(:slack_icon_emoji), - attachments: [{ - color: 'good', - text: fetch(:slack_msg_finished), - mrkdwn_in: [:text] - }] + attachments: make_attachments(:finished, color: 'good') } ) end end end @@ -60,15 +61,11 @@ payload: { channel: fetch(:slack_channel_failed) || fetch(:slack_channel), username: fetch(:slack_username), icon_url: fetch(:slack_icon_url), icon_emoji: fetch(:slack_icon_emoji), - attachments: [{ - color: 'danger', - text: fetch(:slack_msg_failed), - mrkdwn_in: [:text] - }] + attachments: make_attachments(:failed, color: 'danger') } ) end end end @@ -99,7 +96,13 @@ set :slack_run_finished, -> { true } # Set to false to disable finished message. set :slack_run_failed, -> { true } # Set to false to disable failure message. set :slack_msg_starting, -> { "#{ENV['USER'] || ENV['USERNAME']} has started deploying branch #{fetch :branch} of #{fetch :application} to #{fetch :stage, 'an unknown stage'}" } set :slack_msg_finished, -> { "#{ENV['USER'] || ENV['USERNAME']} has finished deploying branch #{fetch :branch} of #{fetch :application} to #{fetch :stage, 'an unknown stage'}" } set :slack_msg_failed, -> { "#{ENV['USER'] || ENV['USERNAME']} failed to deploy branch #{fetch :branch} of #{fetch :application} to #{fetch :stage, 'an unknown stage'}" } + set :slack_title_starting, -> { nil } + set :slack_title_finished, -> { nil } + set :slack_title_failed, -> { nil } + set :slack_pretext_starting, -> { nil } + set :slack_pretext_finished, -> { nil } + set :slack_pretext_failed, -> { nil } end end