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