Created
October 7, 2012 01:19
-
-
Save joshuap/3846751 to your computer and use it in GitHub Desktop.
Honeybadger deployment notification capistrano task using local machine and curl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :deploy do | |
desc "Notifies Honeybadger locally using curl" | |
task :notify_honeybadger do | |
require 'json' | |
require 'honeybadger' | |
begin | |
require './config/initializers/honeybadger' | |
rescue LoadError | |
logger.info 'Honeybadger initializer not found' | |
else | |
honeybadger_api_key = Honeybadger.configuration.api_key | |
local_user = ENV['USER'] || ENV['USERNAME'] | |
honeybadger_env = fetch(:rails_env, "production") | |
notify_command = "curl -sd 'deploy[repository]=#{repository}&deploy[revision]=#{current_revision}&deploy[local_username]=#{local_user}&deploy[environment]=#{honeybadger_env}&api_key=#{honeybadger_api_key}' https://api.honeybadger.io/v1/deploys" | |
logger.info "Notifying Honeybadger of Deploy (`#{notify_command}`)" | |
result = JSON.parse `#{notify_command}` rescue nil | |
result ||= { 'error' => 'Invalid response' } | |
if result.include?('error') | |
logger.info "Honeybadger Notification Failed: #{result['error']}" | |
else | |
logger.info "Honeybadger Notification Complete." | |
end | |
end | |
end | |
end | |
after 'deploy', 'deploy:notify_honeybadger' | |
after 'deploy:migrations', 'deploy:notify_honeybadger' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment