README.md in slackistrano-3.8.1 vs README.md in slackistrano-3.8.2

- old
+ new

@@ -64,10 +64,30 @@ team: 'your-team-name', token: 'your-token' } ``` +### Optional Configuration & Overrides + +By default Slackistrano will use a default icon and username. These, can be +overriden if you are using the default messaging class (ie. have not specified +your own). + +1. Configure per instructions above. +2. Add the following to `config/deploy.rb`: + + ```ruby + set :slackistrano, { + ... + username: 'Foobar the Deployer', + icon_emoji: ':thumbsup:', # takes precedence over icon_url + icon_url: 'https://avatars2.githubusercontent.com/u/16705?v=4&s=40', + ... + } + ``` + + ### Test your Configuration Test your setup by running the following command. This will post each stage's message to Slack in turn. @@ -84,81 +104,86 @@ You can customize the messaging posted to Slack by providing your own messaging class and overriding several methods. Here is one example: ```ruby -module Slackistrano - class CustomMessaging < Messaging::Base +if defined?(Slackistrano::Messaging) + module Slackistrano + class CustomMessaging < Messaging::Base - # Send failed message to #ops. Send all other messages to default channels. - # The #ops channel must exist prior. - def channels_for(action) - if action == :failed - "#ops" - else - super - end - end + # Send failed message to #ops. Send all other messages to default channels. + # The #ops channel must exist prior. + def channels_for(action) + if action == :failed + "#ops" + else + super + end + end - # Suppress updating message. - def payload_for_updating - nil - end + # Suppress updating message. + def payload_for_updating + nil + end - # Suppress reverting message. - def payload_for_reverting - nil - end + # Suppress reverting message. + def payload_for_reverting + nil + end - # Fancy updated message. - # See https://api.slack.com/docs/message-attachments - def payload_for_updated - { - attachments: [{ - color: 'good', - title: 'Integrations Application Deployed :boom::bangbang:', - fields: [{ - title: 'Environment', - value: stage, - short: true - }, { - title: 'Branch', - value: branch, - short: true - }, { - title: 'Deployer', - value: deployer, - short: true - }, { - title: 'Time', - value: elapsed_time, - short: true - }], - fallback: super[:text] - }] - } - end + # Fancy updated message. + # See https://api.slack.com/docs/message-attachments + def payload_for_updated + { + attachments: [{ + color: 'good', + title: 'Integrations Application Deployed :boom::bangbang:', + fields: [{ + title: 'Environment', + value: stage, + short: true + }, { + title: 'Branch', + value: branch, + short: true + }, { + title: 'Deployer', + value: deployer, + short: true + }, { + title: 'Time', + value: elapsed_time, + short: true + }], + fallback: super[:text] + }] + } + end - # Default reverted message. Alternatively simply do not redefine this - # method. - def payload_for_reverted - super - end + # Default reverted message. Alternatively simply do not redefine this + # method. + def payload_for_reverted + super + end - # Slightly tweaked failed message. - # See https://api.slack.com/docs/message-formatting - def payload_for_failed - payload = super - payload[:text] = "OMG :fire: #{payload[:text]}" - payload - end + # Slightly tweaked failed message. + # See https://api.slack.com/docs/message-formatting + def payload_for_failed + payload = super + payload[:text] = "OMG :fire: #{payload[:text]}" + payload + end - # Override the deployer helper to pull the full name from the password file. - # See https://github.com/phallstrom/slackistrano/blob/master/lib/slackistrano/messaging/helpers.rb - def deployer - Etc.getpwnam(ENV['USER']).gecos - end - end + # Override the deployer helper to pull the best name available (git, password file, env vars). + # See https://github.com/phallstrom/slackistrano/blob/master/lib/slackistrano/messaging/helpers.rb + def deployer + name = `git config user.name`.strip + name = nil if name.empty? + name ||= Etc.getpwnam(ENV['USER']).gecos || ENV['USER'] || ENV['USERNAME'] + name + end + end + end end ``` The output would look like this: ![Custom Messaging](https://raw.githubusercontent.com/phallstrom/slackistrano/overhaul/images/custom_messaging.jpg)