phallstrom / slackistrano

Slack integration for Capistrano deployments.
MIT License
373 stars 74 forks source link

No colour for slack notifications #63

Closed grappler closed 7 years ago

grappler commented 7 years ago

I am using slackistrano (3.1.0) with the webhook. When we were using version (2.0.1) there was always a colour for the notifications.

How can I get that back?

image

phallstrom commented 7 years ago

What does the slackistrano settings look like in your config/deploy.rb?

grappler commented 7 years ago

Like this

set :slackistrano, {
  channel: '#deploy',
  webhook: 'https://hooks.slack.com/services/'
}
phallstrom commented 7 years ago

@grappler You need to make your own custom messaging class and tweak the payload.

See https://github.com/phallstrom/slackistrano#customizing-the-messaging

Using a class like this:

module Slackistrano
  class CustomMessaging < Messaging::Base

    def payload_for_updated
      make_message(super.merge(color: 'good'))
    end

    def payload_for_reverted
      make_message(super.merge(color: 'warning'))
    end

    def payload_for_failed
      make_message(super.merge(color: 'danger'))
    end

    private ##################################################

    def make_message(options={})
      attachment = options.reject{|k, v| v.nil? }
      {attachments: [attachment]}
    end

  end
end
grappler commented 7 years ago

Thank you for your help! I not well versed in ruby so struggled how I could adapt the example.

grappler commented 7 years ago

I was able to get it to a point where we have created our own gem with this included. https://rubygems.org/gems/capistrano-wearerequired