Commit 903946c7 authored by Connor Shea's avatar Connor Shea

Replace colorize gem with rainbow.

Colorize is a gem licensed under the GPLv2, so we can’t use it in GitLab without relicensing GitLab under the terms of the GPL. Rainbow is licensed under the MIT license and does the exact same thing as Colorize, so Rainbow was added in place of Colorize.

The syntax is slightly different for Rainbow vs. Colorize, and was updated in accordance.

The gem is still a dependency of Spinach, so it’s included in the development/test environments, but won’t be packaged with the actual product, and therefore doesn’t require we relicense the product.

An attempt at relicensing Colorize was made, but didn’t succeed as the library owner never responded.

Rainbow library: https://github.com/sickill/rainbow
Relevant issue regarding licensing in GitLab's gems: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/3775
parent 8e7e3be5
......@@ -143,7 +143,7 @@ gem 'redis-namespace'
gem "httparty", '~> 0.13.3'
# Colored output to console
gem "colorize", '~> 0.7.0'
gem "rainbow", '~> 2.1.0'
# GitLab settings
gem 'settingslogic', '~> 2.0.9'
......
......@@ -823,7 +823,6 @@ DEPENDENCIES
carrierwave (~> 0.10.0)
charlock_holmes (~> 0.7.3)
coffee-rails (~> 4.1.0)
colorize (~> 0.7.0)
connection_pool (~> 2.0)
coveralls (~> 0.8.2)
creole (~> 0.5.0)
......@@ -914,6 +913,7 @@ DEPENDENCIES
rack-oauth2 (~> 1.2.1)
rails (= 4.2.6)
rails-deprecated_sanitizer (~> 1.0.3)
rainbow (~> 2.1.0)
raphael-rails (~> 2.1.2)
rblineprof
rdoc (~> 3.6)
......
......@@ -86,9 +86,9 @@ module Backup
def report_success(success)
if success
$progress.puts '[DONE]'.green
$progress.puts '[DONE]'.color(:green)
else
$progress.puts '[FAILED]'.red
$progress.puts '[FAILED]'.color(:red)
end
end
end
......
......@@ -27,9 +27,9 @@ module Backup
# Set file permissions on open to prevent chmod races.
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".green
$progress.puts "done".color(:green)
else
puts "creating archive #{tar_file} failed".red
puts "creating archive #{tar_file} failed".color(:red)
abort 'Backup failed'
end
......@@ -43,7 +43,7 @@ module Backup
connection_settings = Gitlab.config.backup.upload.connection
if connection_settings.blank?
$progress.puts "skipped".yellow
$progress.puts "skipped".color(:yellow)
return
end
......@@ -53,9 +53,9 @@ module Backup
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)
$progress.puts "done".green
$progress.puts "done".color(:green)
else
puts "uploading backup to #{remote_directory} failed".red
puts "uploading backup to #{remote_directory} failed".color(:red)
abort 'Backup failed'
end
end
......@@ -67,9 +67,9 @@ module Backup
next unless File.exist?(File.join(Gitlab.config.backup.path, dir))
if FileUtils.rm_rf(File.join(Gitlab.config.backup.path, dir))
$progress.puts "done".green
$progress.puts "done".color(:green)
else
puts "deleting tmp directory '#{dir}' failed".red
puts "deleting tmp directory '#{dir}' failed".color(:red)
abort 'Backup failed'
end
end
......@@ -95,9 +95,9 @@ module Backup
end
end
$progress.puts "done. (#{removed} removed)".green
$progress.puts "done. (#{removed} removed)".color(:green)
else
$progress.puts "skipping".yellow
$progress.puts "skipping".color(:yellow)
end
end
......@@ -124,20 +124,20 @@ module Backup
$progress.print "Unpacking backup ... "
unless Kernel.system(*%W(tar -xf #{tar_file}))
puts "unpacking backup failed".red
puts "unpacking backup failed".color(:red)
exit 1
else
$progress.puts "done".green
$progress.puts "done".color(:green)
end
ENV["VERSION"] = "#{settings[:db_version]}" if settings[:db_version].to_i > 0
# restoring mismatching backups can lead to unexpected problems
if settings[:gitlab_version] != Gitlab::VERSION
puts "GitLab version mismatch:".red
puts " Your current GitLab version (#{Gitlab::VERSION}) differs from the GitLab version in the backup!".red
puts " Please switch to the following version and try again:".red
puts " version: #{settings[:gitlab_version]}".red
puts "GitLab version mismatch:".color(:red)
puts " Your current GitLab version (#{Gitlab::VERSION}) differs from the GitLab version in the backup!".color(:red)
puts " Please switch to the following version and try again:".color(:red)
puts " version: #{settings[:gitlab_version]}".color(:red)
puts
puts "Hint: git checkout v#{settings[:gitlab_version]}"
exit 1
......
......@@ -14,14 +14,14 @@ module Backup
FileUtils.mkdir_p(File.join(backup_repos_path, project.namespace.path)) if project.namespace
if project.empty_repo?
$progress.puts "[SKIPPED]".cyan
$progress.puts "[SKIPPED]".color(:cyan)
else
cmd = %W(tar -cf #{path_to_bundle(project)} -C #{path_to_repo(project)} .)
output, status = Gitlab::Popen.popen(cmd)
if status.zero?
$progress.puts "[DONE]".green
$progress.puts "[DONE]".color(:green)
else
puts "[FAILED]".red
puts "[FAILED]".color(:red)
puts "failed: #{cmd.join(' ')}"
puts output
abort 'Backup failed'
......@@ -33,14 +33,14 @@ module Backup
if File.exists?(path_to_repo(wiki))
$progress.print " * #{wiki.path_with_namespace} ... "
if wiki.repository.empty?
$progress.puts " [SKIPPED]".cyan
$progress.puts " [SKIPPED]".color(:cyan)
else
cmd = %W(#{Gitlab.config.git.bin_path} --git-dir=#{path_to_repo(wiki)} bundle create #{path_to_bundle(wiki)} --all)
output, status = Gitlab::Popen.popen(cmd)
if status.zero?
$progress.puts " [DONE]".green
$progress.puts " [DONE]".color(:green)
else
puts " [FAILED]".red
puts " [FAILED]".color(:red)
puts "failed: #{cmd.join(' ')}"
abort 'Backup failed'
end
......@@ -71,9 +71,9 @@ module Backup
end
if system(*cmd, silent)
$progress.puts "[DONE]".green
$progress.puts "[DONE]".color(:green)
else
puts "[FAILED]".red
puts "[FAILED]".color(:red)
puts "failed: #{cmd.join(' ')}"
abort 'Restore failed'
end
......@@ -90,21 +90,21 @@ module Backup
cmd = %W(#{Gitlab.config.git.bin_path} clone --bare #{path_to_bundle(wiki)} #{path_to_repo(wiki)})
if system(*cmd, silent)
$progress.puts " [DONE]".green
$progress.puts " [DONE]".color(:green)
else
puts " [FAILED]".red
puts " [FAILED]".color(:red)
puts "failed: #{cmd.join(' ')}"
abort 'Restore failed'
end
end
end
$progress.print 'Put GitLab hooks in repositories dirs'.yellow
$progress.print 'Put GitLab hooks in repositories dirs'.color(:yellow)
cmd = "#{Gitlab.config.gitlab_shell.path}/bin/create-hooks"
if system(cmd)
$progress.puts " [DONE]".green
$progress.puts " [DONE]".color(:green)
else
puts " [FAILED]".red
puts " [FAILED]".color(:red)
puts "failed: #{cmd}"
end
......
......@@ -5,7 +5,7 @@ module Gitlab
SeedFu.quiet = true
yield
SeedFu.quiet = false
puts "\nOK".green
puts "\nOK".color(:green)
end
def self.by_user(user)
......
......@@ -40,14 +40,14 @@ namespace :gitlab do
removed.
MSG
ask_to_continue
puts 'Removing all tables. Press `Ctrl-C` within 5 seconds to abort'.yellow
puts 'Removing all tables. Press `Ctrl-C` within 5 seconds to abort'.color(:yellow)
sleep(5)
end
# Drop all tables Load the schema to ensure we don't have any newer tables
# hanging out from a failed upgrade
$progress.puts 'Cleaning the database ... '.blue
$progress.puts 'Cleaning the database ... '.color(:blue)
Rake::Task['gitlab:db:drop_tables'].invoke
$progress.puts 'done'.green
$progress.puts 'done'.color(:green)
Rake::Task['gitlab:backup:db:restore'].invoke
end
Rake::Task['gitlab:backup:repo:restore'].invoke unless backup.skipped?('repositories')
......@@ -63,141 +63,141 @@ namespace :gitlab do
namespace :repo do
task create: :environment do
$progress.puts "Dumping repositories ...".blue
$progress.puts "Dumping repositories ...".color(:blue)
if ENV["SKIP"] && ENV["SKIP"].include?("repositories")
$progress.puts "[SKIPPED]".cyan
$progress.puts "[SKIPPED]".color(:cyan)
else
Backup::Repository.new.dump
$progress.puts "done".green
$progress.puts "done".color(:green)
end
end
task restore: :environment do
$progress.puts "Restoring repositories ...".blue
$progress.puts "Restoring repositories ...".color(:blue)
Backup::Repository.new.restore
$progress.puts "done".green
$progress.puts "done".color(:green)
end
end
namespace :db do
task create: :environment do
$progress.puts "Dumping database ... ".blue
$progress.puts "Dumping database ... ".color(:blue)
if ENV["SKIP"] && ENV["SKIP"].include?("db")
$progress.puts "[SKIPPED]".cyan
$progress.puts "[SKIPPED]".color(:cyan)
else
Backup::Database.new.dump
$progress.puts "done".green
$progress.puts "done".color(:green)
end
end
task restore: :environment do
$progress.puts "Restoring database ... ".blue
$progress.puts "Restoring database ... ".color(:blue)
Backup::Database.new.restore
$progress.puts "done".green
$progress.puts "done".color(:green)
end
end
namespace :builds do
task create: :environment do
$progress.puts "Dumping builds ... ".blue
$progress.puts "Dumping builds ... ".color(:blue)
if ENV["SKIP"] && ENV["SKIP"].include?("builds")
$progress.puts "[SKIPPED]".cyan
$progress.puts "[SKIPPED]".color(:cyan)
else
Backup::Builds.new.dump
$progress.puts "done".green
$progress.puts "done".color(:green)
end
end
task restore: :environment do
$progress.puts "Restoring builds ... ".blue
$progress.puts "Restoring builds ... ".color(:blue)
Backup::Builds.new.restore
$progress.puts "done".green
$progress.puts "done".color(:green)
end
end
namespace :uploads do
task create: :environment do
$progress.puts "Dumping uploads ... ".blue
$progress.puts "Dumping uploads ... ".color(:blue)
if ENV["SKIP"] && ENV["SKIP"].include?("uploads")
$progress.puts "[SKIPPED]".cyan
$progress.puts "[SKIPPED]".color(:cyan)
else
Backup::Uploads.new.dump
$progress.puts "done".green
$progress.puts "done".color(:green)
end
end
task restore: :environment do
$progress.puts "Restoring uploads ... ".blue
$progress.puts "Restoring uploads ... ".color(:blue)
Backup::Uploads.new.restore
$progress.puts "done".green
$progress.puts "done".color(:green)
end
end
namespace :artifacts do
task create: :environment do
$progress.puts "Dumping artifacts ... ".blue
$progress.puts "Dumping artifacts ... ".color(:blue)
if ENV["SKIP"] && ENV["SKIP"].include?("artifacts")
$progress.puts "[SKIPPED]".cyan
$progress.puts "[SKIPPED]".color(:cyan)
else
Backup::Artifacts.new.dump
$progress.puts "done".green
$progress.puts "done".color(:green)
end
end
task restore: :environment do
$progress.puts "Restoring artifacts ... ".blue
$progress.puts "Restoring artifacts ... ".color(:blue)
Backup::Artifacts.new.restore
$progress.puts "done".green
$progress.puts "done".color(:green)
end
end
namespace :lfs do
task create: :environment do
$progress.puts "Dumping lfs objects ... ".blue
$progress.puts "Dumping lfs objects ... ".color(:blue)
if ENV["SKIP"] && ENV["SKIP"].include?("lfs")
$progress.puts "[SKIPPED]".cyan
$progress.puts "[SKIPPED]".color(:cyan)
else
Backup::Lfs.new.dump
$progress.puts "done".green
$progress.puts "done".color(:green)
end
end
task restore: :environment do
$progress.puts "Restoring lfs objects ... ".blue
$progress.puts "Restoring lfs objects ... ".color(:blue)
Backup::Lfs.new.restore
$progress.puts "done".green
$progress.puts "done".color(:green)
end
end
namespace :registry do
task create: :environment do
$progress.puts "Dumping container registry images ... ".blue
$progress.puts "Dumping container registry images ... ".color(:blue)
if Gitlab.config.registry.enabled
if ENV["SKIP"] && ENV["SKIP"].include?("registry")
$progress.puts "[SKIPPED]".cyan
$progress.puts "[SKIPPED]".color(:cyan)
else
Backup::Registry.new.dump
$progress.puts "done".green
$progress.puts "done".color(:green)
end
else
$progress.puts "[DISABLED]".cyan
$progress.puts "[DISABLED]".color(:cyan)
end
end
task restore: :environment do
$progress.puts "Restoring container registry images ... ".blue
$progress.puts "Restoring container registry images ... ".color(:blue)
if Gitlab.config.registry.enabled
Backup::Registry.new.restore
$progress.puts "done".green
$progress.puts "done".color(:green)
else
$progress.puts "[DISABLED]".cyan
$progress.puts "[DISABLED]".color(:cyan)
end
end
end
......
......@@ -50,14 +50,14 @@ namespace :gitlab do
end
if correct_options.all?
puts "yes".green
puts "yes".color(:green)
else
print "Trying to fix Git error automatically. ..."
if auto_fix_git_config(options)
puts "Success".green
puts "Success".color(:green)
else
puts "Failed".red
puts "Failed".color(:red)
try_fixing_it(
sudo_gitlab("\"#{Gitlab.config.git.bin_path}\" config --global core.autocrlf \"#{options["core.autocrlf"]}\"")
)
......@@ -74,9 +74,9 @@ namespace :gitlab do
database_config_file = Rails.root.join("config", "database.yml")
if File.exists?(database_config_file)
puts "yes".green
puts "yes".color(:green)
else
puts "no".red
puts "no".color(:red)
try_fixing_it(
"Copy config/database.yml.<your db> to config/database.yml",
"Check that the information in config/database.yml is correct"
......@@ -95,9 +95,9 @@ namespace :gitlab do
gitlab_config_file = Rails.root.join("config", "gitlab.yml")
if File.exists?(gitlab_config_file)
puts "yes".green
puts "yes".color(:green)
else
puts "no".red
puts "no".color(:red)
try_fixing_it(
"Copy config/gitlab.yml.example to config/gitlab.yml",
"Update config/gitlab.yml to match your setup"
......@@ -114,14 +114,14 @@ namespace :gitlab do
gitlab_config_file = Rails.root.join("config", "gitlab.yml")
unless File.exists?(gitlab_config_file)
puts "can't check because of previous errors".magenta
puts "can't check because of previous errors".color(:magenta)
end
# omniauth or ldap could have been deleted from the file
unless Gitlab.config['git_host']
puts "no".green
puts "no".color(:green)
else
puts "yes".red
puts "yes".color(:red)
try_fixing_it(
"Backup your config/gitlab.yml",
"Copy config/gitlab.yml.example to config/gitlab.yml",
......@@ -138,16 +138,16 @@ namespace :gitlab do
print "Init script exists? ... "
if omnibus_gitlab?
puts 'skipped (omnibus-gitlab has no init script)'.magenta
puts 'skipped (omnibus-gitlab has no init script)'.color(:magenta)
return
end
script_path = "/etc/init.d/gitlab"
if File.exists?(script_path)
puts "yes".green
puts "yes".color(:green)
else
puts "no".red
puts "no".color(:red)
try_fixing_it(
"Install the init script"
)
......@@ -162,7 +162,7 @@ namespace :gitlab do
print "Init script up-to-date? ... "
if omnibus_gitlab?
puts 'skipped (omnibus-gitlab has no init script)'.magenta
puts 'skipped (omnibus-gitlab has no init script)'.color(:magenta)
return
end
......@@ -170,7 +170,7 @@ namespace :gitlab do
script_path = "/etc/init.d/gitlab"
unless File.exists?(script_path)
puts "can't check because of previous errors".magenta
puts "can't check because of previous errors".color(:magenta)
return
end
......@@ -178,9 +178,9 @@ namespace :gitlab do
script_content = File.read(script_path)
if recipe_content == script_content
puts "yes".green
puts "yes".color(:green)
else
puts "no".red
puts "no".color(:red)
try_fixing_it(
"Redownload the init script"
)
......@@ -197,9 +197,9 @@ namespace :gitlab do
migration_status, _ = Gitlab::Popen.popen(%W(bundle exec rake db:migrate:status))
unless migration_status =~ /down\s+\d{14}/
puts "yes".green
puts "yes".color(:green)
else
puts "no".red
puts "no".color(:red)
try_fixing_it(
sudo_gitlab("bundle exec rake db:migrate RAILS_ENV=production")
)
......@@ -210,13 +210,13 @@ namespace :gitlab do
def check_orphaned_group_members
print "Database contains orphaned GroupMembers? ... "
if GroupMember.where("user_id not in (select id from users)").count > 0
puts "yes".red
puts "yes".color(:red)
try_fixing_it(
"You can delete the orphaned records using something along the lines of:",
sudo_gitlab("bundle exec rails runner -e production 'GroupMember.where(\"user_id NOT IN (SELECT id FROM users)\").delete_all'")
)
else
puts "no".green
puts "no".color(:green)
end
end
......@@ -226,9 +226,9 @@ namespace :gitlab do
log_path = Rails.root.join("log")
if File.writable?(log_path)
puts "yes".green
puts "yes".color(:green)
else
puts "no".red
puts "no".color(:red)
try_fixing_it(
"sudo chown -R gitlab #{log_path}",
"sudo chmod -R u+rwX #{log_path}"
......@@ -246,9 +246,9 @@ namespace :gitlab do
tmp_path = Rails.root.join("tmp")
if File.writable?(tmp_path)
puts "yes".green
puts "yes".color(:green)
else
puts "no".red
puts "no".color(:red)
try_fixing_it(
"sudo chown -R gitlab #{tmp_path}",
"sudo chmod -R u+rwX #{tmp_path}"
......@@ -264,7 +264,7 @@ namespace :gitlab do
print "Uploads directory setup correctly? ... "
unless File.directory?(Rails.root.join('public/uploads'))
puts "no".red
puts "no".color(:red)
try_fixing_it(
"sudo -u #{gitlab_user} mkdir #{Rails.root}/public/uploads"
)
......@@ -280,16 +280,16 @@ namespace :gitlab do
if File.stat(upload_path).mode == 040700
unless Dir.exists?(upload_path_tmp)
puts 'skipped (no tmp uploads folder yet)'.magenta
puts 'skipped (no tmp uploads folder yet)'.color(:magenta)
return
end
# If tmp upload dir has incorrect permissions, assume others do as well
# Verify drwx------ permissions
if File.stat(upload_path_tmp).mode == 040700 && File.owned?(upload_path_tmp)
puts "yes".green
puts "yes".color(:green)
else
puts "no".red
puts "no".color(:red)
try_fixing_it(
"sudo chown -R #{gitlab_user} #{upload_path}",
"sudo find #{upload_path} -type f -exec chmod 0644 {} \\;",
......@@ -301,7 +301,7 @@ namespace :gitlab do
fix_and_rerun
end
else
puts "no".red
puts "no".color(:red)
try_fixing_it(
"sudo chmod 700 #{upload_path}"
)
......@@ -320,9 +320,9 @@ namespace :gitlab do
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))
puts "yes".green
puts "yes".color(:green)
else
puts "no".red
puts "no".color(:red)
try_fixing_it(
"Update your redis server to a version >= #{min_redis_version}"
)
......@@ -361,10 +361,10 @@ namespace :gitlab do
repo_base_path = Gitlab.config.gitlab_shell.repos_path
if File.exists?(repo_base_path)
puts "yes".green
puts "yes".color(:green)
else
puts "no".red
puts "#{repo_base_path} is missing".red
puts "no".color(:red)
puts "#{repo_base_path} is missing".color(:red)
try_fixing_it(
"This should have been created when setting up GitLab Shell.",
"Make sure it's set correctly in config/gitlab.yml",
......@@ -382,14 +382,14 @@ namespace :gitlab do
repo_base_path = Gitlab.config.gitlab_shell.repos_path
unless File.exists?(repo_base_path)
puts "can't check because of previous errors".magenta
puts "can't check because of previous errors".color(:magenta)
return
end
unless File.symlink?(repo_base_path)
puts "no".green
puts "no".color(:green)
else
puts "yes".red
puts "yes".color(:red)
try_fixing_it(
"Make sure it's set to the real directory in config/gitlab.yml"
)
......@@ -402,14 +402,14 @@ namespace :gitlab do
repo_base_path = Gitlab.config.gitlab_shell.repos_path
unless File.exists?(repo_base_path)
puts "can't check because of previous errors".magenta
puts "can't check because of previous errors".color(:magenta)
return
end
if File.stat(repo_base_path).mode.to_s(8).ends_with?("2770")
puts "yes".green
puts "yes".color(:green)
else
puts "no".red
puts "no".color(:red)
try_fixing_it(
"sudo chmod -R ug+rwX,o-rwx #{repo_base_path}",
"sudo chmod -R ug-s #{repo_base_path}",
......@@ -429,17 +429,17 @@ namespace :gitlab do
repo_base_path = Gitlab.config.gitlab_shell.repos_path
unless File.exists?(repo_base_path)
puts "can't check because of previous errors".magenta
puts "can't check because of previous errors".color(:magenta)
return
end
uid = uid_for(gitlab_shell_ssh_user)
gid = gid_for(gitlab_shell_owner_group)
if File.stat(repo_base_path).uid == uid && File.stat(repo_base_path).gid == gid
puts "yes".green
puts "yes".color(:green)
else
puts "no".red
puts " User id for #{gitlab_shell_ssh_user}: #{uid}. Groupd id for #{gitlab_shell_owner_group}: #{gid}".blue
puts "no".color(:red)
puts " User id for #{gitlab_shell_ssh_user}: #{uid}. Groupd id for #{gitlab_shell_owner_group}: #{gid}".color(:blue)
try_fixing_it(
"sudo chown -R #{gitlab_shell_ssh_user}:#{gitlab_shell_owner_group} #{repo_base_path}"
)
......@@ -456,7 +456,7 @@ namespace :gitlab do
gitlab_shell_hooks_path = Gitlab.config.gitlab_shell.hooks_path
unless Project.count > 0
puts "can't check, you have no projects".magenta
puts "can't check, you have no projects".color(:magenta)
return
end
puts ""
......@@ -466,12 +466,12 @@ namespace :gitlab do
project_hook_directory = File.join(project.repository.path_to_repo, "hooks")
if project.empty_repo?
puts "repository is empty".magenta
puts "repository is empty".color(:magenta)
elsif File.directory?(project_hook_directory) && File.directory?(gitlab_shell_hooks_path) &&
(File.realpath(project_hook_directory) == File.realpath(gitlab_shell_hooks_path))
puts 'ok'.green
puts 'ok'.color(:green)
else
puts "wrong or missing hooks".red
puts "wrong or missing hooks".color(:red)
try_fixing_it(
sudo_gitlab("#{File.join(gitlab_shell_path, 'bin/create-hooks')}"),
'Check the hooks_path in config/gitlab.yml',
......@@ -491,9 +491,9 @@ namespace :gitlab do
check_cmd = File.expand_path('bin/check', gitlab_shell_repo_base)
puts "Running #{check_cmd}"
if system(check_cmd, chdir: gitlab_shell_repo_base)
puts 'gitlab-shell self-check successful'.green
puts 'gitlab-shell self-check successful'.color(:green)
else
puts 'gitlab-shell self-check failed'.red
puts 'gitlab-shell self-check failed'.color(:red)
try_fixing_it(
'Make sure GitLab is running;',
'Check the gitlab-shell configuration file:',
......@@ -507,7 +507,7 @@ namespace :gitlab do
print "projects have namespace: ... "
unless Project.count > 0
puts "can't check, you have no projects".magenta
puts "can't check, you have no projects".color(:magenta)
return
end
puts ""
......@@ -516,9 +516,9 @@ namespace :gitlab do
print sanitized_message(project)
if project.namespace
puts "yes".green
puts "yes".color(:green)
else
puts "no".red
puts "no".color(:red)
try_fixing_it(
"Migrate global projects"
)
......@@ -576,9 +576,9 @@ namespace :gitlab do
print "Running? ... "
if sidekiq_process_count > 0
puts "yes".green
puts "yes".color(:green)
else
puts "no".red
puts "no".color(:red)
try_fixing_it(
sudo_gitlab("RAILS_ENV=production bin/background_jobs start")
)
......@@ -596,9 +596,9 @@ namespace :gitlab do
print 'Number of Sidekiq processes ... '
if process_count == 1
puts '1'.green
puts '1'.color(:green)
else
puts "#{process_count}".red
puts "#{process_count}".color(:red)
try_fixing_it(
'sudo service gitlab stop',
"sudo pkill -u #{gitlab_user} -f sidekiq",
......@@ -646,16 +646,16 @@ namespace :gitlab do
print "Init.d configured correctly? ... "
if omnibus_gitlab?
puts 'skipped (omnibus-gitlab has no init script)'.magenta
puts 'skipped (omnibus-gitlab has no init script)'.color(:magenta)
return
end
path = "/etc/default/gitlab"
if File.exist?(path) && File.read(path).include?("mail_room_enabled=true")
puts "yes".green
puts "yes".color(:green)
else
puts "no".red
puts "no".color(:red)
try_fixing_it(
"Enable mail_room in the init.d configuration."
)
......@@ -672,9 +672,9 @@ namespace :gitlab do
path = Rails.root.join("Procfile")
if File.exist?(path) && File.read(path) =~ /^mail_room:/
puts "yes".green
puts "yes".color(:green)
else
puts "no".red
puts "no".color(:red)
try_fixing_it(
"Enable mail_room in your Procfile."
)
......@@ -691,14 +691,14 @@ namespace :gitlab do
path = "/etc/default/gitlab"
unless File.exist?(path) && File.read(path).include?("mail_room_enabled=true")
puts "can't check because of previous errors".magenta
puts "can't check because of previous errors".color(:magenta)
return
end
if mail_room_running?
puts "yes".green
puts "yes".color(:green)
else
puts "no".red
puts "no".color(:red)
try_fixing_it(
sudo_gitlab("RAILS_ENV=production bin/mail_room start")
)
......@@ -729,9 +729,9 @@ namespace :gitlab do
end
if connected
puts "yes".green
puts "yes".color(:green)
else
puts "no".red
puts "no".color(:red)
try_fixing_it(
"Check that the information in config/gitlab.yml is correct"
)
......@@ -799,7 +799,7 @@ namespace :gitlab do
namespace :user do
desc "GitLab | Check the integrity of a specific user's repositories"
task :check_repos, [:username] => :environment do |t, args|
username = args[:username] || prompt("Check repository integrity for which username? ".blue)
username = args[:username] || prompt("Check repository integrity for which username? ".color(:blue))
user = User.find_by(username: username)
if user
repo_dirs = user.authorized_projects.map do |p|
......@@ -811,7 +811,7 @@ namespace :gitlab do
repo_dirs.each { |repo_dir| check_repo_integrity(repo_dir) }
else
puts "\nUser '#{username}' not found".red
puts "\nUser '#{username}' not found".color(:red)
end
end
end
......@@ -820,13 +820,13 @@ namespace :gitlab do
##########################
def fix_and_rerun
puts " Please #{"fix the error above"} and rerun the checks.".red
puts " Please #{"fix the error above"} and rerun the checks.".color(:red)
end
def for_more_information(*sources)
sources = sources.shift if sources.first.is_a?(Array)
puts " For more information see:".blue
puts " For more information see:".color(:blue)
sources.each do |source|
puts " #{source}"
end
......@@ -834,7 +834,7 @@ namespace :gitlab do
def finished_checking(component)
puts ""
puts "Checking #{component.yellow} ... #{"Finished".green}"
puts "Checking #{component.color(:yellow)} ... #{"Finished".color(:green)}"
puts ""
end
......@@ -855,14 +855,14 @@ namespace :gitlab do
end
def start_checking(component)
puts "Checking #{component.yellow} ..."
puts "Checking #{component.color(:yellow)} ..."
puts ""
end
def try_fixing_it(*steps)
steps = steps.shift if steps.first.is_a?(Array)
puts " Try fixing it:".blue
puts " Try fixing it:".color(:blue)
steps.each do |step|
puts " #{step}"
end
......@@ -874,9 +874,9 @@ namespace :gitlab do
print "GitLab Shell version >= #{required_version} ? ... "
if current_version.valid? && required_version <= current_version
puts "OK (#{current_version})".green
puts "OK (#{current_version})".color(:green)
else
puts "FAIL. Please update gitlab-shell to #{required_version} from #{current_version}".red
puts "FAIL. Please update gitlab-shell to #{required_version} from #{current_version}".color(:red)
end
end
......@@ -887,9 +887,9 @@ namespace :gitlab do
print "Ruby version >= #{required_version} ? ... "
if current_version.valid? && required_version <= current_version
puts "yes (#{current_version})".green
puts "yes (#{current_version})".color(:green)
else
puts "no".red
puts "no".color(:red)
try_fixing_it(
"Update your ruby to a version >= #{required_version} from #{current_version}"
)
......@@ -905,9 +905,9 @@ namespace :gitlab do
print "Git version >= #{required_version} ? ... "
if current_version.valid? && required_version <= current_version
puts "yes (#{current_version})".green
puts "yes (#{current_version})".color(:green)
else
puts "no".red
puts "no".color(:red)
try_fixing_it(
"Update your git to a version >= #{required_version} from #{current_version}"
)
......@@ -925,9 +925,9 @@ namespace :gitlab do
def sanitized_message(project)
if should_sanitize?
"#{project.namespace_id.to_s.yellow}/#{project.id.to_s.yellow} ... "
"#{project.namespace_id.to_s.color(:yellow)}/#{project.id.to_s.color(:yellow)} ... "
else
"#{project.name_with_namespace.yellow} ... "
"#{project.name_with_namespace.color(:yellow)} ... "
end
end
......@@ -940,7 +940,7 @@ namespace :gitlab do
end
def check_repo_integrity(repo_dir)
puts "\nChecking repo at #{repo_dir.yellow}"
puts "\nChecking repo at #{repo_dir.color(:yellow)}"
git_fsck(repo_dir)
check_config_lock(repo_dir)
......@@ -948,25 +948,25 @@ namespace :gitlab do
end
def git_fsck(repo_dir)
puts "Running `git fsck`".yellow
puts "Running `git fsck`".color(:yellow)
system(*%W(#{Gitlab.config.git.bin_path} fsck), chdir: repo_dir)
end
def check_config_lock(repo_dir)
config_exists = File.exist?(File.join(repo_dir,'config.lock'))
config_output = config_exists ? 'yes'.red : 'no'.green
puts "'config.lock' file exists?".yellow + " ... #{config_output}"
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'))
if lock_files.present?
puts "Ref lock files exist:".red
puts "Ref lock files exist:".color(:red)
lock_files.each do |lock_file|
puts " #{lock_file}"
end
else
puts "No ref lock files exist".green
puts "No ref lock files exist".color(:green)
end
end
end
......@@ -10,7 +10,7 @@ namespace :gitlab do
git_base_path = Gitlab.config.gitlab_shell.repos_path
all_dirs = Dir.glob(git_base_path + '/*')
puts git_base_path.yellow
puts git_base_path.color(:yellow)
puts "Looking for directories to remove... "
all_dirs.reject! do |dir|
......@@ -29,17 +29,17 @@ namespace :gitlab do
if remove_flag
if FileUtils.rm_rf dir_path
puts "Removed...#{dir_path}".red
puts "Removed...#{dir_path}".color(:red)
else
puts "Cannot remove #{dir_path}".red
puts "Cannot remove #{dir_path}".color(:red)
end
else
puts "Can be removed: #{dir_path}".red
puts "Can be removed: #{dir_path}".color(:red)
end
end
unless remove_flag
puts "To cleanup this directories run this command with REMOVE=true".yellow
puts "To cleanup this directories run this command with REMOVE=true".color(:yellow)
end
end
......@@ -75,19 +75,19 @@ namespace :gitlab do
next unless user.ldap_user?
print "#{user.name} (#{user.ldap_identity.extern_uid}) ..."
if Gitlab::LDAP::Access.allowed?(user)
puts " [OK]".green
puts " [OK]".color(:green)
else
if block_flag
user.block! unless user.blocked?
puts " [BLOCKED]".red
puts " [BLOCKED]".color(:red)
else
puts " [NOT IN LDAP]".yellow
puts " [NOT IN LDAP]".color(:yellow)
end
end
end
unless block_flag
puts "To block these users run this command with BLOCK=true".yellow
puts "To block these users run this command with BLOCK=true".color(:yellow)
end
end
end
......
......@@ -3,22 +3,22 @@ namespace :gitlab do
desc 'GitLab | Manually insert schema migration version'
task :mark_migration_complete, [:version] => :environment do |_, args|
unless args[:version]
puts "Must specify a migration version as an argument".red
puts "Must specify a migration version as an argument".color(:red)
exit 1
end
version = args[:version].to_i
if version == 0
puts "Version '#{args[:version]}' must be a non-zero integer".red
puts "Version '#{args[:version]}' must be a non-zero integer".color(:red)
exit 1
end
sql = "INSERT INTO schema_migrations (version) VALUES (#{version})"
begin
ActiveRecord::Base.connection.execute(sql)
puts "Successfully marked '#{version}' as complete".green
puts "Successfully marked '#{version}' as complete".color(:green)
rescue ActiveRecord::RecordNotUnique
puts "Migration version '#{version}' is already marked complete".yellow
puts "Migration version '#{version}' is already marked complete".color(:yellow)
end
end
......
......@@ -5,7 +5,7 @@ namespace :gitlab do
task repack: :environment do
failures = perform_git_cmd(%W(git repack -a --quiet), "Repacking repo")
if failures.empty?
puts "Done".green
puts "Done".color(:green)
else
output_failures(failures)
end
......@@ -15,7 +15,7 @@ namespace :gitlab do
task gc: :environment do
failures = perform_git_cmd(%W(git gc --auto --quiet), "Garbage Collecting")
if failures.empty?
puts "Done".green
puts "Done".color(:green)
else
output_failures(failures)
end
......@@ -25,7 +25,7 @@ namespace :gitlab do
task prune: :environment do
failures = perform_git_cmd(%W(git prune), "Git Prune")
if failures.empty?
puts "Done".green
puts "Done".color(:green)
else
output_failures(failures)
end
......@@ -47,7 +47,7 @@ namespace :gitlab do
end
def output_failures(failures)
puts "The following repositories reported errors:".red
puts "The following repositories reported errors:".color(:red)
failures.each { |f| puts "- #{f}" }
end
......
......@@ -23,7 +23,7 @@ namespace :gitlab do
group_name, name = File.split(path)
group_name = nil if group_name == '.'
puts "Processing #{repo_path}".yellow
puts "Processing #{repo_path}".color(:yellow)
if path.end_with?('.wiki')
puts " * Skipping wiki repo"
......@@ -51,9 +51,9 @@ namespace :gitlab do
group.path = group_name
group.owner = user
if group.save
puts " * Created Group #{group.name} (#{group.id})".green
puts " * Created Group #{group.name} (#{group.id})".color(:green)
else
puts " * Failed trying to create group #{group.name}".red
puts " * Failed trying to create group #{group.name}".color(:red)
end
end
# set project group
......@@ -63,17 +63,17 @@ namespace :gitlab do
project = Projects::CreateService.new(user, project_params).execute
if project.persisted?
puts " * Created #{project.name} (#{repo_path})".green
puts " * Created #{project.name} (#{repo_path})".color(:green)
project.update_repository_size
project.update_commit_count
else
puts " * Failed trying to create #{project.name} (#{repo_path})".red
puts " Errors: #{project.errors.messages}".red
puts " * Failed trying to create #{project.name} (#{repo_path})".color(:red)
puts " Errors: #{project.errors.messages}".color(:red)
end
end
end
puts "Done!".green
puts "Done!".color(:green)
end
end
end
......@@ -15,15 +15,15 @@ namespace :gitlab do
rake_version = run_and_match(%W(rake --version), /[\d\.]+/).try(:to_s)
puts ""
puts "System information".yellow
puts "System:\t\t#{os_name || "unknown".red}"
puts "System information".color(:yellow)
puts "System:\t\t#{os_name || "unknown".color(:red)}"
puts "Current User:\t#{run(%W(whoami))}"
puts "Using RVM:\t#{rvm_version.present? ? "yes".green : "no"}"
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".red}"
puts "Gem Version:\t#{gem_version || "unknown".red}"
puts "Bundler Version:#{bunder_version || "unknown".red}"
puts "Rake Version:\t#{rake_version || "unknown".red}"
puts "Ruby Version:\t#{ruby_version || "unknown".color(:red)}"
puts "Gem Version:\t#{gem_version || "unknown".color(:red)}"
puts "Bundler Version:#{bunder_version || "unknown".color(:red)}"
puts "Rake Version:\t#{rake_version || "unknown".color(:red)}"
puts "Sidekiq Version:#{Sidekiq::VERSION}"
......@@ -39,7 +39,7 @@ namespace :gitlab do
omniauth_providers.map! { |provider| provider['name'] }
puts ""
puts "GitLab information".yellow
puts "GitLab information".color(:yellow)
puts "Version:\t#{Gitlab::VERSION}"
puts "Revision:\t#{Gitlab::REVISION}"
puts "Directory:\t#{Rails.root}"
......@@ -47,9 +47,9 @@ namespace :gitlab do
puts "URL:\t\t#{Gitlab.config.gitlab.url}"
puts "HTTP Clone URL:\t#{http_clone_url}"
puts "SSH Clone URL:\t#{ssh_clone_url}"
puts "Using LDAP:\t#{Gitlab.config.ldap.enabled ? "yes".green : "no"}"
puts "Using Omniauth:\t#{Gitlab.config.omniauth.enabled ? "yes".green : "no"}"
puts "Omniauth Providers: #{omniauth_providers.map(&:magenta).join(', ')}" if Gitlab.config.omniauth.enabled
puts "Using LDAP:\t#{Gitlab.config.ldap.enabled ? "yes".color(:green) : "no"}"
puts "Using Omniauth:\t#{Gitlab.config.omniauth.enabled ? "yes".color(:green) : "no"}"
puts "Omniauth Providers: #{omniauth_providers.join(', ')}" if Gitlab.config.omniauth.enabled
......@@ -60,8 +60,8 @@ namespace :gitlab do
end
puts ""
puts "GitLab Shell".yellow
puts "Version:\t#{gitlab_shell_version || "unknown".red}"
puts "GitLab Shell".color(:yellow)
puts "Version:\t#{gitlab_shell_version || "unknown".color(:red)}"
puts "Repositories:\t#{Gitlab.config.gitlab_shell.repos_path}"
puts "Hooks:\t\t#{Gitlab.config.gitlab_shell.hooks_path}"
puts "Git:\t\t#{Gitlab.config.git.bin_path}"
......
......@@ -118,12 +118,12 @@ namespace :gitlab do
puts ""
unless $?.success?
puts "Failed to add keys...".red
puts "Failed to add keys...".color(:red)
exit 1
end
rescue Gitlab::TaskAbortedByUserError
puts "Quitting...".red
puts "Quitting...".color(:red)
exit 1
end
......
......@@ -2,7 +2,7 @@ module Gitlab
class TaskAbortedByUserError < StandardError; end
end
String.disable_colorization = true unless STDOUT.isatty
require 'rainbow/ext/string'
# Prevent StateMachine warnings from outputting during a cron task
StateMachines::Machine.ignore_method_conflicts = true if ENV['CRON']
......@@ -14,7 +14,7 @@ namespace :gitlab do
# Returns "yes" the user chose to continue
# Raises Gitlab::TaskAbortedByUserError if the user chose *not* to continue
def ask_to_continue
answer = prompt("Do you want to continue (yes/no)? ".blue, %w{yes no})
answer = prompt("Do you want to continue (yes/no)? ".color(:blue), %w{yes no})
raise Gitlab::TaskAbortedByUserError unless answer == "yes"
end
......@@ -98,10 +98,10 @@ namespace :gitlab do
gitlab_user = Gitlab.config.gitlab.user
current_user = run(%W(whoami)).chomp
unless current_user == gitlab_user
puts " Warning ".colorize(:black).on_yellow
puts " You are running as user #{current_user.magenta}, we hope you know what you are doing."
puts " Warning ".color(:black).background(:yellow)
puts " You are running as user #{current_user.color(:magenta)}, we hope you know what you are doing."
puts " Things may work\/fail for the wrong reasons."
puts " For correct results you should run this as user #{gitlab_user.magenta}."
puts " For correct results you should run this as user #{gitlab_user.color(:magenta)}."
puts ""
end
@warned_user_not_gitlab = true
......
......@@ -6,17 +6,17 @@ namespace :gitlab do
count = scope.count
if count > 0
puts "This will disable 2FA for #{count.to_s.red} users..."
puts "This will disable 2FA for #{count.to_s.color(:red)} users..."
begin
ask_to_continue
scope.find_each(&:disable_two_factor!)
puts "Successfully disabled 2FA for #{count} users.".green
puts "Successfully disabled 2FA for #{count} users.".color(:green)
rescue Gitlab::TaskAbortedByUserError
puts "Quitting...".red
puts "Quitting...".color(:red)
end
else
puts "There are currently no users with 2FA enabled.".yellow
puts "There are currently no users with 2FA enabled.".color(:yellow)
end
end
end
......
......@@ -6,15 +6,15 @@ namespace :gitlab do
ask_to_continue unless ENV['force'] == 'yes'
projects.find_each(batch_size: 100) do |project|
print "#{project.name_with_namespace.yellow} ... "
print "#{project.name_with_namespace.color(:yellow)} ... "
unless project.repo_exists?
puts "skipping, because the repo is empty".magenta
puts "skipping, because the repo is empty".color(:magenta)
next
end
project.update_commit_count
puts project.commit_count.to_s.green
puts project.commit_count.to_s.color(:green)
end
end
end
......@@ -2,14 +2,14 @@ namespace :gitlab do
desc "GitLab | Update gitignore"
task :update_gitignore do
unless clone_gitignores
puts "Cloning the gitignores failed".red
puts "Cloning the gitignores failed".color(:red)
return
end
remove_unneeded_files(gitignore_directory)
remove_unneeded_files(global_directory)
puts "Done".green
puts "Done".color(:green)
end
def clone_gitignores
......
......@@ -12,9 +12,9 @@ namespace :gitlab do
print "- #{project.name} ... "
web_hook = project.hooks.new(url: web_hook_url)
if web_hook.save
puts "added".green
puts "added".color(:green)
else
print "failed".red
print "failed".color(:red)
puts " [#{web_hook.errors.full_messages.to_sentence}]"
end
end
......@@ -57,7 +57,7 @@ namespace :gitlab do
if namespace
Project.in_namespace(namespace.id)
else
puts "Namespace not found: #{namespace_path}".red
puts "Namespace not found: #{namespace_path}".color(:red)
exit 2
end
end
......
desc "GitLab | Build internal ids for issues and merge requests"
task migrate_iids: :environment do
puts 'Issues'.yellow
puts 'Issues'.color(:yellow)
Issue.where(iid: nil).find_each(batch_size: 100) do |issue|
begin
issue.set_iid
......@@ -15,7 +15,7 @@ task migrate_iids: :environment do
end
puts 'done'
puts 'Merge Requests'.yellow
puts 'Merge Requests'.color(:yellow)
MergeRequest.where(iid: nil).find_each(batch_size: 100) do |mr|
begin
mr.set_iid
......@@ -30,7 +30,7 @@ task migrate_iids: :environment do
end
puts 'done'
puts 'Milestones'.yellow
puts 'Milestones'.color(:yellow)
Milestone.where(iid: nil).find_each(batch_size: 100) do |m|
begin
m.set_iid
......
......@@ -52,7 +52,7 @@ def run_spinach_tests(tags)
tests = File.foreach('tmp/spinach-rerun.txt').map(&:chomp)
puts ''
puts "Spinach tests for #{tags}: Retrying tests... #{tests}".red
puts "Spinach tests for #{tags}: Retrying tests... #{tests}".color(:red)
puts ''
sleep(3)
success = run_spinach_command(tests)
......
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