Sha256: db096029aaf98ec1688624d615b7eafd1d59ac252cdae6b816e7ace704c822a8

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 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)

        http = Net::HTTP.new(url.host, url.port)
        http.use_ssl = true
        resp = http.request(request)
        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

2 entries across 2 versions & 1 rubygems

Version Path
BibOpsworks-0.1.4 lib/bib/opsworks/qafoo.rb
BibOpsworks-0.1.3 lib/bib/opsworks/qafoo.rb