Commit 87c9df29 authored by Douwe Maan's avatar Douwe Maan

Don’t exclude some file in lib from rubocop

parent e2bbbb1a
......@@ -22,13 +22,6 @@ AllCops:
- 'db/fixtures/**/*'
- 'tmp/**/*'
- 'bin/**/*'
- 'lib/backup/**/*'
- 'lib/ci/backup/**/*'
- 'lib/tasks/**/*'
- 'lib/ci/migrate/**/*'
- 'lib/email_validator.rb'
- 'lib/gitlab/upgrader.rb'
- 'lib/gitlab/seeder.rb'
- 'generator_templates/**/*'
# Style #######################################################################
......@@ -208,6 +201,9 @@ Style/FrozenStringLiteralComment:
# Do not introduce global variables.
Style/GlobalVars:
Enabled: true
Exclude:
- 'lib/backup/**/*'
- 'lib/tasks/**/*'
# Prefer Ruby 1.9 hash syntax `{ a: 1, b: 2 }`
# over 1.8 syntax `{ :a => 1, :b => 2 }`.
......@@ -780,6 +776,11 @@ Rails/HasAndBelongsToMany:
# Checks for calls to puts, print, etc.
Rails/Output:
Enabled: true
Exclude:
- lib/gitlab/seeder.rb
- lib/gitlab/upgrader.rb
- 'lib/backup/**/*'
- 'lib/tasks/**/*'
# Checks for incorrect grammar when using methods like `3.day.ago`.
Rails/PluralizationGrammar:
......@@ -971,3 +972,9 @@ Style/ConditionalAssignment:
Style/DoubleNegation:
Enabled: false
Rails/Exit:
Enabled: true
Exclude:
- lib/gitlab/upgrader.rb
- 'lib/backup/**/*'
......@@ -5,7 +5,7 @@ module Backup
attr_reader :config, :db_file_name
def initialize
@config = YAML.load_file(File.join(Rails.root,'config','database.yml'))[Rails.env]
@config = YAML.load_file(File.join(Rails.root, 'config', 'database.yml'))[Rails.env]
@db_file_name = File.join(Gitlab.config.backup.path, 'db', 'database.sql.gz')
end
......@@ -13,28 +13,32 @@ module Backup
FileUtils.mkdir_p(File.dirname(db_file_name))
FileUtils.rm_f(db_file_name)
compress_rd, compress_wr = IO.pipe
compress_pid = spawn(*%W(gzip -1 -c), in: compress_rd, out: [db_file_name, 'w', 0600])
compress_pid = spawn(*%w(gzip -1 -c), in: compress_rd, out: [db_file_name, 'w', 0600])
compress_rd.close
dump_pid = case config["adapter"]
when /^mysql/ then
$progress.print "Dumping MySQL database #{config['database']} ... "
# Workaround warnings from MySQL 5.6 about passwords on cmd line
ENV['MYSQL_PWD'] = config["password"].to_s if config["password"]
spawn('mysqldump', *mysql_args, config['database'], out: compress_wr)
when "postgresql" then
$progress.print "Dumping PostgreSQL database #{config['database']} ... "
pg_env
pgsql_args = ["--clean"] # Pass '--clean' to include 'DROP TABLE' statements in the DB dump.
if Gitlab.config.backup.pg_schema
pgsql_args << "-n"
pgsql_args << Gitlab.config.backup.pg_schema
dump_pid =
case config["adapter"]
when /^mysql/ then
$progress.print "Dumping MySQL database #{config['database']} ... "
# Workaround warnings from MySQL 5.6 about passwords on cmd line
ENV['MYSQL_PWD'] = config["password"].to_s if config["password"]
spawn('mysqldump', *mysql_args, config['database'], out: compress_wr)
when "postgresql" then
$progress.print "Dumping PostgreSQL database #{config['database']} ... "
pg_env
pgsql_args = ["--clean"] # Pass '--clean' to include 'DROP TABLE' statements in the DB dump.
if Gitlab.config.backup.pg_schema
pgsql_args << "-n"
pgsql_args << Gitlab.config.backup.pg_schema
end
spawn('pg_dump', *pgsql_args, config['database'], out: compress_wr)
end
spawn('pg_dump', *pgsql_args, config['database'], out: compress_wr)
end
compress_wr.close
success = [compress_pid, dump_pid].all? { |pid| Process.waitpid(pid); $?.success? }
success = [compress_pid, dump_pid].all? do |pid|
Process.waitpid(pid)
$?.success?
end
report_success(success)
abort 'Backup failed' unless success
......@@ -42,23 +46,27 @@ module Backup
def restore
decompress_rd, decompress_wr = IO.pipe
decompress_pid = spawn(*%W(gzip -cd), out: decompress_wr, in: db_file_name)
decompress_pid = spawn(*%w(gzip -cd), out: decompress_wr, in: db_file_name)
decompress_wr.close
restore_pid = case config["adapter"]
when /^mysql/ then
$progress.print "Restoring MySQL database #{config['database']} ... "
# Workaround warnings from MySQL 5.6 about passwords on cmd line
ENV['MYSQL_PWD'] = config["password"].to_s if config["password"]
spawn('mysql', *mysql_args, config['database'], in: decompress_rd)
when "postgresql" then
$progress.print "Restoring PostgreSQL database #{config['database']} ... "
pg_env
spawn('psql', config['database'], in: decompress_rd)
end
restore_pid =
case config["adapter"]
when /^mysql/ then
$progress.print "Restoring MySQL database #{config['database']} ... "
# Workaround warnings from MySQL 5.6 about passwords on cmd line
ENV['MYSQL_PWD'] = config["password"].to_s if config["password"]
spawn('mysql', *mysql_args, config['database'], in: decompress_rd)
when "postgresql" then
$progress.print "Restoring PostgreSQL database #{config['database']} ... "
pg_env
spawn('psql', config['database'], in: decompress_rd)
end
decompress_rd.close
success = [decompress_pid, restore_pid].all? { |pid| Process.waitpid(pid); $?.success? }
success = [decompress_pid, restore_pid].all? do |pid|
Process.waitpid(pid)
$?.success?
end
report_success(success)
abort 'Restore failed' unless success
......
......@@ -26,10 +26,10 @@ module Backup
abort 'Backup failed'
end
run_pipeline!([%W(tar -C #{@backup_files_dir} -cf - .), %W(gzip -c -1)], out: [backup_tarball, 'w', 0600])
run_pipeline!([%W(tar -C #{@backup_files_dir} -cf - .), %w(gzip -c -1)], out: [backup_tarball, 'w', 0600])
FileUtils.rm_rf(@backup_files_dir)
else
run_pipeline!([%W(tar -C #{app_files_dir} -cf - .), %W(gzip -c -1)], out: [backup_tarball, 'w', 0600])
run_pipeline!([%W(tar -C #{app_files_dir} -cf - .), %w(gzip -c -1)], out: [backup_tarball, 'w', 0600])
end
end
......@@ -37,7 +37,7 @@ module Backup
backup_existing_files_dir
create_files_dir
run_pipeline!([%W(gzip -cd), %W(tar -C #{app_files_dir} -xf -)], in: backup_tarball)
run_pipeline!([%w(gzip -cd), %W(tar -C #{app_files_dir} -xf -)], in: backup_tarball)
end
def backup_existing_files_dir
......@@ -47,7 +47,7 @@ module Backup
end
end
def run_pipeline!(cmd_list, options={})
def run_pipeline!(cmd_list, options = {})
status_list = Open3.pipeline(*cmd_list, options)
abort 'Backup failed' unless status_list.compact.all?(&:success?)
end
......
module Backup
class Manager
ARCHIVES_TO_BACKUP = %w[uploads builds artifacts pages lfs registry]
FOLDERS_TO_BACKUP = %w[repositories db]
FILE_NAME_SUFFIX = '_gitlab_backup.tar'
ARCHIVES_TO_BACKUP = %w[uploads builds artifacts pages lfs registry].freeze
FOLDERS_TO_BACKUP = %w[repositories db].freeze
FILE_NAME_SUFFIX = '_gitlab_backup.tar'.freeze
def pack
# Make sure there is a connection
......@@ -20,13 +20,13 @@ module Backup
Dir.chdir(Gitlab.config.backup.path) do
File.open("#{Gitlab.config.backup.path}/backup_information.yml",
"w+") do |file|
file << s.to_yaml.gsub(/^---\n/,'')
file << s.to_yaml.gsub(/^---\n/, '')
end
# create archive
$progress.print "Creating backup archive: #{tar_file} ... "
# Set file permissions on open to prevent chmod races.
tar_system_options = {out: [tar_file, 'w', Gitlab.config.backup.archive_permissions]}
tar_system_options = { out: [tar_file, 'w', Gitlab.config.backup.archive_permissions] }
if Kernel.system('tar', '-cf', '-', *backup_contents, tar_system_options)
$progress.puts "done".color(:green)
else
......@@ -50,8 +50,8 @@ module Backup
directory = connect_to_remote_directory(connection_settings)
if directory.files.create(key: tar_file, body: File.open(tar_file), public: false,
multipart_chunk_size: Gitlab.config.backup.upload.multipart_chunk_size,
encryption: Gitlab.config.backup.upload.encryption)
multipart_chunk_size: Gitlab.config.backup.upload.multipart_chunk_size,
encryption: Gitlab.config.backup.upload.encryption)
$progress.puts "done".color(:green)
else
puts "uploading backup to #{remote_directory} failed".color(:red)
......@@ -123,11 +123,11 @@ module Backup
exit 1
end
if ENV['BACKUP'].present?
tar_file = "#{ENV['BACKUP']}#{FILE_NAME_SUFFIX}"
else
tar_file = file_list.first
end
tar_file = if ENV['BACKUP'].present?
"#{ENV['BACKUP']}#{FILE_NAME_SUFFIX}"
else
file_list.first
end
unless File.exist?(tar_file)
$progress.puts "The backup file #{tar_file} does not exist!"
......@@ -158,7 +158,7 @@ module Backup
end
def tar_version
tar_version, _ = Gitlab::Popen.popen(%W(tar --version))
tar_version, _ = Gitlab::Popen.popen(%w(tar --version))
tar_version.force_encoding('locale').split("\n").first
end
......
......@@ -2,7 +2,7 @@ require 'yaml'
module Backup
class Repository
# rubocop:disable Metrics/AbcSize
def dump
prepare
......@@ -85,11 +85,11 @@ module Backup
project.ensure_dir_exist
if File.exists?(path_to_project_bundle)
cmd = %W(#{Gitlab.config.git.bin_path} clone --bare #{path_to_project_bundle} #{path_to_project_repo})
else
cmd = %W(#{Gitlab.config.git.bin_path} init --bare #{path_to_project_repo})
end
cmd = if File.exist?(path_to_project_bundle)
%W(#{Gitlab.config.git.bin_path} clone --bare #{path_to_project_bundle} #{path_to_project_repo})
else
%W(#{Gitlab.config.git.bin_path} init --bare #{path_to_project_repo})
end
output, status = Gitlab::Popen.popen(cmd)
if status.zero?
......@@ -150,6 +150,7 @@ module Backup
puts output
end
end
# rubocop:enable Metrics/AbcSize
protected
......@@ -193,7 +194,7 @@ module Backup
end
def silent
{err: '/dev/null', out: '/dev/null'}
{ err: '/dev/null', out: '/dev/null' }
end
private
......
......@@ -2,7 +2,6 @@ require 'backup/files'
module Backup
class Uploads < Files
def initialize
super('uploads', Rails.root.join('public/uploads'))
end
......
......@@ -18,7 +18,7 @@ def Notify.deliver_later
self
end
eos
eval(code)
eval(code) # rubocop:disable Lint/Eval
end
end
end
......@@ -46,7 +46,7 @@ module Gitlab
git_tags = fetch_git_tags
git_tags = git_tags.select { |version| version =~ /v\d+\.\d+\.\d+\Z/ }
git_versions = git_tags.map { |tag| Gitlab::VersionInfo.parse(tag.match(/v\d+\.\d+\.\d+/).to_s) }
"v#{git_versions.sort.last.to_s}"
"v#{git_versions.sort.last}"
end
def fetch_git_tags
......@@ -59,10 +59,10 @@ module Gitlab
"Stash changed files" => %W(#{Gitlab.config.git.bin_path} stash),
"Get latest code" => %W(#{Gitlab.config.git.bin_path} fetch),
"Switch to new version" => %W(#{Gitlab.config.git.bin_path} checkout v#{latest_version}),
"Install gems" => %W(bundle),
"Migrate DB" => %W(bundle exec rake db:migrate),
"Recompile assets" => %W(bundle exec rake yarn:install gitlab:assets:clean gitlab:assets:compile),
"Clear cache" => %W(bundle exec rake cache:clear)
"Install gems" => %w(bundle),
"Migrate DB" => %w(bundle exec rake db:migrate),
"Recompile assets" => %w(bundle exec rake yarn:install gitlab:assets:clean gitlab:assets:compile),
"Clear cache" => %w(bundle exec rake cache:clear)
}
end
......
......@@ -2,7 +2,7 @@ desc 'Security check via brakeman'
task :brakeman do
# We get 0 warnings at level 'w3' but we would like to reach 'w2'. Merge
# requests are welcome!
if system(*%W(brakeman --no-progress --skip-files lib/backup/repository.rb -w3 -z))
if system(*%w(brakeman --no-progress --skip-files lib/backup/repository.rb -w3 -z))
puts 'Security check succeed'
else
puts 'Security check failed'
......
namespace :cache do
namespace :clear do
REDIS_CLEAR_BATCH_SIZE = 1000 # There seems to be no speedup when pushing beyond 1,000
REDIS_SCAN_START_STOP = '0' # Magic value, see http://redis.io/commands/scan
REDIS_SCAN_START_STOP = '0'.freeze # Magic value, see http://redis.io/commands/scan
desc "GitLab | Clear redis cache"
task redis: :environment do
......
......@@ -2,7 +2,7 @@ task dev: ["dev:setup"]
namespace :dev do
desc "GitLab | Setup developer environment (db, fixtures)"
task :setup => :environment do
task setup: :environment do
ENV['force'] = 'yes'
Rake::Task["gitlab:setup"].invoke
Rake::Task["gitlab:shell:setup"].invoke
......
desc 'Checks if migrations in a branch require downtime'
task downtime_check: :environment do
if defined?(Gitlab::License)
repo = 'gitlab-ee'
else
repo = 'gitlab-ce'
end
repo = if defined?(Gitlab::License)
'gitlab-ee'
else
'gitlab-ce'
end
`git fetch https://gitlab.com/gitlab-org/#{repo}.git --depth 1`
......
desc 'Code duplication analyze via flay'
task :flay do
output = %x(bundle exec flay --mass 35 app/ lib/gitlab/)
output = `bundle exec flay --mass 35 app/ lib/gitlab/`
if output.include? "Similar code found"
puts output
......
......@@ -81,9 +81,9 @@ namespace :gemojione do
# SpriteFactory's SCSS is a bit too verbose for our purposes here, so
# let's simplify it
system(%Q(sed -i '' "s/width: #{SIZE}px; height: #{SIZE}px; background: image-url('emoji.png')/background-position:/" #{style_path}))
system(%Q(sed -i '' "s/ no-repeat//" #{style_path}))
system(%Q(sed -i '' "s/ 0px/ 0/" #{style_path}))
system(%(sed -i '' "s/width: #{SIZE}px; height: #{SIZE}px; background: image-url('emoji.png')/background-position:/" #{style_path}))
system(%(sed -i '' "s/ no-repeat//" #{style_path}))
system(%(sed -i '' "s/ 0px/ 0/" #{style_path}))
# Append a generic rule that applies to all Emojis
File.open(style_path, 'a') do |f|
......
......@@ -20,7 +20,7 @@ namespace :gitlab do
desc 'GitLab | Assets | Fix all absolute url references in CSS'
task :fix_urls do
css_files = Dir['public/assets/*.css']
css_files.each do | file |
css_files.each do |file|
# replace url(/assets/*) with url(./*)
puts "Fixing #{file}"
system "sed", "-i", "-e", 's/url(\([\"\']\?\)\/assets\//url(\1.\//g', file
......
......@@ -6,8 +6,6 @@ namespace :gitlab do
gitlab:ldap:check
gitlab:app:check}
namespace :app do
desc "GitLab | Check the configuration of the GitLab Rails app"
task check: :environment do
......@@ -34,7 +32,6 @@ namespace :gitlab do
finished_checking "GitLab"
end
# Checks
########################
......@@ -194,7 +191,7 @@ namespace :gitlab do
def check_migrations_are_up
print "All migrations up? ... "
migration_status, _ = Gitlab::Popen.popen(%W(bundle exec rake db:migrate:status))
migration_status, _ = Gitlab::Popen.popen(%w(bundle exec rake db:migrate:status))
unless migration_status =~ /down\s+\d{14}/
puts "yes".color(:green)
......@@ -279,7 +276,7 @@ namespace :gitlab do
upload_path_tmp = File.join(upload_path, 'tmp')
if File.stat(upload_path).mode == 040700
unless Dir.exists?(upload_path_tmp)
unless Dir.exist?(upload_path_tmp)
puts 'skipped (no tmp uploads folder yet)'.color(:magenta)
return
end
......@@ -316,7 +313,7 @@ namespace :gitlab do
min_redis_version = "2.8.0"
print "Redis version >= #{min_redis_version}? ... "
redis_version = run_command(%W(redis-cli --version))
redis_version = run_command(%w(redis-cli --version))
redis_version = redis_version.try(:match, /redis-cli (\d+\.\d+\.\d+)/)
if redis_version &&
(Gem::Version.new(redis_version[1]) > Gem::Version.new(min_redis_version))
......@@ -351,7 +348,6 @@ namespace :gitlab do
finished_checking "GitLab Shell"
end
# Checks
########################
......@@ -387,7 +383,7 @@ namespace :gitlab do
unless File.exist?(repo_base_path)
puts "can't check because of previous errors".color(:magenta)
return
break
end
unless File.symlink?(repo_base_path)
......@@ -410,7 +406,7 @@ namespace :gitlab do
unless File.exist?(repo_base_path)
puts "can't check because of previous errors".color(:magenta)
return
break
end
if File.stat(repo_base_path).mode.to_s(8).ends_with?("2770")
......@@ -440,7 +436,7 @@ namespace :gitlab do
unless File.exist?(repo_base_path)
puts "can't check because of previous errors".color(:magenta)
return
break
end
uid = uid_for(gitlab_shell_ssh_user)
......@@ -493,7 +489,6 @@ namespace :gitlab do
)
fix_and_rerun
end
end
end
......@@ -565,8 +560,6 @@ namespace :gitlab do
end
end
namespace :sidekiq do
desc "GitLab | Check the configuration of Sidekiq"
task check: :environment do
......@@ -579,7 +572,6 @@ namespace :gitlab do
finished_checking "Sidekiq"
end
# Checks
########################
......@@ -621,12 +613,11 @@ namespace :gitlab do
end
def sidekiq_process_count
ps_ux, _ = Gitlab::Popen.popen(%W(ps ux))
ps_ux, _ = Gitlab::Popen.popen(%w(ps ux))
ps_ux.scan(/sidekiq \d+\.\d+\.\d+/).count
end
end
namespace :incoming_email do
desc "GitLab | Check the configuration of Reply by email"
task check: :environment do
......@@ -649,7 +640,6 @@ namespace :gitlab do
finished_checking "Reply by email"
end
# Checks
########################
......@@ -757,7 +747,7 @@ namespace :gitlab do
end
def mail_room_running?
ps_ux, _ = Gitlab::Popen.popen(%W(ps ux))
ps_ux, _ = Gitlab::Popen.popen(%w(ps ux))
ps_ux.include?("mail_room")
end
end
......@@ -805,13 +795,13 @@ namespace :gitlab do
def check_ldap_auth(adapter)
auth = adapter.config.has_auth?
if auth && adapter.ldap.bind
message = 'Success'.color(:green)
elsif auth
message = 'Failed. Check `bind_dn` and `password` configuration values'.color(:red)
else
message = 'Anonymous. No `bind_dn` or `password` configured'.color(:yellow)
end
message = if auth && adapter.ldap.bind
'Success'.color(:green)
elsif auth
'Failed. Check `bind_dn` and `password` configuration values'.color(:red)
else
'Anonymous. No `bind_dn` or `password` configured'.color(:yellow)
end
puts "LDAP authentication... #{message}"
end
......@@ -838,11 +828,11 @@ namespace :gitlab do
user = User.find_by(username: username)
if user
repo_dirs = user.authorized_projects.map do |p|
File.join(
p.repository_storage_path,
"#{p.path_with_namespace}.git"
)
end
File.join(
p.repository_storage_path,
"#{p.path_with_namespace}.git"
)
end
repo_dirs.each { |repo_dir| check_repo_integrity(repo_dir) }
else
......@@ -855,7 +845,7 @@ namespace :gitlab do
##########################
def fix_and_rerun
puts " Please #{"fix the error above"} and rerun the checks.".color(:red)
puts " Please fix the error above and rerun the checks.".color(:red)
end
def for_more_information(*sources)
......@@ -917,7 +907,7 @@ namespace :gitlab do
def check_ruby_version
required_version = Gitlab::VersionInfo.new(2, 1, 0)
current_version = Gitlab::VersionInfo.parse(run_command(%W(ruby --version)))
current_version = Gitlab::VersionInfo.parse(run_command(%w(ruby --version)))
print "Ruby version >= #{required_version} ? ... "
......@@ -988,13 +978,13 @@ namespace :gitlab do
end
def check_config_lock(repo_dir)
config_exists = File.exist?(File.join(repo_dir,'config.lock'))
config_exists = File.exist?(File.join(repo_dir, 'config.lock'))
config_output = config_exists ? 'yes'.color(:red) : 'no'.color(:green)
puts "'config.lock' file exists?".color(:yellow) + " ... #{config_output}"
end
def check_ref_locks(repo_dir)
lock_files = Dir.glob(File.join(repo_dir,'refs/heads/*.lock'))
lock_files = Dir.glob(File.join(repo_dir, 'refs/heads/*.lock'))
if lock_files.present?
puts "Ref lock files exist:".color(:red)
lock_files.each do |lock_file|
......
......@@ -25,7 +25,6 @@ namespace :gitlab do
end
all_dirs.each do |dir_path|
if remove_flag
if FileUtils.rm_rf dir_path
puts "Removed...#{dir_path}".color(:red)
......@@ -53,11 +52,11 @@ namespace :gitlab do
IO.popen(%W(find #{repo_root} -mindepth 1 -maxdepth 2 -name *.git)) do |find|
find.each_line do |path|
path.chomp!
repo_with_namespace = path.
sub(repo_root, '').
sub(%r{^/*}, '').
chomp('.git').
chomp('.wiki')
repo_with_namespace = path
.sub(repo_root, '')
.sub(%r{^/*}, '')
.chomp('.git')
.chomp('.wiki')
next if Project.find_by_full_path(repo_with_namespace)
new_path = path + move_suffix
puts path.inspect + ' -> ' + new_path.inspect
......
......@@ -23,7 +23,7 @@ namespace :gitlab do
end
desc 'Drop all tables'
task :drop_tables => :environment do
task drop_tables: :environment do
connection = ActiveRecord::Base.connection
# If MySQL, turn off foreign key checks
......@@ -62,9 +62,9 @@ namespace :gitlab do
ref = Shellwords.escape(args[:ref])
migrations = `git diff #{ref}.. --name-only -- db/migrate`.lines.
map { |file| Rails.root.join(file.strip).to_s }.
select { |file| File.file?(file) }
migrations = `git diff #{ref}.. --name-only -- db/migrate`.lines
.map { |file| Rails.root.join(file.strip).to_s }
.select { |file| File.file?(file) }
Gitlab::DowntimeCheck.new.check_and_print(migrations)
end
......
namespace :gitlab do
namespace :git do
desc "GitLab | Git | Repack"
task repack: :environment do
failures = perform_git_cmd(%W(#{Gitlab.config.git.bin_path} repack -a --quiet), "Repacking repo")
......@@ -50,6 +49,5 @@ namespace :gitlab do
puts "The following repositories reported errors:".color(:red)
failures.each { |f| puts "- #{f}" }
end
end
end
......@@ -46,7 +46,7 @@ namespace :gitlab do
group = Namespace.find_by(path: group_name)
# create group namespace
unless group
group = Group.new(:name => group_name)
group = Group.new(name: group_name)
group.path = group_name
group.owner = user
if group.save
......
......@@ -7,7 +7,7 @@ namespace :gitlab do
desc "GitLab | Display exported DB structure"
task data: :environment do
puts YAML.load_file(Gitlab::ImportExport.config_file)['project_tree'].to_yaml(:SortKeys => true)
puts YAML.load_file(Gitlab::ImportExport.config_file)['project_tree'].to_yaml(SortKeys: true)
end
end
end
......@@ -2,24 +2,23 @@ namespace :gitlab do
namespace :env do
desc "GitLab | Show information about GitLab and its environment"
task info: :environment do
# check if there is an RVM environment
rvm_version = run_and_match(%W(rvm --version), /[\d\.]+/).try(:to_s)
rvm_version = run_and_match(%w(rvm --version), /[\d\.]+/).try(:to_s)
# check Ruby version
ruby_version = run_and_match(%W(ruby --version), /[\d\.p]+/).try(:to_s)
ruby_version = run_and_match(%w(ruby --version), /[\d\.p]+/).try(:to_s)
# check Gem version
gem_version = run_command(%W(gem --version))
gem_version = run_command(%w(gem --version))
# check Bundler version
bunder_version = run_and_match(%W(bundle --version), /[\d\.]+/).try(:to_s)
bunder_version = run_and_match(%w(bundle --version), /[\d\.]+/).try(:to_s)
# check Rake version
rake_version = run_and_match(%W(rake --version), /[\d\.]+/).try(:to_s)
rake_version = run_and_match(%w(rake --version), /[\d\.]+/).try(:to_s)
# check redis version
redis_version = run_and_match(%W(redis-cli --version), /redis-cli (\d+\.\d+\.\d+)/).to_a
redis_version = run_and_match(%w(redis-cli --version), /redis-cli (\d+\.\d+\.\d+)/).to_a
puts ""
puts "System information".color(:yellow)
puts "System:\t\t#{os_name || "unknown".color(:red)}"
puts "Current User:\t#{run_command(%W(whoami))}"
puts "Current User:\t#{run_command(%w(whoami))}"
puts "Using RVM:\t#{rvm_version.present? ? "yes".color(:green) : "no"}"
puts "RVM Version:\t#{rvm_version}" if rvm_version.present?
puts "Ruby Version:\t#{ruby_version || "unknown".color(:red)}"
......@@ -29,7 +28,6 @@ namespace :gitlab do
puts "Redis Version:\t#{redis_version[1] || "unknown".color(:red)}"
puts "Sidekiq Version:#{Sidekiq::VERSION}"
# check database adapter
database_adapter = ActiveRecord::Base.connection.adapter_name.downcase
......@@ -54,8 +52,6 @@ namespace :gitlab do
puts "Using Omniauth:\t#{Gitlab.config.omniauth.enabled ? "yes".color(:green) : "no"}"
puts "Omniauth Providers: #{omniauth_providers.join(', ')}" if Gitlab.config.omniauth.enabled
# check Gitolite version
gitlab_shell_version_file = "#{Gitlab.config.gitlab_shell.hooks_path}/../VERSION"
if File.readable?(gitlab_shell_version_file)
......@@ -71,7 +67,6 @@ namespace :gitlab do
end
puts "Hooks:\t\t#{Gitlab.config.gitlab_shell.hooks_path}"
puts "Git:\t\t#{Gitlab.config.git.bin_path}"
end
end
end
......@@ -20,10 +20,10 @@ namespace :gitlab do
config = {
user: Gitlab.config.gitlab.user,
gitlab_url: gitlab_url,
http_settings: {self_signed_cert: false}.stringify_keys,
http_settings: { self_signed_cert: false }.stringify_keys,
auth_file: File.join(user_home, ".ssh", "authorized_keys"),
redis: {
bin: %x{which redis-cli}.chomp,
bin: `which redis-cli`.chomp,
namespace: "resque:gitlab"
}.stringify_keys,
log_level: "INFO",
......@@ -43,7 +43,7 @@ namespace :gitlab do
File.open("config.yml", "w+") {|f| f.puts config.to_yaml}
# Launch installation process
system(*%W(bin/install) + repository_storage_paths_args)
system(*%w(bin/install) + repository_storage_paths_args)
end
# (Re)create hooks
......
namespace :gitlab do
namespace :sidekiq do
QUEUE = 'queue:post_receive'
QUEUE = 'queue:post_receive'.freeze
desc 'Drop all Sidekiq PostReceive jobs for a given project'
task :drop_post_receive , [:project] => :environment do |t, args|
task :drop_post_receive, [:project] => :environment do |t, args|
unless args.project.present?
abort "Please specify the project you want to drop PostReceive jobs for:\n rake gitlab:sidekiq:drop_post_receive[group/project]"
end
......@@ -21,7 +21,7 @@ namespace :gitlab do
# new jobs already. We will repopulate it with the old jobs, skipping the
# ones we want to drop.
dropped = 0
while (job = redis.lpop(temp_queue)) do
while (job = redis.lpop(temp_queue))
if repo_path(job) == project_path
dropped += 1
else
......
......@@ -19,23 +19,15 @@ module Gitlab
# It will primarily use lsb_relase to determine the OS.
# It has fallbacks to Debian, SuSE, OS X and systems running systemd.
def os_name
os_name = run_command(%W(lsb_release -irs))
os_name ||= if File.readable?('/etc/system-release')
File.read('/etc/system-release')
end
os_name ||= if File.readable?('/etc/debian_version')
debian_version = File.read('/etc/debian_version')
"Debian #{debian_version}"
end
os_name ||= if File.readable?('/etc/SuSE-release')
File.read('/etc/SuSE-release')
end
os_name ||= if os_x_version = run_command(%W(sw_vers -productVersion))
"Mac OS X #{os_x_version}"
end
os_name ||= if File.readable?('/etc/os-release')
File.read('/etc/os-release').match(/PRETTY_NAME=\"(.+)\"/)[1]
end
os_name = run_command(%w(lsb_release -irs))
os_name ||= File.read('/etc/system-release') if File.readable?('/etc/system-release')
os_name ||= "Debian #{File.read('/etc/debian_version')}" if File.readable?('/etc/debian_version')
os_name ||= File.read('/etc/SuSE-release') if File.readable?('/etc/SuSE-release')
os_name ||=
if os_x_version = run_command(%w(sw_vers -productVersion))
"Mac OS X #{os_x_version}"
end
os_name ||= File.read('/etc/os-release').match(/PRETTY_NAME=\"(.+)\"/)[1] if File.readable?('/etc/os-release')
os_name.try(:squish!)
end
......@@ -104,7 +96,7 @@ module Gitlab
def warn_user_is_not_gitlab
unless @warned_user_not_gitlab
gitlab_user = Gitlab.config.gitlab.user
current_user = run_command(%W(whoami)).chomp
current_user = run_command(%w(whoami)).chomp
unless current_user == gitlab_user
puts " Warning ".color(:black).background(:yellow)
puts " You are running as user #{current_user.color(:magenta)}, we hope you know what you are doing."
......@@ -171,14 +163,14 @@ module Gitlab
def reset_to_tag(tag_wanted, target_dir)
tag =
begin
# First try to checkout without fetching
# to avoid stalling tests if the Internet is down.
run_command!(%W[#{Gitlab.config.git.bin_path} -C #{target_dir} describe -- #{tag_wanted}])
rescue Gitlab::TaskFailedError
run_command!(%W[#{Gitlab.config.git.bin_path} -C #{target_dir} fetch origin])
run_command!(%W[#{Gitlab.config.git.bin_path} -C #{target_dir} describe -- origin/#{tag_wanted}])
end
begin
# First try to checkout without fetching
# to avoid stalling tests if the Internet is down.
run_command!(%W[#{Gitlab.config.git.bin_path} -C #{target_dir} describe -- #{tag_wanted}])
rescue Gitlab::TaskFailedError
run_command!(%W[#{Gitlab.config.git.bin_path} -C #{target_dir} fetch origin])
run_command!(%W[#{Gitlab.config.git.bin_path} -C #{target_dir} describe -- origin/#{tag_wanted}])
end
if tag
run_command!(%W[#{Gitlab.config.git.bin_path} -C #{target_dir} reset --hard #{tag.strip}])
......
......@@ -2,15 +2,15 @@ namespace :gitlab do
desc "GitLab | Run all tests"
task :test do
cmds = [
%W(rake brakeman),
%W(rake rubocop),
%W(rake spinach),
%W(rake spec),
%W(rake karma)
%w(rake brakeman),
%w(rake rubocop),
%w(rake spinach),
%w(rake spec),
%w(rake karma)
]
cmds.each do |cmd|
system({'RAILS_ENV' => 'test', 'force' => 'yes'}, *cmd) or raise("#{cmd} failed!")
system({ 'RAILS_ENV' => 'test', 'force' => 'yes' }, *cmd) || raise("#{cmd} failed!")
end
end
end
namespace :gitlab do
desc 'GitLab | Tracks a deployment in GitLab Performance Monitoring'
task track_deployment: :environment do
metric = Gitlab::Metrics::Metric.
new('deployments', version: Gitlab::VERSION)
metric = Gitlab::Metrics::Metric
.new('deployments', version: Gitlab::VERSION)
Gitlab::Metrics.submit_metrics([metric.to_hash])
end
......
......@@ -46,7 +46,7 @@ namespace :gitlab do
"https://gitlab.com/gitlab-org/gitlab-ci-yml.git",
/(\.{1,2}|LICENSE|Pages|autodeploy|\.gitlab-ci.yml)\z/
)
]
].freeze
def vendor_directory
Rails.root.join('vendor')
......
namespace :gitlab do
namespace :web_hook do
desc "GitLab | Adds a webhook to the projects"
task :add => :environment do
task add: :environment do
web_hook_url = ENV['URL']
namespace_path = ENV['NAMESPACE']
......@@ -21,7 +21,7 @@ namespace :gitlab do
end
desc "GitLab | Remove a webhook from the projects"
task :rm => :environment do
task rm: :environment do
web_hook_url = ENV['URL']
namespace_path = ENV['NAMESPACE']
......@@ -34,7 +34,7 @@ namespace :gitlab do
end
desc "GitLab | List webhooks"
task :list => :environment do
task list: :environment do
namespace_path = ENV['NAMESPACE']
projects = find_projects(namespace_path)
......
......@@ -6,4 +6,3 @@ unless Rails.env.production?
end
end
end
......@@ -24,7 +24,7 @@ task migrate_iids: :environment do
else
print 'F'
end
rescue => ex
rescue
print 'F'
end
end
......
......@@ -76,23 +76,23 @@ namespace :services do
end
param_hash
end.sort_by { |p| p[:required] ? 0 : 1 }
end
service_hash[:params].sort_by! { |p| p[:required] ? 0 : 1 }
puts "Collected data for: #{service.title}, #{Time.now-service_start}"
puts "Collected data for: #{service.title}, #{Time.now - service_start}"
service_hash
end
doc_start = Time.now
doc_path = File.join(Rails.root, 'doc', 'api', 'services.md')
result = ERB.new(services_template, 0 , '>')
result = ERB.new(services_template, 0, '>')
.result(OpenStruct.new(services: services).instance_eval { binding })
File.open(doc_path, 'w') do |f|
f.write result
end
puts "write a new service.md to: #{doc_path.to_s}, #{Time.now-doc_start}"
puts "write a new service.md to: #{doc_path}, #{Time.now - doc_start}"
end
end
namespace :sidekiq do
desc "GitLab | Stop sidekiq"
task :stop do
system *%W(bin/background_jobs stop)
system(*%w(bin/background_jobs stop))
end
desc "GitLab | Start sidekiq"
task :start do
system *%W(bin/background_jobs start)
system(*%w(bin/background_jobs start))
end
desc 'GitLab | Restart sidekiq'
task :restart do
system *%W(bin/background_jobs restart)
system(*%w(bin/background_jobs restart))
end
desc "GitLab | Start sidekiq with launchd on Mac OS X"
task :launchd do
system *%W(bin/background_jobs start_no_deamonize)
system(*%w(bin/background_jobs start_no_deamonize))
end
end
......@@ -4,8 +4,8 @@ namespace :spec do
desc 'GitLab | Rspec | Run request specs'
task :api do
cmds = [
%W(rake gitlab:setup),
%W(rspec spec --tag @api)
%w(rake gitlab:setup),
%w(rspec spec --tag @api)
]
run_commands(cmds)
end
......@@ -13,8 +13,8 @@ namespace :spec do
desc 'GitLab | Rspec | Run feature specs'
task :feature do
cmds = [
%W(rake gitlab:setup),
%W(rspec spec --tag @feature)
%w(rake gitlab:setup),
%w(rspec spec --tag @feature)
]
run_commands(cmds)
end
......@@ -22,8 +22,8 @@ namespace :spec do
desc 'GitLab | Rspec | Run model specs'
task :models do
cmds = [
%W(rake gitlab:setup),
%W(rspec spec --tag @models)
%w(rake gitlab:setup),
%w(rspec spec --tag @models)
]
run_commands(cmds)
end
......@@ -31,8 +31,8 @@ namespace :spec do
desc 'GitLab | Rspec | Run service specs'
task :services do
cmds = [
%W(rake gitlab:setup),
%W(rspec spec --tag @services)
%w(rake gitlab:setup),
%w(rspec spec --tag @services)
]
run_commands(cmds)
end
......@@ -40,8 +40,8 @@ namespace :spec do
desc 'GitLab | Rspec | Run lib specs'
task :lib do
cmds = [
%W(rake gitlab:setup),
%W(rspec spec --tag @lib)
%w(rake gitlab:setup),
%w(rspec spec --tag @lib)
]
run_commands(cmds)
end
......@@ -49,8 +49,8 @@ namespace :spec do
desc 'GitLab | Rspec | Run other specs'
task :other do
cmds = [
%W(rake gitlab:setup),
%W(rspec spec --tag ~@api --tag ~@feature --tag ~@models --tag ~@lib --tag ~@services)
%w(rake gitlab:setup),
%w(rspec spec --tag ~@api --tag ~@feature --tag ~@models --tag ~@lib --tag ~@services)
]
run_commands(cmds)
end
......@@ -59,14 +59,14 @@ end
desc "GitLab | Run specs"
task :spec do
cmds = [
%W(rake gitlab:setup),
%W(rspec spec),
%w(rake gitlab:setup),
%w(rspec spec),
]
run_commands(cmds)
end
def run_commands(cmds)
cmds.each do |cmd|
system({'RAILS_ENV' => 'test', 'force' => 'yes'}, *cmd) or raise("#{cmd} failed!")
system({ 'RAILS_ENV' => 'test', 'force' => 'yes' }, *cmd) || raise("#{cmd} failed!")
end
end
......@@ -35,7 +35,7 @@ task :spinach do
end
def run_system_command(cmd)
system({'RAILS_ENV' => 'test', 'force' => 'yes'}, *cmd)
system({ 'RAILS_ENV' => 'test', 'force' => 'yes' }, *cmd)
end
def run_spinach_command(args)
......
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