Skip to content

Commit

Permalink
fix conflicts in airbrake.cap
Browse files Browse the repository at this point in the history
  • Loading branch information
shifi committed Aug 8, 2014
2 parents 01a48b2 + 6b82e43 commit 700d761
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 79 deletions.
65 changes: 2 additions & 63 deletions lib/airbrake/capistrano3.rb
Original file line number Diff line number Diff line change
@@ -1,64 +1,3 @@
# Defines deploy:notify_airbrake which will send information about the deploy to Airbrake.
require 'capistrano'
# Defines airbrake:deploy which will send information about the deploy to Airbrake.

module Airbrake
module Capistrano
# What follows is a copy-paste backport of the shellescape method
# included in Ruby 1.9 and greater. The FSF's guidance on a snippet
# of this size indicates that such a small function is not subject
# to copyright and as such there is no risk of a license conflict:
# See www.gnu.org/prep/maintain/maintain.html#Legally-Significant
#
# Escapes a string so that it can be safely used in a Bourne shell
# command line. +str+ can be a non-string object that responds to
# +to_s+.
#
# Note that a resulted string should be used unquoted and is not
# intended for use in double quotes nor in single quotes.
#
# argv = Shellwords.escape("It's better to give than to receive")
# argv #=> "It\\'s\\ better\\ to\\ give\\ than\\ to\\ receive"
#
# String#shellescape is a shorthand for this function.
#
# argv = "It's better to give than to receive".shellescape
# argv #=> "It\\'s\\ better\\ to\\ give\\ than\\ to\\ receive"
#
# # Search files in lib for method definitions
# pattern = "^[ \t]*def "
# open("| grep -Ern #{pattern.shellescape} lib") { |grep|
# grep.each_line { |line|
# file, lineno, matched_line = line.split(':', 3)
# # ...
# }
# }
#
# It is the caller's responsibility to encode the string in the right
# encoding for the shell environment where this string is used.
#
# Multibyte characters are treated as multibyte characters, not bytes.
#
# Returns an empty quoted String if +str+ has a length of zero.
def self.shellescape(str)
str = str.to_s

# An empty argument will be skipped, so return empty quotes.
return "''" if str.empty?

str = str.dup

# Treat multibyte characters as is. It is caller's responsibility
# to encode the string in the right encoding for the shell
# environment.
str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/, "\\\\\\1")

# A LF cannot be escaped with a backslash because a backslash + LF
# combo is regarded as line continuation and simply ignored.
str.gsub!(/\n/, "'\n'")

return str
end
end
end

load File.expand_path('../tasks/airbrake.cap', __FILE__)
load File.expand_path("../tasks/airbrake.cap", __FILE__)
33 changes: 17 additions & 16 deletions lib/airbrake/tasks/airbrake.cap
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@ namespace :airbrake do
- Run remotely so we use remote API keys, environment, etc.
DESC
task :deploy do
on roles(:all) do |host|
rails_env = fetch(:rails_env, "production")
airbrake_env = fetch(:airbrake_env, fetch(:rails_env, "production"))
local_user = ENV['USER'] || ENV['USERNAME']
executable = RUBY_PLATFORM.downcase.include?('mswin') ? fetch(:rake, 'rake.bat') : fetch(:rake, 'bundle exec rake ')
current_revision = capture("cd #{repo_path} && git rev-parse HEAD")
repository = ENV['REPO'] || ENV['REPONAME']

notify_command = "RAILS_ENV=#{rails_env} airbrake:deploy TO=#{airbrake_env} REVISION=#{current_revision} REPO=#{repo_url} USER=#{Airbrake::Capistrano::shellescape(local_user)}"
notify_command << " API_KEY=#{ENV['API_KEY']}" if ENV['API_KEY']
info "Notifying Airbrake of Deploy (#{notify_command})"
result = ""
# update scm state to get the repository information
invoke "#{scm}:update"
on roles(:app) do
within release_path do
execute :rake, notify_command, :once => true do |ch, stream, data|
result << data
# XXX: Invoking deploy:set_rails_env would set :rails_env to proper
# value, but that would make us depend on capistrano-rails
with rails_env: fetch(:rails_env, fetch(:stage)) do
# Compose the command notify_command
airbrake_env = fetch(:airbrake_env, fetch(:rails_env, fetch(:stage)))
notify_command = "airbrake:deploy"
notify_command << " TO=#{airbrake_env}"
notify_command << " REVISION=#{fetch(:current_revision)} REPO=#{fetch(:repo_url)}"
notify_command << " USER=#{local_user.strip.shellescape}"
notify_command << " API_KEY=#{ENV['API_KEY']}" if ENV['API_KEY']

info "Notifying Airbrake of Deploy (#{notify_command})"
execute :rake, notify_command
info "Airbrake Notification Complete."
end
end
# TODO: Check if SSL is active on account via result content.
info "Airbrake Notification Complete."
end
end
end

0 comments on commit 700d761

Please sign in to comment.