Sha256: 3ffb5267acac1c8d539645fdad09733be7bb3efe7596d07ce1983371735fe70f

Contents?: true

Size: 1.75 KB

Versions: 35

Compression:

Stored size: 1.75 KB

Contents

require "bugsnag"
require "httparty"
require "multi_json"

namespace :bugsnag do
  desc "Notify Bugsnag of a new deploy."
  task :deploy => :load do
    # Fetch and check the api key
    api_key = ENV["BUGSNAG_API_KEY"] || Bugsnag.configuration.api_key
    raise RuntimeError.new("No API key found when notifying deploy") if !api_key || api_key.empty?

    # Build the deploy payload
    payload = {
      :apiKey => api_key,
      :releaseStage => ENV["BUGSNAG_RELEASE_STAGE"] || Bugsnag.configuration.release_stage
    }
    payload[:appVersion] = ENV["BUGSNAG_APP_VERSION"] if ENV["BUGSNAG_APP_VERSION"]
    payload[:revision] = ENV["BUGSNAG_REVISION"] if ENV["BUGSNAG_REVISION"]
    payload[:repository] = ENV["BUGSNAG_REPOSITORY"] if ENV["BUGSNAG_REPOSITORY"]
    payload[:branch] = ENV["BUGSNAG_BRANCH"] if ENV["BUGSNAG_BRANCH"]

    # Post the deploy notification
    begin
      endpoint = (Bugsnag.configuration.use_ssl ? "https://" : "http://") \
               + (Bugsnag.configuration.endpoint || Bugsnag::Notification::DEFAULT_ENDPOINT) \
               + "/deploy"

      HTTParty.post(endpoint, {
        :body => Bugsnag::Helpers.dump_json(payload),
        :headers => {"Content-Type" => "application/json"}
      })
    rescue Exception => e
      Bugsnag.log("Deploy notification failed, #{e.inspect}")
    end
  end

  desc "Send a test exception to Bugsnag."
  task :test_exception => :load do 
    begin
      raise RuntimeError.new("Bugsnag test exception")
    rescue => e
      Bugsnag.notify(e, {:context => "rake#test_exception"})
    end
  end

  desc "Show the bugsnag middleware stack"
  task :middleware => :load do
    Bugsnag.configuration.middleware.each {|m| puts m.to_s}
  end
end

task :load do
  begin 
    Rake::Task["environment"].invoke
  rescue
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
bugsnag-1.5.2 lib/bugsnag/tasks/bugsnag.rake
bugsnag-1.5.1 lib/bugsnag/tasks/bugsnag.rake
bugsnag-1.5.0 lib/bugsnag/tasks/bugsnag.rake
bugsnag-1.4.2 lib/bugsnag/tasks/bugsnag.rake
bugsnag-1.4.1 lib/bugsnag/tasks/bugsnag.rake
bugsnag-1.4.0 lib/bugsnag/tasks/bugsnag.rake
bugsnag-1.3.8 lib/bugsnag/tasks/bugsnag.rake
bugsnag-1.3.7 lib/bugsnag/tasks/bugsnag.rake
bugsnag-1.3.6 lib/bugsnag/tasks/bugsnag.rake
bugsnag-1.3.5 lib/bugsnag/tasks/bugsnag.rake
bugsnag-1.3.4 lib/bugsnag/tasks/bugsnag.rake
bugsnag-1.3.3 lib/bugsnag/tasks/bugsnag.rake
bugsnag-1.3.2 lib/bugsnag/tasks/bugsnag.rake
bugsnag-1.3.1 lib/bugsnag/tasks/bugsnag.rake
bugsnag-1.3.0 lib/bugsnag/tasks/bugsnag.rake
bugsnag-1.2.18 lib/bugsnag/tasks/bugsnag.rake
bugsnag-1.2.17 lib/bugsnag/tasks/bugsnag.rake
bugsnag-1.2.16 lib/bugsnag/tasks/bugsnag.rake
bugsnag-1.2.15 lib/bugsnag/tasks/bugsnag.rake
bugsnag-1.2.14 lib/bugsnag/tasks/bugsnag.rake