Class: Honeybadger::CLI::Heroku Private

Inherits:
Thor
  • Object
show all
Defined in:
lib/honeybadger/cli/heroku.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#install(api_key) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/honeybadger/cli/heroku.rb', line 33

def install(api_key)
  say("Installing Honeybadger #{VERSION} for Heroku")

  app = options[:app] || detect_heroku_app(false)
  say("Adding config HONEYBADGER_API_KEY=#{api_key} to Heroku.", :magenta)
  unless write_heroku_env({'HONEYBADGER_API_KEY' => api_key}, app)
    say('Unable to update heroku config. You may need to specify an app name with --app APP', :red)
    exit(1)
  end

  if env = heroku_var('RAILS_ENV', app, heroku_var('RACK_ENV', app))
    say('Installing deploy notification addon', :magenta)
    invoke :install_deploy_notification, [], { app: app, api_key: api_key, environment: env }
  else
    say('Skipping deploy notification installation: we were unable to determine the environment name from your Heroku app.', :yellow)
    say("To install manually, try `honeybadger heroku install_deploy_notification#{app ? " -a #{app}" : ""} -k #{api_key} --environment ENVIRONMENT`", :yellow)
  end

  say("Installation complete. Happy 'badgering!", :green)
end

#install_deploy_notificationObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/honeybadger/cli/heroku.rb', line 9

def install_deploy_notification
  app       = options.has_key?('app') ? options['app'] : detect_heroku_app(false)
  rails_env = options['environment'] || heroku_var('RAILS_ENV', app)
  api_key   = options['api_key'] || heroku_var('HONEYBADGER_API_KEY', app)

  unless api_key =~ /\S/
    say("Unable to detect your API key from Heroku.", :red)
    say('Have you configured multiple Heroku apps? Try using --app APP', :red) unless app
    exit(1)
  end

  unless rails_env =~ /\S/
    say("Unable to detect your environment from Heroku. Use --environment ENVIRONMENT.", :red)
    say('Have you configured multiple Heroku apps? Try using --app APP', :red) unless app
    exit(1)
  end

  cmd = %Q(heroku webhooks:add -i api:release -l notify -u "https://api.honeybadger.io/v1/deploys/heroku?environment=#{rails_env}&api_key=#{api_key}"#{app ? " --app #{app}" : ''})

  say("Running: `#{cmd}`")
  say(run(cmd))
end