summaryrefslogtreecommitdiff
path: root/lib/tasks
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2017-04-27 11:44:02 +0100
committerPhil Hughes <me@iamphill.com>2017-04-27 11:44:02 +0100
commit429a42b0cd2f7dd20e8e6bc924ecc27b55500410 (patch)
tree2538b2527ef2f89febf82a0409ff87b8ed470c9a /lib/tasks
parent1dc91f48cfb10d4ed61a06c37e444b72eb7743d3 (diff)
parent025b04f3e7976ac8829e24fcb587d86574b0037d (diff)
downloadgitlab-ce-429a42b0cd2f7dd20e8e6bc924ecc27b55500410.tar.gz
Merge branch 'master' into emoji-button-titles
Diffstat (limited to 'lib/tasks')
-rw-r--r--lib/tasks/gitlab/gitaly.rake37
-rw-r--r--lib/tasks/gitlab/update_templates.rake8
-rw-r--r--lib/tasks/import.rake112
3 files changed, 65 insertions, 92 deletions
diff --git a/lib/tasks/gitlab/gitaly.rake b/lib/tasks/gitlab/gitaly.rake
index 8079c6e416c..046780481ba 100644
--- a/lib/tasks/gitlab/gitaly.rake
+++ b/lib/tasks/gitlab/gitaly.rake
@@ -2,6 +2,8 @@ namespace :gitlab do
namespace :gitaly do
desc "GitLab | Install or upgrade gitaly"
task :install, [:dir] => :environment do |t, args|
+ require 'toml'
+
warn_user_is_not_gitlab
unless args.dir.present?
abort %(Please specify the directory where you want to install gitaly:\n rake "gitlab:gitaly:install[/home/git/gitaly]")
@@ -16,6 +18,7 @@ namespace :gitlab do
command = status.zero? ? 'gmake' : 'make'
Dir.chdir(args.dir) do
+ create_gitaly_configuration
run_command!([command])
end
end
@@ -33,5 +36,39 @@ namespace :gitlab do
puts TOML.dump(storage: config)
end
+
+ private
+
+ # We cannot create config.toml files for all possible Gitaly configuations.
+ # For instance, if Gitaly is running on another machine then it makes no
+ # sense to write a config.toml file on the current machine. This method will
+ # only write a config.toml file in the most common and simplest case: the
+ # case where we have exactly one Gitaly process and we are sure it is
+ # running locally because it uses a Unix socket.
+ def create_gitaly_configuration
+ storages = []
+ address = nil
+
+ Gitlab.config.repositories.storages.each do |key, val|
+ if address
+ if address != val['gitaly_address']
+ raise ArgumentError, "Your gitlab.yml contains more than one gitaly_address."
+ end
+ elsif URI(val['gitaly_address']).scheme != 'unix'
+ raise ArgumentError, "Automatic config.toml generation only supports 'unix:' addresses."
+ else
+ address = val['gitaly_address']
+ end
+
+ storages << { name: key, path: val['path'] }
+ end
+
+ File.open("config.toml", "w") do |f|
+ f.puts TOML.dump(socket_path: address.sub(%r{\Aunix:}, ''), storages: storages)
+ end
+ rescue ArgumentError => e
+ puts "Skipping config.toml generation:"
+ puts e.message
+ end
end
end
diff --git a/lib/tasks/gitlab/update_templates.rake b/lib/tasks/gitlab/update_templates.rake
index cb2adc81c9d..1b04e1350ed 100644
--- a/lib/tasks/gitlab/update_templates.rake
+++ b/lib/tasks/gitlab/update_templates.rake
@@ -5,7 +5,7 @@ namespace :gitlab do
end
def update(template)
- sub_dir = template.repo_url.match(/([a-z-]+)\.git\z/)[1]
+ sub_dir = template.repo_url.match(/([A-Za-z-]+)\.git\z/)[1]
dir = File.join(vendor_directory, sub_dir)
unless clone_repository(template.repo_url, dir)
@@ -45,7 +45,11 @@ namespace :gitlab do
Template.new(
"https://gitlab.com/gitlab-org/gitlab-ci-yml.git",
/(\.{1,2}|LICENSE|CONTRIBUTING.md|Pages|autodeploy|\.gitlab-ci.yml)\z/
- )
+ ),
+ Template.new(
+ "https://gitlab.com/gitlab-org/Dockerfile.git",
+ /(\.{1,2}|LICENSE|CONTRIBUTING.md|\.Dockerfile)\z/
+ ),
].freeze
def vendor_directory
diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake
index a9dad6a1bf0..bc76d7edc55 100644
--- a/lib/tasks/import.rake
+++ b/lib/tasks/import.rake
@@ -1,67 +1,5 @@
require 'benchmark'
require 'rainbow/ext/string'
-require_relative '../gitlab/shell_adapter'
-require_relative '../gitlab/github_import/importer'
-
-class NewImporter < ::Gitlab::GithubImport::Importer
- def execute
- # Same as ::Gitlab::GithubImport::Importer#execute, but showing some progress.
- puts 'Importing repository...'.color(:aqua)
- import_repository unless project.repository_exists?
-
- puts 'Importing labels...'.color(:aqua)
- import_labels
-
- puts 'Importing milestones...'.color(:aqua)
- import_milestones
-
- puts 'Importing pull requests...'.color(:aqua)
- import_pull_requests
-
- puts 'Importing issues...'.color(:aqua)
- import_issues
-
- puts 'Importing issue comments...'.color(:aqua)
- import_comments(:issues)
-
- puts 'Importing pull request comments...'.color(:aqua)
- import_comments(:pull_requests)
-
- puts 'Importing wiki...'.color(:aqua)
- import_wiki
-
- # Gitea doesn't have a Release API yet
- # See https://github.com/go-gitea/gitea/issues/330
- unless project.gitea_import?
- import_releases
- end
-
- handle_errors
-
- project.repository.after_import
- project.import_finish
-
- true
- end
-
- def import_repository
- begin
- raise 'Blocked import URL.' if Gitlab::UrlBlocker.blocked_url?(project.import_url)
-
- project.create_repository
- project.repository.add_remote(project.import_type, project.import_url)
- project.repository.set_remote_as_mirror(project.import_type)
- project.repository.fetch_remote(project.import_type, forced: true)
- rescue => e
- # Expire cache to prevent scenarios such as:
- # 1. First import failed, but the repo was imported successfully, so +exists?+ returns true
- # 2. Retried import, repo is broken or not imported but +exists?+ still returns true
- project.repository.expire_content_cache if project.repository_exists?
-
- raise "Error importing repository #{project.import_url} into #{project.path_with_namespace} - #{e.message}"
- end
- end
-end
class GithubImport
def self.run!(*args)
@@ -69,14 +7,14 @@ class GithubImport
end
def initialize(token, gitlab_username, project_path, extras)
- @token = token
+ @options = { url: 'https://api.github.com', token: token, verbose: true }
@project_path = project_path
@current_user = User.find_by_username(gitlab_username)
@github_repo = extras.empty? ? nil : extras.first
end
def run!
- @repo = GithubRepos.new(@token, @current_user, @github_repo).choose_one!
+ @repo = GithubRepos.new(@options, @current_user, @github_repo).choose_one!
raise 'No repo found!' unless @repo
@@ -90,25 +28,24 @@ class GithubImport
private
def show_warning!
- puts "This will import GH #{@repo.full_name.bright} into GL #{@project_path.bright} as #{@current_user.name}"
+ puts "This will import GitHub #{@repo['full_name'].bright} into GitLab #{@project_path.bright} as #{@current_user.name}"
puts "Permission checks are ignored. Press any key to continue.".color(:red)
STDIN.getch
- puts 'Starting the import...'.color(:green)
+ puts 'Starting the import (this could take a while)'.color(:green)
end
def import!
- import_url = @project.import_url.gsub(/\:\/\/(.*@)?/, "://#{@token}@")
- @project.update(import_url: import_url)
-
@project.import_start
timings = Benchmark.measure do
- NewImporter.new(@project).execute
+ Github::Import.new(@project, @options).execute
end
puts "Import finished. Timings: #{timings}".color(:green)
+
+ @project.import_finish
end
def new_project
@@ -116,17 +53,17 @@ class GithubImport
namespace_path, _sep, name = @project_path.rpartition('/')
namespace = find_or_create_namespace(namespace_path)
- Project.create!(
- import_url: "https://#{@token}@github.com/#{@repo.full_name}.git",
+ Projects::CreateService.new(
+ @current_user,
name: name,
path: name,
- description: @repo.description,
- namespace: namespace,
+ description: @repo['description'],
+ namespace_id: namespace.id,
visibility_level: visibility_level,
import_type: 'github',
- import_source: @repo.full_name,
- creator: @current_user
- )
+ import_source: @repo['full_name'],
+ skip_wiki: @repo['has_wiki']
+ ).execute
end
end
@@ -134,7 +71,6 @@ class GithubImport
return @current_user.namespace if names == @current_user.namespace_path
return @current_user.namespace unless @current_user.can_create_group?
- names = params[:target_namespace].presence || names
full_path_namespace = Namespace.find_by_full_path(names)
return full_path_namespace if full_path_namespace
@@ -159,13 +95,13 @@ class GithubImport
end
def visibility_level
- @repo.private ? Gitlab::VisibilityLevel::PRIVATE : current_application_settings.default_project_visibility
+ @repo['private'] ? Gitlab::VisibilityLevel::PRIVATE : current_application_settings.default_project_visibility
end
end
class GithubRepos
- def initialize(token, current_user, github_repo)
- @token = token
+ def initialize(options, current_user, github_repo)
+ @options = options
@current_user = current_user
@github_repo = github_repo
end
@@ -174,17 +110,17 @@ class GithubRepos
return found_github_repo if @github_repo
repos.each do |repo|
- print "ID: #{repo[:id].to_s.bright} ".color(:green)
- puts "- Name: #{repo[:full_name]}".color(:green)
+ print "ID: #{repo['id'].to_s.bright}".color(:green)
+ print "\tName: #{repo['full_name']}\n".color(:green)
end
print 'ID? '.bright
- repos.find { |repo| repo[:id] == repo_id }
+ repos.find { |repo| repo['id'] == repo_id }
end
def found_github_repo
- repos.find { |repo| repo[:full_name] == @github_repo }
+ repos.find { |repo| repo['full_name'] == @github_repo }
end
def repo_id
@@ -192,11 +128,7 @@ class GithubRepos
end
def repos
- @repos ||= client.repos
- end
-
- def client
- @client ||= Gitlab::GithubImport::Client.new(@token, {})
+ Github::Repositories.new(@options).fetch
end
end