Sha256: b38e1e2953a0b993edeedb34e474ca713f63f939f428ae74f7bfb86ee502bde2

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

require 'net/http'
require 'rubygems'
require 'json'

namespace :rollbar do

  desc 'Send the deployment notification to Rollbar.'
  task :deploy do
    on roles fetch(:rollbar_role) do
      warn("You need to upgrade capistrano to '>= 3.1' version in order to correctly report deploys to Rollbar. (On 3.0, the reported revision will be incorrect.)") if Capistrano::VERSION =~ /^3\.0/

      uri    = URI.parse 'https://api.rollbar.com/api/1/deploy/'
      params = {
        :local_username => fetch(:rollbar_user),
        :access_token   => fetch(:rollbar_token),
        :environment    => fetch(:rollbar_env),
        :revision       => fetch(:current_revision) }

      debug "Building Rollbar POST to #{uri} with #{params.inspect}"

      request      = Net::HTTP::Post.new(uri.request_uri)
      request.body = JSON.dump(params)

      Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
        http.request(request)
      end

      info 'Rollbar notification complete.'
    end
  end
end

namespace :deploy do
  after 'deploy:finished', 'rollbar:deploy'
end

namespace :load do
  task :defaults do
    set :rollbar_user,  Proc.new { ENV['USER'] || ENV['USERNAME'] }
    set :rollbar_env,   Proc.new { fetch :rails_env, 'production' }
    set :rollbar_token, Proc.new { abort "Please specify the Rollbar access token, set :rollbar_token, 'your token'" }
    set :rollbar_role,  Proc.new { :app }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rollbar-2.0.1 lib/rollbar/tasks/rollbar.cap
rollbar-2.0.0 lib/rollbar/tasks/rollbar.cap