Commit bcc59f6a authored by Robert Speicher's avatar Robert Speicher

Merge branch 'dz-update-deps' into 'master'

Update rubocop

See merge request gitlab-org/gitlab-shell!190
parents ec2806f1 fe4b0d63
This diff is collapsed.
source "http://rubygems.org" source "http://rubygems.org"
group :development, :test do group :development, :test do
gem 'simplecov', require: false
gem 'rspec', '~> 2.14.0'
gem 'webmock'
gem 'guard' gem 'guard'
gem 'guard-rspec' gem 'guard-rspec'
gem 'rspec', '~> 2.14.0'
gem 'rubocop', '0.49.1', require: false
gem 'simplecov', require: false
gem 'vcr' gem 'vcr'
gem 'rubocop', '0.28.0', require: false gem 'webmock'
end end
...@@ -2,11 +2,9 @@ GEM ...@@ -2,11 +2,9 @@ GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
addressable (2.3.2) addressable (2.3.2)
ast (2.0.0) ast (2.4.0)
astrolabe (1.3.0)
parser (>= 2.2.0.pre.3, < 3.0)
coderay (1.0.8) coderay (1.0.8)
crack (0.3.1) crack (0.3.2)
diff-lcs (1.2.5) diff-lcs (1.2.5)
docile (1.1.5) docile (1.1.5)
guard (1.5.4) guard (1.5.4)
...@@ -21,14 +19,17 @@ GEM ...@@ -21,14 +19,17 @@ GEM
lumberjack (1.0.2) lumberjack (1.0.2)
method_source (0.8.1) method_source (0.8.1)
multi_json (1.10.1) multi_json (1.10.1)
parser (2.2.0.2) parallel (1.12.1)
ast (>= 1.1, < 3.0) parser (2.5.0.2)
powerpack (0.0.9) ast (~> 2.4.0)
powerpack (0.1.1)
pry (0.9.10) pry (0.9.10)
coderay (~> 1.0.5) coderay (~> 1.0.5)
method_source (~> 0.8) method_source (~> 0.8)
slop (~> 3.3.1) slop (~> 3.3.1)
rainbow (2.0.0) rainbow (2.2.2)
rake
rake (12.3.0)
rspec (2.14.1) rspec (2.14.1)
rspec-core (~> 2.14.0) rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0) rspec-expectations (~> 2.14.0)
...@@ -37,13 +38,14 @@ GEM ...@@ -37,13 +38,14 @@ GEM
rspec-expectations (2.14.5) rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0) diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6) rspec-mocks (2.14.6)
rubocop (0.28.0) rubocop (0.49.1)
astrolabe (~> 1.3) parallel (~> 1.10)
parser (>= 2.2.0.pre.7, < 3.0) parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.0.6) powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0) rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.4) ruby-progressbar (~> 1.7)
ruby-progressbar (1.7.1) unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
simplecov (0.9.1) simplecov (0.9.1)
docile (~> 1.1.0) docile (~> 1.1.0)
multi_json (~> 1.0) multi_json (~> 1.0)
...@@ -51,6 +53,7 @@ GEM ...@@ -51,6 +53,7 @@ GEM
simplecov-html (0.8.0) simplecov-html (0.8.0)
slop (3.3.3) slop (3.3.3)
thor (0.19.1) thor (0.19.1)
unicode-display_width (1.3.0)
vcr (2.4.0) vcr (2.4.0)
webmock (1.9.0) webmock (1.9.0)
addressable (>= 2.2.7) addressable (>= 2.2.7)
...@@ -63,7 +66,7 @@ DEPENDENCIES ...@@ -63,7 +66,7 @@ DEPENDENCIES
guard guard
guard-rspec guard-rspec
rspec (~> 2.14.0) rspec (~> 2.14.0)
rubocop (= 0.28.0) rubocop (= 0.49.1)
simplecov simplecov
vcr vcr
webmock webmock
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# will be processed properly. # will be processed properly.
refs = $stdin.read refs = $stdin.read
key_id = ENV.delete('GL_ID') key_id = ENV.delete('GL_ID')
gl_repository = ENV.delete('GL_REPOSITORY') gl_repository = ENV.delete('GL_REPOSITORY')
repo_path = Dir.pwd repo_path = Dir.pwd
......
...@@ -14,12 +14,12 @@ class GitAccessStatus ...@@ -14,12 +14,12 @@ class GitAccessStatus
def self.create_from_json(json) def self.create_from_json(json)
values = JSON.parse(json) values = JSON.parse(json)
self.new(values["status"], new(values["status"],
values["message"], values["message"],
gl_repository: values["gl_repository"], gl_repository: values["gl_repository"],
gl_username: values["gl_username"], gl_username: values["gl_username"],
repository_path: values["repository_path"], repository_path: values["repository_path"],
gitaly: values["gitaly"]) gitaly: values["gitaly"])
end end
def allowed? def allowed?
......
...@@ -47,7 +47,7 @@ class GitlabCustomHook ...@@ -47,7 +47,7 @@ class GitlabCustomHook
# Submit changes to the hook via its stdin. # Submit changes to the hook via its stdin.
begin begin
IO.copy_stream(StringIO.new(changes), stdin_writer) IO.copy_stream(StringIO.new(changes), stdin_writer)
rescue Errno::EPIPE rescue Errno::EPIPE # rubocop:disable Lint/HandleExceptions
# It is not an error if the hook does not consume all of its input. # It is not an error if the hook does not consume all of its input.
end end
......
...@@ -4,19 +4,26 @@ require_relative 'gitlab_config' ...@@ -4,19 +4,26 @@ require_relative 'gitlab_config'
require_relative 'gitlab_logger' require_relative 'gitlab_logger'
require_relative 'gitlab_metrics' require_relative 'gitlab_metrics'
class GitlabKeys class GitlabKeys # rubocop:disable Metrics/ClassLength
class KeyError < StandardError ; end class KeyError < StandardError; end
attr_accessor :auth_file, :key attr_accessor :auth_file, :key
def self.command(key_id) def self.command(key_id)
raise KeyError.new("Invalid key_id: #{key_id.inspect}") unless /\A[a-z0-9-]+\z/ =~ key_id unless /\A[a-z0-9-]+\z/ =~ key_id
raise KeyError, "Invalid key_id: #{key_id.inspect}"
end
"#{ROOT_PATH}/bin/gitlab-shell #{key_id}" "#{ROOT_PATH}/bin/gitlab-shell #{key_id}"
end end
def self.key_line(key_id, public_key) def self.key_line(key_id, public_key)
public_key.chomp! public_key.chomp!
raise KeyError.new("Invalid public_key: #{public_key.inspect}") if public_key.include?("\n")
if public_key.include?("\n")
raise KeyError, "Invalid public_key: #{public_key.inspect}"
end
"command=\"#{command(key_id)}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty #{public_key}" "command=\"#{command(key_id)}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty #{public_key}"
end end
...@@ -31,19 +38,19 @@ class GitlabKeys ...@@ -31,19 +38,19 @@ class GitlabKeys
def exec def exec
GitlabMetrics.measure("command-#{@command}") do GitlabMetrics.measure("command-#{@command}") do
case @command case @command
when 'add-key'; when 'add-key'
add_key add_key
when 'batch-add-keys'; when 'batch-add-keys'
batch_add_keys batch_add_keys
when 'rm-key'; when 'rm-key'
rm_key rm_key
when 'list-keys'; when 'list-keys'
list_keys list_keys
when 'list-key-ids'; when 'list-key-ids'
list_key_ids list_key_ids
when 'clear'; when 'clear'
clear clear
when 'check-permissions'; when 'check-permissions'
check_permissions check_permissions
else else
$logger.warn "Attempt to execute invalid gitlab-keys command #{@command.inspect}." $logger.warn "Attempt to execute invalid gitlab-keys command #{@command.inspect}."
...@@ -111,7 +118,7 @@ class GitlabKeys ...@@ -111,7 +118,7 @@ class GitlabKeys
lock do lock do
$logger.info "Removing key #{@key_id}" $logger.info "Removing key #{@key_id}"
open_auth_file('r+') do |f| open_auth_file('r+') do |f|
while line = f.gets do while line = f.gets # rubocop:disable Style/AssignmentInCondition
next unless line.start_with?("command=\"#{self.class.command(@key_id)}\"") next unless line.start_with?("command=\"#{self.class.command(@key_id)}\"")
f.seek(-line.length, IO::SEEK_CUR) f.seek(-line.length, IO::SEEK_CUR)
# Overwrite the line with #'s. Because the 'line' variable contains # Overwrite the line with #'s. Because the 'line' variable contains
...@@ -145,7 +152,7 @@ class GitlabKeys ...@@ -145,7 +152,7 @@ class GitlabKeys
File.open(lock_file, "w+") do |f| File.open(lock_file, "w+") do |f|
begin begin
f.flock File::LOCK_EX f.flock File::LOCK_EX
Timeout::timeout(timeout) { yield } Timeout.timeout(timeout) { yield }
ensure ensure
f.flock File::LOCK_UN f.flock File::LOCK_UN
end end
...@@ -157,8 +164,8 @@ class GitlabKeys ...@@ -157,8 +164,8 @@ class GitlabKeys
end end
def open_auth_file(mode) def open_auth_file(mode)
open(auth_file, mode, 0600) do |file| open(auth_file, mode, 0o600) do |file|
file.chmod(0600) file.chmod(0o600)
yield file yield file
end end
end end
......
...@@ -11,12 +11,10 @@ class GitlabLfsAuthentication ...@@ -11,12 +11,10 @@ class GitlabLfsAuthentication
end end
def self.build_from_json(json) def self.build_from_json(json)
begin values = JSON.parse(json)
values = JSON.parse(json) new(values['username'], values['lfs_token'], values['repository_http_path'])
self.new(values['username'], values['lfs_token'], values['repository_http_path']) rescue
rescue nil
nil
end
end end
def authentication_payload def authentication_payload
......
...@@ -2,7 +2,7 @@ require 'logger' ...@@ -2,7 +2,7 @@ require 'logger'
require_relative 'gitlab_config' require_relative 'gitlab_config'
def convert_log_level log_level def convert_log_level(log_level)
Logger.const_get(log_level.upcase) Logger.const_get(log_level.upcase)
rescue NameError rescue NameError
$stderr.puts "WARNING: Unrecognized log level #{log_level.inspect}." $stderr.puts "WARNING: Unrecognized log level #{log_level.inspect}."
......
...@@ -8,7 +8,7 @@ require_relative 'gitlab_access' ...@@ -8,7 +8,7 @@ require_relative 'gitlab_access'
require_relative 'gitlab_lfs_authentication' require_relative 'gitlab_lfs_authentication'
require_relative 'httpunix' require_relative 'httpunix'
class GitlabNet class GitlabNet # rubocop:disable Metrics/ClassLength
class ApiUnreachableError < StandardError; end class ApiUnreachableError < StandardError; end
class NotFound < StandardError; end class NotFound < StandardError; end
...@@ -16,7 +16,7 @@ class GitlabNet ...@@ -16,7 +16,7 @@ class GitlabNet
READ_TIMEOUT = 300 READ_TIMEOUT = 300
def check_access(cmd, gl_repository, repo, actor, changes, protocol, env: {}) def check_access(cmd, gl_repository, repo, actor, changes, protocol, env: {})
changes = changes.join("\n") unless changes.kind_of?(String) changes = changes.join("\n") unless changes.is_a?(String)
params = { params = {
action: cmd, action: cmd,
...@@ -28,9 +28,9 @@ class GitlabNet ...@@ -28,9 +28,9 @@ class GitlabNet
} }
if actor =~ /\Akey\-\d+\Z/ if actor =~ /\Akey\-\d+\Z/
params.merge!(key_id: actor.gsub("key-", "")) params[:key_id] = actor.gsub("key-", "")
elsif actor =~ /\Auser\-\d+\Z/ elsif actor =~ /\Auser\-\d+\Z/
params.merge!(user_id: actor.gsub("user-", "")) params[:user_id] = actor.gsub("user-", "")
end end
url = "#{host}/allowed" url = "#{host}/allowed"
...@@ -73,7 +73,7 @@ class GitlabNet ...@@ -73,7 +73,7 @@ class GitlabNet
end end
def merge_request_urls(gl_repository, repo_path, changes) def merge_request_urls(gl_repository, repo_path, changes)
changes = changes.join("\n") unless changes.kind_of?(String) changes = changes.join("\n") unless changes.is_a?(String)
changes = changes.encode('UTF-8', 'ASCII', invalid: :replace, replace: '') changes = changes.encode('UTF-8', 'ASCII', invalid: :replace, replace: '')
url = "#{host}/merge_request_urls?project=#{URI.escape(repo_path)}&changes=#{URI.escape(changes)}" url = "#{host}/merge_request_urls?project=#{URI.escape(repo_path)}&changes=#{URI.escape(changes)}"
url += "&gl_repository=#{URI.escape(gl_repository)}" if gl_repository url += "&gl_repository=#{URI.escape(gl_repository)}" if gl_repository
...@@ -141,7 +141,7 @@ class GitlabNet ...@@ -141,7 +141,7 @@ class GitlabNet
protected protected
def sanitize_path(repo) def sanitize_path(repo)
repo.gsub("'", "") repo.delete("'")
end end
def config def config
...@@ -152,12 +152,12 @@ class GitlabNet ...@@ -152,12 +152,12 @@ class GitlabNet
"#{config.gitlab_url}/api/v4/internal" "#{config.gitlab_url}/api/v4/internal"
end end
def http_client_for(uri, options={}) def http_client_for(uri, options = {})
if uri.is_a?(URI::HTTPUNIX) http = if uri.is_a?(URI::HTTPUNIX)
http = Net::HTTPUNIX.new(uri.hostname) Net::HTTPUNIX.new(uri.hostname)
else else
http = Net::HTTP.new(uri.host, uri.port) Net::HTTP.new(uri.host, uri.port)
end end
http.read_timeout = options[:read_timeout] || read_timeout http.read_timeout = options[:read_timeout] || read_timeout
...@@ -189,7 +189,7 @@ class GitlabNet ...@@ -189,7 +189,7 @@ class GitlabNet
request request
end end
def request(method, url, params = {}, options={}) def request(method, url, params = {}, options = {})
$logger.debug "Performing #{method.to_s.upcase} #{url}" $logger.debug "Performing #{method.to_s.upcase} #{url}"
uri = URI.parse(url) uri = URI.parse(url)
...@@ -205,7 +205,7 @@ class GitlabNet ...@@ -205,7 +205,7 @@ class GitlabNet
raise ApiUnreachableError raise ApiUnreachableError
ensure ensure
$logger.info do $logger.info do
sprintf('%s %s %0.5f', method.to_s.upcase, url, Time.new - start_time) sprintf('%s %s %0.5f', method.to_s.upcase, url, Time.new - start_time) # rubocop:disable Style/FormatString
end end
end end
...@@ -218,7 +218,7 @@ class GitlabNet ...@@ -218,7 +218,7 @@ class GitlabNet
response response
end end
def get(url, options={}) def get(url, options = {})
request(:get, url, {}, options) request(:get, url, {}, options)
end end
...@@ -231,13 +231,11 @@ class GitlabNet ...@@ -231,13 +231,11 @@ class GitlabNet
store = OpenSSL::X509::Store.new store = OpenSSL::X509::Store.new
store.set_default_paths store.set_default_paths
if ca_file = config.http_settings['ca_file'] ca_file = config.http_settings['ca_file']
store.add_file(ca_file) store.add_file(ca_file) if ca_file
end
if ca_path = config.http_settings['ca_path'] ca_path = config.http_settings['ca_path']
store.add_path(ca_path) store.add_path(ca_path) if ca_path
end
store store
end end
......
...@@ -13,7 +13,8 @@ class GitlabPostReceive ...@@ -13,7 +13,8 @@ class GitlabPostReceive
def initialize(gl_repository, repo_path, actor, changes) def initialize(gl_repository, repo_path, actor, changes)
@config = GitlabConfig.new @config = GitlabConfig.new
@gl_repository = gl_repository @gl_repository = gl_repository
@repo_path, @actor = repo_path.strip, actor @repo_path = repo_path.strip
@actor = actor
@changes = changes @changes = changes
@jid = SecureRandom.hex(12) @jid = SecureRandom.hex(12)
end end
...@@ -47,11 +48,12 @@ class GitlabPostReceive ...@@ -47,11 +48,12 @@ class GitlabPostReceive
end end
def print_merge_request_link(merge_request) def print_merge_request_link(merge_request)
if merge_request["new_merge_request"] message =
message = "To create a merge request for #{merge_request["branch_name"]}, visit:" if merge_request["new_merge_request"]
else "To create a merge request for #{merge_request['branch_name']}, visit:"
message = "View merge request for #{merge_request["branch_name"]}:" else
end "View merge request for #{merge_request['branch_name']}:"
end
puts message puts message
puts((" " * 2) + merge_request["url"]) puts((" " * 2) + merge_request["url"])
...@@ -64,7 +66,7 @@ class GitlabPostReceive ...@@ -64,7 +66,7 @@ class GitlabPostReceive
# Git prefixes remote messages with "remote: ", so this width is subtracted # Git prefixes remote messages with "remote: ", so this width is subtracted
# from the width available to us. # from the width available to us.
total_width -= "remote: ".length total_width -= "remote: ".length # rubocop:disable Performance/FixedSize
# Our centered text shouldn't start or end right at the edge of the window, # Our centered text shouldn't start or end right at the edge of the window,
# so we add some horizontal padding: 2 chars on either side. # so we add some horizontal padding: 2 chars on either side.
......
...@@ -4,7 +4,7 @@ require 'pathname' ...@@ -4,7 +4,7 @@ require 'pathname'
require_relative 'gitlab_net' require_relative 'gitlab_net'
require_relative 'gitlab_metrics' require_relative 'gitlab_metrics'
class GitlabShell class GitlabShell # rubocop:disable Metrics/ClassLength
class AccessDeniedError < StandardError; end class AccessDeniedError < StandardError; end
class DisallowedCommandError < StandardError; end class DisallowedCommandError < StandardError; end
class InvalidRepositoryPathError < StandardError; end class InvalidRepositoryPathError < StandardError; end
...@@ -12,9 +12,9 @@ class GitlabShell ...@@ -12,9 +12,9 @@ class GitlabShell
GIT_COMMANDS = %w(git-upload-pack git-receive-pack git-upload-archive git-lfs-authenticate).freeze GIT_COMMANDS = %w(git-upload-pack git-receive-pack git-upload-archive git-lfs-authenticate).freeze
GITALY_MIGRATED_COMMANDS = { GITALY_MIGRATED_COMMANDS = {
'git-upload-pack' => File.join(ROOT_PATH, 'bin', 'gitaly-upload-pack'), 'git-upload-pack' => File.join(ROOT_PATH, 'bin', 'gitaly-upload-pack'),
'git-receive-pack' => File.join(ROOT_PATH, 'bin', 'gitaly-receive-pack'), 'git-receive-pack' => File.join(ROOT_PATH, 'bin', 'gitaly-receive-pack')
} }.freeze
API_COMMANDS = %w(2fa_recovery_codes) API_COMMANDS = %w(2fa_recovery_codes).freeze
GL_PROTOCOL = 'ssh'.freeze GL_PROTOCOL = 'ssh'.freeze
attr_accessor :key_id, :gl_repository, :repo_name, :command, :git_access, :username attr_accessor :key_id, :gl_repository, :repo_name, :command, :git_access, :username
...@@ -44,7 +44,7 @@ class GitlabShell ...@@ -44,7 +44,7 @@ class GitlabShell
process_cmd(args) process_cmd(args)
true true
rescue GitlabNet::ApiUnreachableError => ex rescue GitlabNet::ApiUnreachableError
$stderr.puts "GitLab: Failed to authorize your Git request: internal API unreachable" $stderr.puts "GitLab: Failed to authorize your Git request: internal API unreachable"
false false
rescue AccessDeniedError => ex rescue AccessDeniedError => ex
...@@ -53,13 +53,13 @@ class GitlabShell ...@@ -53,13 +53,13 @@ class GitlabShell
$stderr.puts "GitLab: #{ex.message}" $stderr.puts "GitLab: #{ex.message}"
false false
rescue DisallowedCommandError => ex rescue DisallowedCommandError
message = "gitlab-shell: Attempt to execute disallowed command <#{origin_cmd}> by #{log_username}." message = "gitlab-shell: Attempt to execute disallowed command <#{origin_cmd}> by #{log_username}."
$logger.warn message $logger.warn message
$stderr.puts "GitLab: Disallowed command" $stderr.puts "GitLab: Disallowed command"
false false
rescue InvalidRepositoryPathError => ex rescue InvalidRepositoryPathError
$stderr.puts "GitLab: Invalid repository path" $stderr.puts "GitLab: Invalid repository path"
false false
end end
...@@ -113,7 +113,7 @@ class GitlabShell ...@@ -113,7 +113,7 @@ class GitlabShell
end end
def process_cmd(args) def process_cmd(args)
return self.send("api_#{@command}") if API_COMMANDS.include?(@command) return send("api_#{@command}") if API_COMMANDS.include?(@command)
if @command == 'git-lfs-authenticate' if @command == 'git-lfs-authenticate'
GitlabMetrics.measure('lfs-authenticate') do GitlabMetrics.measure('lfs-authenticate') do
...@@ -126,7 +126,7 @@ class GitlabShell ...@@ -126,7 +126,7 @@ class GitlabShell
executable = @command executable = @command
args = [repo_path] args = [repo_path]
if GITALY_MIGRATED_COMMANDS.has_key?(executable) && @gitaly if GITALY_MIGRATED_COMMANDS.key?(executable) && @gitaly
executable = GITALY_MIGRATED_COMMANDS[executable] executable = GITALY_MIGRATED_COMMANDS[executable]
gitaly_address = @gitaly['address'] gitaly_address = @gitaly['address']
...@@ -172,15 +172,15 @@ class GitlabShell ...@@ -172,15 +172,15 @@ class GitlabShell
end end
if git_trace_available? if git_trace_available?
env.merge!({ env.merge!(
'GIT_TRACE' => @config.git_trace_log_file, 'GIT_TRACE' => @config.git_trace_log_file,
'GIT_TRACE_PACKET' => @config.git_trace_log_file, 'GIT_TRACE_PACKET' => @config.git_trace_log_file,
'GIT_TRACE_PERFORMANCE' => @config.git_trace_log_file, 'GIT_TRACE_PERFORMANCE' => @config.git_trace_log_file
}) )
end end
# We use 'chdir: ROOT_PATH' to let the next executable know where config.yml is. # We use 'chdir: ROOT_PATH' to let the next executable know where config.yml is.
Kernel::exec(env, *args, unsetenv_others: true, chdir: ROOT_PATH) Kernel.exec(env, *args, unsetenv_others: true, chdir: ROOT_PATH)
end end
def api def api
......
...@@ -11,7 +11,7 @@ module URI ...@@ -11,7 +11,7 @@ module URI
class HTTPUNIX < HTTP class HTTPUNIX < HTTP
def hostname def hostname
# decode %XX from path to file # decode %XX from path to file
v = self.host v = host
URI.decode(v) URI.decode(v)
end end
...@@ -30,9 +30,9 @@ end ...@@ -30,9 +30,9 @@ end
# - Net::HTTP::connect # - Net::HTTP::connect
module Net module Net
class HTTPUNIX < HTTP class HTTPUNIX < HTTP
def initialize(socketpath, port=nil) def initialize(socketpath, port = nil)
super(socketpath, port) super(socketpath, port)
@port = nil # HTTP will set it to default - override back -> set DEFAULT_PORT @port = nil # HTTP will set it to default - override back -> set DEFAULT_PORT
end end
# override to prevent ":<port>" being appended to HTTP_HOST # override to prevent ":<port>" being appended to HTTP_HOST
......
...@@ -5,7 +5,7 @@ def main(check) ...@@ -5,7 +5,7 @@ def main(check)
cmd = %w[gofmt -s -l] cmd = %w[gofmt -s -l]
cmd << '-w' unless check cmd << '-w' unless check
cmd += go_files cmd += go_files
output = IO.popen(cmd, 'r') { |io| io.read } output = IO.popen(cmd, 'r', &:read)
$stdout.write(output) $stdout.write(output)
abort 'gofmt failed' unless $?.success? abort 'gofmt failed' unless $?.success?
if check && output.lines.any? { |l| l != "\n" } if check && output.lines.any? { |l| l != "\n" }
......
...@@ -6,14 +6,14 @@ require 'fileutils' ...@@ -6,14 +6,14 @@ require 'fileutils'
require_relative '../lib/gitlab_init' require_relative '../lib/gitlab_init'
module GoBuild module GoBuild
GO_DIR = 'go' GO_DIR = 'go'.freeze
BUILD_DIR = File.join(ROOT_PATH, 'go_build') BUILD_DIR = File.join(ROOT_PATH, 'go_build')
GO_PACKAGE = File.join('gitlab.com/gitlab-org/gitlab-shell', GO_DIR) GO_PACKAGE = File.join('gitlab.com/gitlab-org/gitlab-shell', GO_DIR)
GO_ENV = { GO_ENV = {
'GOPATH' => BUILD_DIR, 'GOPATH' => BUILD_DIR,
'GO15VENDOREXPERIMENT' => '1', 'GO15VENDOREXPERIMENT' => '1'
} }.freeze
def create_fresh_build_dir def create_fresh_build_dir
FileUtils.rm_rf(BUILD_DIR) FileUtils.rm_rf(BUILD_DIR)
...@@ -25,8 +25,8 @@ module GoBuild ...@@ -25,8 +25,8 @@ module GoBuild
def run!(env, cmd) def run!(env, cmd)
raise "env must be a hash" unless env.is_a?(Hash) raise "env must be a hash" unless env.is_a?(Hash)
raise "cmd must be an array" unless cmd.is_a?(Array) raise "cmd must be an array" unless cmd.is_a?(Array)
if !system(env, *cmd) unless system(env, *cmd)
abort "command failed: #{env.inspect} #{cmd.join(' ')}" abort "command failed: #{env.inspect} #{cmd.join(' ')}"
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment