Sha256: a1757ec53d1a3831ed46d62b28bc66dbe5f3fd07e0693264c9938ba864ada97e

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 KB

Contents

require 'net/http'
require 'uri'

# Capistrano tasks for notifying Pulse of deploys
module PulseTasks

  # Alerts Pulse of a deploy.
  #
  # @param [Hash] opts Data about the deploy that is set to Pulse
  #
  # @option opts [String] :api_key Api key of you Pulse application
  # @option opts [String] :rails_env Environment of the deploy (production, staging)
  # @option opts [String] :scm_revision The given revision/sha that is being deployed
  # @option opts [String] :scm_repository Address of your repository to help with code lookups
  # @option opts [String] :local_username Who is deploying
  def self.deploy(opts = {})
    api_key = opts.delete(:api_key) || Pulse.configuration.api_key
    if api_key.blank?
      puts "I don't seem to be configured with an API key.  Please check your configuration."
      return false
    end

    if opts[:rails_env].blank?
      puts "I don't know to which Rails environment you are deploying (use the TO=production option)."
      return false
    end

    dry_run = opts.delete(:dry_run)
    params = {'api_key' => api_key}
    opts.each {|k,v| params["deploy[#{k}]"] = v }

    host = Pulse.configuration.host || 'errors.projectlocker.com'
    port = Pulse.configuration.port

    proxy = Net::HTTP.Proxy(Pulse.configuration.proxy_host,
                            Pulse.configuration.proxy_port,
                            Pulse.configuration.proxy_user,
                            Pulse.configuration.proxy_pass)
    http = proxy.new(host, port)



    # Handle Security
    if Pulse.configuration.secure?
      http.use_ssl      = true
      http.ca_file      = Pulse.configuration.ca_bundle_path
      http.verify_mode  = OpenSSL::SSL::VERIFY_PEER
    end

    post = Net::HTTP::Post.new("/deploys.txt")
    post.set_form_data(params)

    if dry_run
      puts http.inspect, params.inspect
      return true
    else
      response = http.request(post)

      puts response.body
      return Net::HTTPSuccess === response
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
projectlocker_pulse-1.0.0 lib/pulse_tasks.rb
projectlocker_pulse-0.2.1 lib/pulse_tasks.rb