Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tasks/gitlab')
-rw-r--r--lib/tasks/gitlab/backup.rake106
-rw-r--r--lib/tasks/gitlab/bulk_add_permission.rake48
-rw-r--r--lib/tasks/gitlab/cleanup.rake113
-rw-r--r--lib/tasks/gitlab/db/drop_all_postgres_sequences.rake10
-rw-r--r--lib/tasks/gitlab/db/drop_all_tables.rake10
-rw-r--r--lib/tasks/gitlab/enable_automerge.rake39
-rw-r--r--lib/tasks/gitlab/generate_docs.rake7
-rw-r--r--lib/tasks/gitlab/import.rake77
-rw-r--r--lib/tasks/gitlab/info.rake72
-rw-r--r--lib/tasks/gitlab/mail_google_schema_whitelisting.rake73
-rw-r--r--lib/tasks/gitlab/setup.rake24
-rw-r--r--lib/tasks/gitlab/shell.rake138
-rw-r--r--lib/tasks/gitlab/sidekiq.rake47
-rw-r--r--lib/tasks/gitlab/task_helpers.rake131
-rw-r--r--lib/tasks/gitlab/test.rake16
-rw-r--r--lib/tasks/gitlab/web_hook.rake65
16 files changed, 0 insertions, 976 deletions
diff --git a/lib/tasks/gitlab/backup.rake b/lib/tasks/gitlab/backup.rake
deleted file mode 100644
index 84445b3bf2f..00000000000
--- a/lib/tasks/gitlab/backup.rake
+++ /dev/null
@@ -1,106 +0,0 @@
-require 'active_record/fixtures'
-
-namespace :gitlab do
- namespace :backup do
- # Create backup of GitLab system
- desc "GITLAB | Create a backup of the GitLab system"
- task create: :environment do
- warn_user_is_not_gitlab
- configure_cron_mode
-
- Rake::Task["gitlab:backup:db:create"].invoke
- Rake::Task["gitlab:backup:repo:create"].invoke
- Rake::Task["gitlab:backup:uploads:create"].invoke
-
- backup = Backup::Manager.new
- backup.pack
- backup.cleanup
- backup.remove_old
- end
-
- # Restore backup of GitLab system
- desc "GITLAB | Restore a previously created backup"
- task restore: :environment do
- warn_user_is_not_gitlab
- configure_cron_mode
-
- backup = Backup::Manager.new
- backup.unpack
-
- Rake::Task["gitlab:backup:db:restore"].invoke unless backup.skipped?("db")
- Rake::Task["gitlab:backup:repo:restore"].invoke unless backup.skipped?("repositories")
- Rake::Task["gitlab:backup:uploads:restore"].invoke unless backup.skipped?("uploads")
- Rake::Task["gitlab:shell:setup"].invoke
-
- backup.cleanup
- end
-
- namespace :repo do
- task create: :environment do
- $progress.puts "Dumping repositories ...".blue
-
- if ENV["SKIP"] && ENV["SKIP"].include?("repositories")
- $progress.puts "[SKIPPED]".cyan
- else
- Backup::Repository.new.dump
- $progress.puts "done".green
- end
- end
-
- task restore: :environment do
- $progress.puts "Restoring repositories ...".blue
- Backup::Repository.new.restore
- $progress.puts "done".green
- end
- end
-
- namespace :db do
- task create: :environment do
- $progress.puts "Dumping database ... ".blue
-
- if ENV["SKIP"] && ENV["SKIP"].include?("db")
- $progress.puts "[SKIPPED]".cyan
- else
- Backup::Database.new.dump
- $progress.puts "done".green
- end
- end
-
- task restore: :environment do
- $progress.puts "Restoring database ... ".blue
- Backup::Database.new.restore
- $progress.puts "done".green
- end
- end
-
- namespace :uploads do
- task create: :environment do
- $progress.puts "Dumping uploads ... ".blue
-
- if ENV["SKIP"] && ENV["SKIP"].include?("uploads")
- $progress.puts "[SKIPPED]".cyan
- else
- Backup::Uploads.new.dump
- $progress.puts "done".green
- end
- end
-
- task restore: :environment do
- $progress.puts "Restoring uploads ... ".blue
- Backup::Uploads.new.restore
- $progress.puts "done".green
- end
- end
-
- def configure_cron_mode
- if ENV['CRON']
- # We need an object we can say 'puts' and 'print' to; let's use a
- # StringIO.
- require 'stringio'
- $progress = StringIO.new
- else
- $progress = $stdout
- end
- end
- end # namespace end: backup
-end # namespace end: gitlab
diff --git a/lib/tasks/gitlab/bulk_add_permission.rake b/lib/tasks/gitlab/bulk_add_permission.rake
deleted file mode 100644
index 3d8c171dfa3..00000000000
--- a/lib/tasks/gitlab/bulk_add_permission.rake
+++ /dev/null
@@ -1,48 +0,0 @@
-namespace :gitlab do
- namespace :import do
- desc "GITLAB | Add all users to all projects (admin users are added as masters)"
- task all_users_to_all_projects: :environment do |t, args|
- user_ids = User.where(admin: false).pluck(:id)
- admin_ids = User.where(admin: true).pluck(:id)
- projects_ids = Project.pluck(:id)
-
- puts "Importing #{user_ids.size} users into #{projects_ids.size} projects"
- ProjectMember.add_users_into_projects(projects_ids, user_ids, ProjectMember::DEVELOPER)
-
- puts "Importing #{admin_ids.size} admins into #{projects_ids.size} projects"
- ProjectMember.add_users_into_projects(projects_ids, admin_ids, ProjectMember::MASTER)
- end
-
- desc "GITLAB | Add a specific user to all projects (as a developer)"
- task :user_to_projects, [:email] => :environment do |t, args|
- user = User.find_by(email: args.email)
- project_ids = Project.pluck(:id)
- puts "Importing #{user.email} users into #{project_ids.size} projects"
- ProjectMember.add_users_into_projects(project_ids, Array.wrap(user.id), ProjectMember::DEVELOPER)
- end
-
- desc "GITLAB | Add all users to all groups (admin users are added as owners)"
- task all_users_to_all_groups: :environment do |t, args|
- user_ids = User.where(admin: false).pluck(:id)
- admin_ids = User.where(admin: true).pluck(:id)
- groups = Group.all
-
- puts "Importing #{user_ids.size} users into #{groups.size} groups"
- puts "Importing #{admin_ids.size} admins into #{groups.size} groups"
- groups.each do |group|
- group.add_users(user_ids, GroupMember::DEVELOPER)
- group.add_users(admin_ids, GroupMember::OWNER)
- end
- end
-
- desc "GITLAB | Add a specific user to all groups (as a developer)"
- task :user_to_groups, [:email] => :environment do |t, args|
- user = User.find_by_email args.email
- groups = Group.all
- puts "Importing #{user.email} users into #{groups.size} groups"
- groups.each do |group|
- group.add_users(Array.wrap(user.id), GroupMember::DEVELOPER)
- end
- end
- end
-end
diff --git a/lib/tasks/gitlab/cleanup.rake b/lib/tasks/gitlab/cleanup.rake
deleted file mode 100644
index 3c9802a0be4..00000000000
--- a/lib/tasks/gitlab/cleanup.rake
+++ /dev/null
@@ -1,113 +0,0 @@
-namespace :gitlab do
- namespace :cleanup do
- desc "GITLAB | Cleanup | Clean namespaces"
- task dirs: :environment do
- warn_user_is_not_gitlab
- remove_flag = ENV['REMOVE']
-
-
- namespaces = Namespace.pluck(:path)
- git_base_path = Gitlab.config.gitlab_shell.repos_path
- all_dirs = Dir.glob(git_base_path + '/*')
-
- puts git_base_path.yellow
- puts "Looking for directories to remove... "
-
- all_dirs.reject! do |dir|
- # skip if git repo
- dir =~ /.git$/
- end
-
- all_dirs.reject! do |dir|
- dir_name = File.basename dir
-
- # skip if namespace present
- namespaces.include?(dir_name)
- end
-
- all_dirs.each do |dir_path|
-
- if remove_flag
- if FileUtils.rm_rf dir_path
- puts "Removed...#{dir_path}".red
- else
- puts "Cannot remove #{dir_path}".red
- end
- else
- puts "Can be removed: #{dir_path}".red
- end
- end
-
- unless remove_flag
- puts "To cleanup this directories run this command with REMOVE=true".yellow
- end
- end
-
- desc "GITLAB | Cleanup | Clean repositories"
- task repos: :environment do
- warn_user_is_not_gitlab
- remove_flag = ENV['REMOVE']
-
- git_base_path = Gitlab.config.gitlab_shell.repos_path
- all_dirs = Dir.glob(git_base_path + '/*')
-
- global_projects = Project.where(namespace_id: nil).pluck(:path)
-
- puts git_base_path.yellow
- puts "Looking for global repos to remove... "
-
- # skip non git repo
- all_dirs.select! do |dir|
- dir =~ /.git$/
- end
-
- # skip existing repos
- all_dirs.reject! do |dir|
- repo_name = File.basename dir
- path = repo_name.gsub(/\.git$/, "")
- global_projects.include?(path)
- end
-
- all_dirs.each do |dir_path|
- if remove_flag
- if FileUtils.rm_rf dir_path
- puts "Removed...#{dir_path}".red
- else
- puts "Cannot remove #{dir_path}".red
- end
- else
- puts "Can be removed: #{dir_path}".red
- end
- end
-
- unless remove_flag
- puts "To cleanup this directories run this command with REMOVE=true".yellow
- end
- end
-
- desc "GITLAB | Cleanup | Block users that have been removed in LDAP"
- task block_removed_ldap_users: :environment do
- warn_user_is_not_gitlab
- block_flag = ENV['BLOCK']
-
- User.find_each do |user|
- next unless user.ldap_user?
- print "#{user.name} (#{user.ldap_identity.extern_uid}) ..."
- if Gitlab::LDAP::Access.allowed?(user)
- puts " [OK]".green
- else
- if block_flag
- user.block! unless user.blocked?
- puts " [BLOCKED]".red
- else
- puts " [NOT IN LDAP]".yellow
- end
- end
- end
-
- unless block_flag
- puts "To block these users run this command with BLOCK=true".yellow
- end
- end
- end
-end
diff --git a/lib/tasks/gitlab/db/drop_all_postgres_sequences.rake b/lib/tasks/gitlab/db/drop_all_postgres_sequences.rake
deleted file mode 100644
index e9cf0a9b5e8..00000000000
--- a/lib/tasks/gitlab/db/drop_all_postgres_sequences.rake
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace :gitlab do
- namespace :db do
- task drop_all_postgres_sequences: :environment do
- connection = ActiveRecord::Base.connection
- connection.execute("SELECT c.relname FROM pg_class c WHERE c.relkind = 'S';").each do |sequence|
- connection.execute("DROP SEQUENCE #{sequence['relname']}")
- end
- end
- end
-end
diff --git a/lib/tasks/gitlab/db/drop_all_tables.rake b/lib/tasks/gitlab/db/drop_all_tables.rake
deleted file mode 100644
index a66030ab93a..00000000000
--- a/lib/tasks/gitlab/db/drop_all_tables.rake
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace :gitlab do
- namespace :db do
- task drop_all_tables: :environment do
- connection = ActiveRecord::Base.connection
- connection.tables.each do |table|
- connection.drop_table(table)
- end
- end
- end
-end
diff --git a/lib/tasks/gitlab/enable_automerge.rake b/lib/tasks/gitlab/enable_automerge.rake
deleted file mode 100644
index aa9869daf2f..00000000000
--- a/lib/tasks/gitlab/enable_automerge.rake
+++ /dev/null
@@ -1,39 +0,0 @@
-namespace :gitlab do
- namespace :satellites do
- desc "GITLAB | Create satellite repos"
- task create: :environment do
- create_satellites
- end
- end
-
- def create_satellites
- warn_user_is_not_gitlab
-
- print "Creating satellites for ..."
- unless Project.count > 0
- puts "skipping, because you have no projects".magenta
- return
- end
- puts ""
-
- Project.find_each(batch_size: 100) do |project|
- print "#{project.name_with_namespace.yellow} ... "
-
- unless project.repo_exists?
- puts "skipping, because the repo is empty".magenta
- next
- end
-
- if project.satellite.exists?
- puts "exists already".green
- else
- print "\n... "
- if project.satellite.create
- puts "created".green
- else
- puts "error".red
- end
- end
- end
- end
-end
diff --git a/lib/tasks/gitlab/generate_docs.rake b/lib/tasks/gitlab/generate_docs.rake
deleted file mode 100644
index 332cd61f84c..00000000000
--- a/lib/tasks/gitlab/generate_docs.rake
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace :gitlab do
- desc "GITLAB | Generate sdocs for project"
- task generate_docs: :environment do
- system(*%W(bundle exec sdoc -o doc/code app lib))
- end
-end
-
diff --git a/lib/tasks/gitlab/import.rake b/lib/tasks/gitlab/import.rake
deleted file mode 100644
index 20abb2fa500..00000000000
--- a/lib/tasks/gitlab/import.rake
+++ /dev/null
@@ -1,77 +0,0 @@
-namespace :gitlab do
- namespace :import do
- # How to use:
- #
- # 1. copy the bare repos under the repos_path (commonly /home/git/repositories)
- # 2. run: bundle exec rake gitlab:import:repos RAILS_ENV=production
- #
- # Notes:
- # * The project owner will set to the first administator of the system
- # * Existing projects will be skipped
- #
- desc "GITLAB | Import bare repositories from gitlab_shell -> repos_path into GitLab project instance"
- task repos: :environment do
-
- git_base_path = Gitlab.config.gitlab_shell.repos_path
- repos_to_import = Dir.glob(git_base_path + '/**/*.git')
-
- repos_to_import.each do |repo_path|
- # strip repo base path
- repo_path[0..git_base_path.length] = ''
-
- path = repo_path.sub(/\.git$/, '')
- group_name, name = File.split(path)
- group_name = nil if group_name == '.'
-
- puts "Processing #{repo_path}".yellow
-
- if path.end_with?('.wiki')
- puts " * Skipping wiki repo"
- next
- end
-
- project = Project.find_with_namespace(path)
-
- if project
- puts " * #{project.name} (#{repo_path}) exists"
- else
- user = User.admins.first
-
- project_params = {
- name: name,
- path: name
- }
-
- # find group namespace
- if group_name
- group = Namespace.find_by(path: group_name)
- # create group namespace
- unless group
- group = Group.new(:name => group_name)
- group.path = group_name
- group.owner = user
- if group.save
- puts " * Created Group #{group.name} (#{group.id})".green
- else
- puts " * Failed trying to create group #{group.name}".red
- end
- end
- # set project group
- project_params[:namespace_id] = group.id
- end
-
- project = Projects::CreateService.new(user, project_params).execute
-
- if project.valid?
- puts " * Created #{project.name} (#{repo_path})".green
- else
- puts " * Failed trying to create #{project.name} (#{repo_path})".red
- puts " Validation Errors: #{project.errors.messages}".red
- end
- end
- end
-
- puts "Done!".green
- end
- end
-end
diff --git a/lib/tasks/gitlab/info.rake b/lib/tasks/gitlab/info.rake
deleted file mode 100644
index 72452e1d8ea..00000000000
--- a/lib/tasks/gitlab/info.rake
+++ /dev/null
@@ -1,72 +0,0 @@
-namespace :gitlab do
- namespace :env do
- desc "GITLAB | Show information about GitLab and its environment"
- task info: :environment do
-
- # check if there is an RVM environment
- rvm_version = run_and_match(%W(rvm --version), /[\d\.]+/).try(:to_s)
- # check Ruby version
- ruby_version = run_and_match(%W(ruby --version), /[\d\.p]+/).try(:to_s)
- # check Gem version
- gem_version = run(%W(gem --version))
- # check Bundler version
- bunder_version = run_and_match(%W(bundle --version), /[\d\.]+/).try(:to_s)
- # check Bundler version
- 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 "Current User:\t#{run(%W(whoami))}"
- puts "Using RVM:\t#{rvm_version.present? ? "yes".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 "Sidekiq Version:#{Sidekiq::VERSION}"
-
-
- # check database adapter
- database_adapter = ActiveRecord::Base.connection.adapter_name.downcase
-
- project = Project.new(path: "some-project")
- project.path = "some-project"
- # construct clone URLs
- http_clone_url = project.http_url_to_repo
- ssh_clone_url = project.ssh_url_to_repo
-
- omniauth_providers = Gitlab.config.omniauth.providers
- omniauth_providers.map! { |provider| provider['name'] }
-
- puts ""
- puts "GitLab information".yellow
- puts "Version:\t#{Gitlab::VERSION}"
- puts "Revision:\t#{Gitlab::REVISION}"
- puts "Directory:\t#{Rails.root}"
- puts "DB Adapter:\t#{database_adapter}"
- 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
-
-
-
- # check Gitolite version
- gitlab_shell_version_file = "#{Gitlab.config.gitlab_shell.hooks_path}/../VERSION"
- if File.readable?(gitlab_shell_version_file)
- gitlab_shell_version = File.read(gitlab_shell_version_file)
- end
-
- puts ""
- puts "GitLab Shell".yellow
- puts "Version:\t#{gitlab_shell_version || "unknown".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}"
-
- end
- end
-end
diff --git a/lib/tasks/gitlab/mail_google_schema_whitelisting.rake b/lib/tasks/gitlab/mail_google_schema_whitelisting.rake
deleted file mode 100644
index 102c6ae55d5..00000000000
--- a/lib/tasks/gitlab/mail_google_schema_whitelisting.rake
+++ /dev/null
@@ -1,73 +0,0 @@
-require "#{Rails.root}/app/helpers/emails_helper"
-require 'action_view/helpers'
-extend ActionView::Helpers
-
-include ActionView::Context
-include EmailsHelper
-
-namespace :gitlab do
- desc "Email google whitelisting email with example email for actions in inbox"
- task mail_google_schema_whitelisting: :environment do
- subject = "Rails | Implemented feature"
- url = "#{Gitlab.config.gitlab.url}/base/rails-project/issues/#{rand(1..100)}#note_#{rand(10..1000)}"
- schema = email_action(url)
- body = email_template(schema, url)
- mail = Notify.test_email("schema.whitelisting+sample@gmail.com", subject, body.html_safe)
- if send_now
- mail.deliver
- else
- puts "WOULD SEND:"
- end
- puts mail
- end
-
- def email_template(schema, url)
- "<html lang='en'>
- <head>
- <meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
- <title>
- GitLab
- </title>
- </meta>
- </head>
- <style>
- img {
- max-width: 100%;
- height: auto;
- }
- p.details {
- font-style:italic;
- color:#777
- }
- .footer p {
- font-size:small;
- color:#777
- }
- </style>
- <body>
- <div class='content'>
- <div>
- <p>I like it :+1: </p>
- </div>
- </div>
-
- <div class='footer' style='margin-top: 10px;'>
- <p>
- <br>
- <a href=\"#{url}\">View it on GitLab</a>
- You're receiving this notification because you are a member of the Base / Rails Project project team.
- #{schema}
- </p>
- </div>
- </body>
- </html>"
- end
-
- def send_now
- if ENV['SEND'] == "true"
- true
- else
- false
- end
- end
-end
diff --git a/lib/tasks/gitlab/setup.rake b/lib/tasks/gitlab/setup.rake
deleted file mode 100644
index 8b4ccdfc3fe..00000000000
--- a/lib/tasks/gitlab/setup.rake
+++ /dev/null
@@ -1,24 +0,0 @@
-namespace :gitlab do
- desc "GITLAB | Setup production application"
- task setup: :environment do
- setup_db
- end
-
- def setup_db
- warn_user_is_not_gitlab
-
- unless ENV['force'] == 'yes'
- puts "This will create the necessary database tables and seed the database."
- puts "You will lose any previous data stored in the database."
- ask_to_continue
- puts ""
- end
-
- Rake::Task["db:setup"].invoke
- Rake::Task["add_limits_mysql"].invoke
- Rake::Task["db:seed_fu"].invoke
- rescue Gitlab::TaskAbortedByUserError
- puts "Quitting...".red
- exit 1
- end
-end
diff --git a/lib/tasks/gitlab/shell.rake b/lib/tasks/gitlab/shell.rake
deleted file mode 100644
index e835d6cb9b7..00000000000
--- a/lib/tasks/gitlab/shell.rake
+++ /dev/null
@@ -1,138 +0,0 @@
-namespace :gitlab do
- namespace :shell do
- desc "GITLAB | Install or upgrade gitlab-shell"
- task :install, [:tag, :repo] => :environment do |t, args|
- warn_user_is_not_gitlab
-
- default_version = Gitlab::Shell.version_required
- args.with_defaults(tag: 'v' + default_version, repo: "https://gitlab.com/gitlab-org/gitlab-shell.git")
-
- user = Gitlab.config.gitlab.user
- home_dir = Rails.env.test? ? Rails.root.join('tmp/tests') : Gitlab.config.gitlab.user_home
- gitlab_url = Gitlab.config.gitlab.url
- # gitlab-shell requires a / at the end of the url
- gitlab_url += '/' unless gitlab_url.end_with?('/')
- repos_path = Gitlab.config.gitlab_shell.repos_path
- target_dir = Gitlab.config.gitlab_shell.path
-
- # Clone if needed
- unless File.directory?(target_dir)
- system(*%W(git clone -- #{args.repo} #{target_dir}))
- end
-
- # Make sure we're on the right tag
- Dir.chdir(target_dir) do
- # First try to checkout without fetching
- # to avoid stalling tests if the Internet is down.
- reseted = reset_to_commit(args)
-
- unless reseted
- system(*%W(git fetch origin))
- reset_to_commit(args)
- end
-
- config = {
- user: user,
- gitlab_url: gitlab_url,
- http_settings: {self_signed_cert: false}.stringify_keys,
- repos_path: repos_path,
- auth_file: File.join(home_dir, ".ssh", "authorized_keys"),
- redis: {
- bin: %x{which redis-cli}.chomp,
- namespace: "resque:gitlab"
- }.stringify_keys,
- log_level: "INFO",
- audit_usernames: false
- }.stringify_keys
-
- redis_url = URI.parse(ENV['REDIS_URL'] || "redis://localhost:6379")
-
- if redis_url.scheme == 'unix'
- config['redis']['socket'] = redis_url.path
- else
- config['redis']['host'] = redis_url.host
- config['redis']['port'] = redis_url.port
- end
-
- # Generate config.yml based on existing gitlab settings
- File.open("config.yml", "w+") {|f| f.puts config.to_yaml}
-
- # Launch installation process
- system(*%W(bin/install))
- end
-
- # Required for debian packaging with PKGR: Setup .ssh/environment with
- # the current PATH, so that the correct ruby version gets loaded
- # Requires to set "PermitUserEnvironment yes" in sshd config (should not
- # be an issue since it is more than likely that there are no "normal"
- # user accounts on a gitlab server). The alternative is for the admin to
- # install a ruby (1.9.3+) in the global path.
- File.open(File.join(home_dir, ".ssh", "environment"), "w+") do |f|
- f.puts "PATH=#{ENV['PATH']}"
- end
- end
-
- desc "GITLAB | Setup gitlab-shell"
- task setup: :environment do
- setup
- end
-
- desc "GITLAB | Build missing projects"
- task build_missing_projects: :environment do
- Project.find_each(batch_size: 1000) do |project|
- path_to_repo = project.repository.path_to_repo
- if File.exists?(path_to_repo)
- print '-'
- else
- if Gitlab::Shell.new.add_repository(project.path_with_namespace)
- print '.'
- else
- print 'F'
- end
- end
- end
- end
- end
-
- def setup
- warn_user_is_not_gitlab
-
- unless ENV['force'] == 'yes'
- puts "This will rebuild an authorized_keys file."
- puts "You will lose any data stored in authorized_keys file."
- ask_to_continue
- puts ""
- end
-
- Gitlab::Shell.new.remove_all_keys
-
- Gitlab::Shell.new.batch_add_keys do |adder|
- Key.find_each(batch_size: 1000) do |key|
- adder.add_key(key.shell_id, key.key)
- print '.'
- end
- end
- puts ""
-
- unless $?.success?
- puts "Failed to add keys...".red
- exit 1
- end
-
- rescue Gitlab::TaskAbortedByUserError
- puts "Quitting...".red
- exit 1
- end
-
- def reset_to_commit(args)
- tag, status = Gitlab::Popen.popen(%W(git describe -- #{args.tag}))
-
- unless status.zero?
- tag, status = Gitlab::Popen.popen(%W(git describe -- origin/#{args.tag}))
- end
-
- tag = tag.strip
- system(*%W(git reset --hard #{tag}))
- end
-end
-
diff --git a/lib/tasks/gitlab/sidekiq.rake b/lib/tasks/gitlab/sidekiq.rake
deleted file mode 100644
index 7e2a6668e59..00000000000
--- a/lib/tasks/gitlab/sidekiq.rake
+++ /dev/null
@@ -1,47 +0,0 @@
-namespace :gitlab do
- namespace :sidekiq do
- QUEUE = 'queue:post_receive'
-
- desc 'Drop all Sidekiq PostReceive jobs for a given project'
- task :drop_post_receive , [:project] => :environment do |t, args|
- unless args.project.present?
- abort "Please specify the project you want to drop PostReceive jobs for:\n rake gitlab:sidekiq:drop_post_receive[group/project]"
- end
- project_path = Project.find_with_namespace(args.project).repository.path_to_repo
-
- Sidekiq.redis do |redis|
- unless redis.exists(QUEUE)
- abort "Queue #{QUEUE} is empty"
- end
-
- temp_queue = "#{QUEUE}_#{Time.now.to_i}"
- redis.rename(QUEUE, temp_queue)
-
- # At this point, then post_receive queue is empty. It may be receiving
- # new jobs already. We will repopulate it with the old jobs, skipping the
- # ones we want to drop.
- dropped = 0
- while (job = redis.lpop(temp_queue)) do
- if repo_path(job) == project_path
- dropped += 1
- else
- redis.rpush(QUEUE, job)
- end
- end
- # The temp_queue will delete itself after we have popped all elements
- # from it
-
- puts "Dropped #{dropped} jobs containing #{project_path} from #{QUEUE}"
- end
- end
-
- def repo_path(job)
- job_args = JSON.parse(job)['args']
- if job_args
- job_args.first
- else
- nil
- end
- end
- end
-end
diff --git a/lib/tasks/gitlab/task_helpers.rake b/lib/tasks/gitlab/task_helpers.rake
deleted file mode 100644
index 14a130be2ca..00000000000
--- a/lib/tasks/gitlab/task_helpers.rake
+++ /dev/null
@@ -1,131 +0,0 @@
-module Gitlab
- class TaskAbortedByUserError < StandardError; end
-end
-
-unless STDOUT.isatty
- module Colored
- extend self
-
- def colorize(string, options={})
- string
- end
- end
-end
-
-namespace :gitlab do
-
- # Ask if the user wants to continue
- #
- # 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})
- raise Gitlab::TaskAbortedByUserError unless answer == "yes"
- end
-
- # Check which OS is running
- #
- # It will primarily use lsb_relase to determine the OS.
- # It has fallbacks to Debian, SuSE, OS X and systems running systemd.
- def os_name
- os_name = run(%W(lsb_release -irs))
- os_name ||= if File.readable?('/etc/system-release')
- File.read('/etc/system-release')
- end
- os_name ||= if File.readable?('/etc/debian_version')
- debian_version = File.read('/etc/debian_version')
- "Debian #{debian_version}"
- end
- os_name ||= if File.readable?('/etc/SuSE-release')
- File.read('/etc/SuSE-release')
- end
- os_name ||= if os_x_version = run(%W(sw_vers -productVersion))
- "Mac OS X #{os_x_version}"
- end
- os_name ||= if File.readable?('/etc/os-release')
- File.read('/etc/os-release').match(/PRETTY_NAME=\"(.+)\"/)[1]
- end
- os_name.try(:squish!)
- end
-
- # Prompt the user to input something
- #
- # message - the message to display before input
- # choices - array of strings of acceptable answers or nil for any answer
- #
- # Returns the user's answer
- def prompt(message, choices = nil)
- begin
- print(message)
- answer = STDIN.gets.chomp
- end while choices.present? && !choices.include?(answer)
- answer
- end
-
- # Runs the given command and matches the output against the given pattern
- #
- # Returns nil if nothing matched
- # Returns the MatchData if the pattern matched
- #
- # see also #run
- # see also String#match
- def run_and_match(command, regexp)
- run(command).try(:match, regexp)
- end
-
- # Runs the given command
- #
- # Returns nil if the command was not found
- # Returns the output of the command otherwise
- #
- # see also #run_and_match
- def run(command)
- output, _ = Gitlab::Popen.popen(command)
- output
- rescue Errno::ENOENT
- '' # if the command does not exist, return an empty string
- end
-
- def uid_for(user_name)
- run(%W(id -u #{user_name})).chomp.to_i
- end
-
- def gid_for(group_name)
- begin
- Etc.getgrnam(group_name).gid
- rescue ArgumentError # no group
- "group #{group_name} doesn't exist"
- end
- end
-
- def warn_user_is_not_gitlab
- unless @warned_user_not_gitlab
- gitlab_user = Gitlab.config.gitlab.user
- current_user = run(%W(whoami)).chomp
- unless current_user == gitlab_user
- puts "#{Colored.color(:black)+Colored.color(:on_yellow)} Warning #{Colored.extra(:clear)}"
- puts " You are running as user #{current_user.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 ""
- end
- @warned_user_not_gitlab = true
- end
- end
-
- # Tries to configure git itself
- #
- # Returns true if all subcommands were successfull (according to their exit code)
- # Returns false if any or all subcommands failed.
- def auto_fix_git_config(options)
- if !@warned_user_not_gitlab && options['user.email'] != 'example@example.com' # default email should be overridden?
- command_success = options.map do |name, value|
- system(%W(#{Gitlab.config.git.bin_path} config --global #{name} #{value}))
- end
-
- command_success.all?
- else
- false
- end
- end
-end
diff --git a/lib/tasks/gitlab/test.rake b/lib/tasks/gitlab/test.rake
deleted file mode 100644
index b4c0ae3ff79..00000000000
--- a/lib/tasks/gitlab/test.rake
+++ /dev/null
@@ -1,16 +0,0 @@
-namespace :gitlab do
- desc "GITLAB | Run all tests"
- task :test do
- cmds = [
- %W(rake brakeman),
- %W(rake rubocop),
- %W(rake spinach),
- %W(rake spec),
- %W(rake jasmine:ci)
- ]
-
- cmds.each do |cmd|
- system({'RAILS_ENV' => 'test', 'force' => 'yes'}, *cmd) or raise("#{cmd} failed!")
- end
- end
-end
diff --git a/lib/tasks/gitlab/web_hook.rake b/lib/tasks/gitlab/web_hook.rake
deleted file mode 100644
index f9f586db93c..00000000000
--- a/lib/tasks/gitlab/web_hook.rake
+++ /dev/null
@@ -1,65 +0,0 @@
-namespace :gitlab do
- namespace :web_hook do
- desc "GITLAB | Adds a web hook to the projects"
- task :add => :environment do
- web_hook_url = ENV['URL']
- namespace_path = ENV['NAMESPACE']
-
- projects = find_projects(namespace_path)
-
- puts "Adding web hook '#{web_hook_url}' to:"
- projects.find_each(batch_size: 1000) do |project|
- print "- #{project.name} ... "
- web_hook = project.hooks.new(url: web_hook_url)
- if web_hook.save
- puts "added".green
- else
- print "failed".red
- puts " [#{web_hook.errors.full_messages.to_sentence}]"
- end
- end
- end
-
- desc "GITLAB | Remove a web hook from the projects"
- task :rm => :environment do
- web_hook_url = ENV['URL']
- namespace_path = ENV['NAMESPACE']
-
- projects = find_projects(namespace_path)
- projects_ids = projects.pluck(:id)
-
- puts "Removing web hooks with the url '#{web_hook_url}' ... "
- count = WebHook.where(url: web_hook_url, project_id: projects_ids, type: 'ProjectHook').delete_all
- puts "#{count} web hooks were removed."
- end
-
- desc "GITLAB | List web hooks"
- task :list => :environment do
- namespace_path = ENV['NAMESPACE']
-
- projects = find_projects(namespace_path)
- web_hooks = projects.all.map(&:hooks).flatten
- web_hooks.each do |hook|
- puts "#{hook.project.name.truncate(20).ljust(20)} -> #{hook.url}"
- end
-
- puts "\n#{web_hooks.size} web hooks found."
- end
- end
-
- def find_projects(namespace_path)
- if namespace_path.blank?
- Project
- elsif namespace_path == '/'
- Project.where(namespace_id: nil)
- else
- namespace = Namespace.where(path: namespace_path).first
- if namespace
- Project.where(namespace_id: namespace.id)
- else
- puts "Namespace not found: #{namespace_path}".red
- exit 2
- end
- end
- end
-end