Skip to content

Instantly share code, notes, and snippets.

@shilov
Created December 27, 2013 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shilov/8140507 to your computer and use it in GitHub Desktop.
Save shilov/8140507 to your computer and use it in GitHub Desktop.
Honeybadger.io deploy task for Capistrano 3
namespace :deploy do
desc "Notifies Honeybadger locally using curl"
task :notify_honeybadger do
on roles(:app) do
require 'json'
require 'honeybadger'
begin
require './config/initializers/honeybadger'
rescue LoadError
error 'Honeybadger initializer not found'
else
honeybadger_api_key = Honeybadger.configuration.api_key
honeybadger_env = fetch(:rails_env, "production")
current_revision = fetch(:current_revision)
notify_command = "curl -sd 'deploy[repository]=#{repo_url}&deploy[revision]=#{current_revision}&deploy[local_username]=#{local_user}&deploy[environment]=#{honeybadger_env}&api_key=#{honeybadger_api_key}' https://api.honeybadger.io/v1/deploys"
info "Notifying Honeybadger of Deploy (`#{notify_command}`)"
result = JSON.parse `#{notify_command}` rescue nil
result ||= { 'error' => 'Invalid response' }
if result.include?('error')
error "Honeybadger Notification Failed: #{result['error']}"
else
info "Honeybadger Notification Complete."
end
end
end
end
after :finishing, :notify_honeybadger
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment