Sha256: cad2ea1b003ee97e81192bb265854f0d889fb4d0a2dbd0148a24e9d4b1f9ed31

Contents?: true

Size: 1018 Bytes

Versions: 3

Compression:

Stored size: 1018 Bytes

Contents

require 'papa/command/base'
require 'papa/helper/config'
require 'json'

module Papa
  module Command
    module Slack
      class SendMessage < Command::Base
        def initialize(build_type, hostname, action)
          @build_type = build_type
          @hostname = hostname
          @action = action

          @user_whoami = `whoami`.chomp
          @user_hostname = `hostname`.chomp

          command = "curl -X POST --data-urlencode 'payload=#{payload.to_json}' #{webhook_url}"
          super(command)
        end

        private

        def payload
          { 'text' => message }
        end

        def webhook_url
          Helper::Config.read["slack_webhook"]
        end

        def message
          url = "https://#{@hostname}.indinerocorp.com"
          message = "<!channel> Deployment to <#{url}|#{@hostname}> #{@action}"
          message << " by #{@user_whoami} at #{@user_hostname}" if @action == 'started'
          message << '.'
          message
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
papa-1.2.0 lib/papa/command/slack/send_message.rb
papa-1.1.0 lib/papa/command/slack/send_message.rb
papa-1.0.0 lib/papa/command/slack/send_message.rb