Sha256: f6539b0b3c2b0963c6548bd607b6a38e03285f638e6563f8423e062ea280b094

Contents?: true

Size: 1.83 KB

Versions: 15

Compression:

Stored size: 1.83 KB

Contents

require 'slack-notifier'

module Taperole
  module Notifiers
    class Slack
      def initialize(webhook_url, deploy_info)
        @notifier = ::Slack::Notifier.new webhook_url
        @notifier.username = 'Tape'
        @deploy_info = deploy_info
      end

      def update(status)
        @status = status
        @notifier.ping(
          "",
          # TODO: Fill in real icon url
          icon_url: 'https://image.freepik.com/free-icon/adhesive-tape_318-42276.png',
          attachments: attachments
        )
      end

      private

      def attachments
        a = {}
        a[:text] = message
        a[:color] = color
        a[:fields] = fields unless @status == :start
        [a]
      end

      def fields
        [
          {
            title: "Project",
            value: project_link,
            short: true
          },
          {
            title: "Hosts/Env",
            value: @deploy_info[:hosts],
            short: true
          },
          {
            title: "Author",
            value: @deploy_info[:user],
            short: true
          }
        ]
      end

      def color
        case @status
        when :start   then "#a9a9a9"
        when :success then "good"
        when :fail    then "danger"
        end
      end

      def gh_link_base
        @deploy_info[:repo].sub(/^git@github.com:/, 'http://github.com/').sub(/.git$/, '')
      end

      def project_link
        "<#{gh_link_base}|#{@deploy_info[:app_name]}>"
      end

      def message
        case @status
        when :start
          user  = @deploy_info[:user]
          app   = @deploy_info[:app_name]
          hosts = @deploy_info[:hosts]
          "#{user} started deploying #{app} to #{hosts}"
        when :success
          "The deploy was successful!"
        when :fail
          "The deploy failed!"
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
taperole-2.1.1 lib/taperole/notifiers/slack.rb
taperole-2.1.0 lib/taperole/notifiers/slack.rb
taperole-2.0.7 lib/taperole/notifiers/slack.rb
taperole-2.0.6 lib/taperole/notifiers/slack.rb
taperole-2.0.5 lib/taperole/notifiers/slack.rb
taperole-2.0.4 lib/taperole/notifiers/slack.rb
taperole-2.0.3 lib/taperole/notifiers/slack.rb
taperole-2.0.2 lib/taperole/notifiers/slack.rb
taperole-2.0.1 lib/taperole/notifiers/slack.rb
taperole-2.0.0 lib/taperole/notifiers/slack.rb
taperole-1.8.2 lib/taperole/notifiers/slack.rb
taperole-1.8.1 lib/taperole/notifiers/slack.rb
taperole-1.8.0 lib/taperole/notifiers/slack.rb
taperole-1.7.1 lib/taperole/notifiers/slack.rb
taperole-1.7.0 lib/taperole/notifiers/slack.rb