module AirbrakeTasks

def self.deploy(opts = {})

Options Hash: (**opts)
  • :local_username (String) -- Who is deploying
  • :scm_repository (String) -- Address of your repository to help with code lookups
  • :scm_revision (String) -- The given revision/sha that is being deployed
  • :rails_env (String) -- Environment of the deploy (production, staging)
  • :api_key (String) -- Api key of you Airbrake application

Parameters:
  • opts (Hash) -- Data about the deploy that is set to Airbrake
def self.deploy(opts = {})
  api_key = opts.delete(:api_key) || Airbrake.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 = Airbrake.configuration.host || 'api.airbrake.io'
  port = Airbrake.configuration.port
  proxy = Net::HTTP.Proxy(Airbrake.configuration.proxy_host,
                          Airbrake.configuration.proxy_port,
                          Airbrake.configuration.proxy_user,
                          Airbrake.configuration.proxy_pass)
  http = proxy.new(host, port)
  # Handle Security
  if Airbrake.configuration.secure?
    http.use_ssl      = true
    http.ca_file      = Airbrake.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