Sha256: d9413089221baf24e1b489787db9946ff27f4836fe3f091f732aa071a7b6cd62

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

require 'simple_deploy/notifier/campfire'
require 'simple_deploy/notifier/slack'

module SimpleDeploy
  class Notifier
    def initialize(args)
      @config = SimpleDeploy.config
      @stack_name = args[:stack_name]
      @environment = args[:environment]
      @notifications = @config.notifications || {}
    end

    def send_deployment_start_message
      message = "Deployment to #{@stack_name} in #{@config.region} started."
      send message
    end

    def send_deployment_complete_message
      message = "Deployment to #{@stack_name} in #{@config.region} complete."
      attributes = stack.attributes

      if attributes['app_github_url']
        message += " App: #{attributes['app_github_url']}/commit/#{attributes['app']}"
      end

      if attributes['chef_repo_github_url']
        message += " Chef: #{attributes['chef_repo_github_url']}/commit/#{attributes['chef_repo']}"
      end

      send message
    end

    def send(message)
      @notifications.keys.each do |notification|
        case notification
        when 'campfire'
          campfire = Notifier::Campfire.new :stack_name  => @stack_name,
                                            :environment => @environment
          campfire.send message
        when 'slack'
          slack = Notifier::Slack.new
          slack.send message
        end
      end
    end

    private

    def stack
      @stack ||= Stack.new :name        => @stack_name,
                           :environment => @environment
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_deploy-0.10.2 lib/simple_deploy/notifier.rb