Sha256: 7c8ce047bbcd75d8309d99517d67b126bcb876a701ccf0293d45918abb507504

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

require 'net/http'

module Bib
  module Opsworks
    class Qafoo
      include Logging

      def publish_deployment(app_name, deploy_data, qafoo_api_key)
        qafoo_params = prepare_publishing_data(app_name, deploy_data)
        qafoo_params['apiKey'] = qafoo_api_key

        qafoo_url = 'https://app.tideways.io/api/events'
        url = URI.parse(qafoo_url)
        request = Net::HTTP::Post.new(url.request_uri)
        request.body = qafoo_params.to_json

        log.debug('qafoo sending data: ' + qafoo_params.to_json)
        begin
          http = Net::HTTP.new(url.host, url.port)
          http.use_ssl = true
          resp = http.request(request)
        rescue SocketError => se
          log.info('Unable to publish deployment with tideways: ' + se)
        end
        log.debug('qafoo Response: ' + resp.code + ' ' + resp.message)
        resp.is_a? Net::HTTPSuccess
      end

      def prepare_publishing_data(app_name, deploy_data)
        scm_revision = deploy_data['scm']['revision']

        if deploy_data['deploying_user'].nil? || deploy_data['deploying_user'].empty?
          deployment_user = 'opsworks'
        else
          deployment_user = deploy_data['deploying_user'].split('/')[1]
        end

        name_text = "#{scm_revision} by #{deployment_user}"

        qafoo_params = {}
        qafoo_params['name'] = name_text
        qafoo_params['environment'] = app_name
        qafoo_params['type'] = 'release'
        qafoo_params
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
BibOpsworks-0.1.5 lib/bib/opsworks/qafoo.rb