Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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