Module: HydraulicBrake::Hook

Defined in:
lib/hydraulic_brake/hook.rb

Class Method Summary collapse

Class Method Details

.deploy(opts = {}) ⇒ Object

Alerts Airbrake of a deploy.

Parameters:

  • opts (Hash) (defaults to: {})

    Data about the deploy that is set to Airbrake

Options Hash (opts):

  • :api_key (String)

    Api key of you Airbrake application

  • :scm_revision (String)

    The given revision/sha that is being deployed

  • :scm_repository (String)

    Address of your repository to help with code lookups

  • :local_username (String)

    Who is deploying



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/hydraulic_brake/hook.rb', line 15

def self.deploy(opts = {})
  api_key = opts.delete(:api_key) || HydraulicBrake.configuration.api_key
  if api_key.empty?
    puts "I don't seem to be configured with an API key.  Please check your configuration."
    return false
  end

  params = {'api_key' => api_key}
  opts.each {|k,v| params["deploy[#{k}]"] = v }

  host = HydraulicBrake.configuration.host
  port = HydraulicBrake.configuration.port

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

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

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

  response = http.request(post)

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