Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capistrano integration #27

Merged
merged 1 commit into from
Mar 8, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions lib/rollbar/capistrano.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'capistrano'

module Rollbar
module Capistrano
def self.load_into(configuration)
configuration.load do
after 'deploy', 'rollbar:deploy'
after 'deploy:migrations', 'rollbar:deploy'
after 'deploy:cold', 'rollbar:deploy'

namespace :rollbar do
desc 'Send the deployment notification to Rollbar.'
task :deploy, :except => { :no_release => true } do
require 'net/http'
require 'rubygems'
require 'json'

_cset(:rollbar_user) { ENV['USER'] || ENV['USERNAME'] }
_cset(:rollbar_env) { fetch(:rails_env, 'production') }
_cset(:rollbar_token) { abort("Please specify the Rollbar access token, set :rollbar_token, 'your token'") }

unless configuration.dry_run
uri = URI.parse('https://api.rollbar.com/api/1/deploy/')

params = {
:local_username => rollbar_user,
:access_token => rollbar_token,
:environment => rollbar_env,
:revision => current_revision
}

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

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

logger.info('Rollbar notification complete')
end
end
end
end
end
end

if Capistrano::Configuration.instance
Rollbar::Capistrano.load_into(Capistrano::Configuration.instance)
end