class Honeybadger::CLI::Heroku
def detect_heroku_app(prompt_on_default = true)
-
prompt_on_default(Boolean) -- If a single remote is discoverd,
def detect_heroku_app(prompt_on_default = true) apps, git_config = {}, File.join(Dir.pwd, '.git', 'config') if File.exist?(git_config) require 'inifile' ini = IniFile.load(git_config) ini.each_section do |section| if match = section.match(/remote \"(?<remote>.+)\"/) url = ini[section]['url'] if url_match = url.match(/heroku\.com:(?<app>.+)\.git$/) apps[match[:remote]] = url_match[:app] end end end if apps.size == 1 if !prompt_on_default apps.values.first else say "We detected a Heroku app named #{apps.values.first}. Do you want to load the config? (y/yes or n/no)" if STDIN.gets.chomp =~ /(y|yes)/i apps.values.first end end elsif apps.size > 1 say "We detected the following Heroku apps:" apps.each_with_index {|a,i| say "\s\s#{i+1}. #{a[1]}" } say "\s\s#{apps.size+1}. Use default" say "Please select an option (1-#{apps.size+1}):" apps.values[STDIN.gets.chomp.to_i-1] end end end