1
0
mirror of https://github.com/meineerde/redmine.git synced 2025-12-19 15:01:14 +00:00

code cleanup: rubocop: fix Lint/IneffectiveAccessModifier in lib/redmine/scm/adapters/abstract_adapter.rb

git-svn-id: http://svn.redmine.org/redmine/trunk@18777 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2019-10-19 13:33:10 +00:00
parent cb2d4068e8
commit 7738078717
2 changed files with 31 additions and 29 deletions

View File

@ -395,7 +395,6 @@ Lint/IneffectiveAccessModifier:
- 'app/models/mail_handler.rb' - 'app/models/mail_handler.rb'
- 'app/models/mailer.rb' - 'app/models/mailer.rb'
- 'app/models/user.rb' - 'app/models/user.rb'
- 'lib/redmine/scm/adapters/abstract_adapter.rb'
Lint/InterpolationCheck: Lint/InterpolationCheck:
Exclude: Exclude:

View File

@ -203,10 +203,6 @@ module Redmine
self.class.shellout(cmd, options, &block) self.class.shellout(cmd, options, &block)
end end
def self.logger
Rails.logger
end
# Path to the file where scm stderr output is logged # Path to the file where scm stderr output is logged
# Returns nil if the log file is not writable # Returns nil if the log file is not writable
def self.stderr_log_file def self.stderr_log_file
@ -234,32 +230,39 @@ module Redmine
end end
private_class_method :stderr_log_file private_class_method :stderr_log_file
def self.shellout(cmd, options = {}, &block) # Singleton class method is public
if logger && logger.debug? class << self
logger.debug "Shelling out: #{strip_credential(cmd)}" def logger
# Capture stderr in a log file Rails.logger
if stderr_log_file
cmd = "#{cmd} 2>>#{shell_quote(stderr_log_file)}"
end
end end
begin
mode = "r+" def shellout(cmd, options = {}, &block)
IO.popen(cmd, mode) do |io| if logger && logger.debug?
io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding) logger.debug "Shelling out: #{strip_credential(cmd)}"
io.close_write unless options[:write_stdin] # Capture stderr in a log file
block.call(io) if block_given? if stderr_log_file
cmd = "#{cmd} 2>>#{shell_quote(stderr_log_file)}"
end
end
begin
mode = "r+"
IO.popen(cmd, mode) do |io|
io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding)
io.close_write unless options[:write_stdin]
block.call(io) if block_given?
end
rescue => e
msg = strip_credential(e.message)
# The command failed, log it and re-raise
logmsg = "SCM command failed, "
logmsg += "make sure that your SCM command (e.g. svn) is "
logmsg += "in PATH (#{ENV['PATH']})\n"
logmsg += "You can configure your scm commands in config/configuration.yml.\n"
logmsg += "#{strip_credential(cmd)}\n"
logmsg += "with: #{msg}"
logger.error(logmsg)
raise CommandFailed.new(msg)
end end
rescue => e
msg = strip_credential(e.message)
# The command failed, log it and re-raise
logmsg = "SCM command failed, "
logmsg += "make sure that your SCM command (e.g. svn) is "
logmsg += "in PATH (#{ENV['PATH']})\n"
logmsg += "You can configure your scm commands in config/configuration.yml.\n"
logmsg += "#{strip_credential(cmd)}\n"
logmsg += "with: #{msg}"
logger.error(logmsg)
raise CommandFailed.new(msg)
end end
end end