diff options
author | James Lopez <james@jameslopez.es> | 2017-03-17 13:33:11 +0100 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2017-03-17 13:33:11 +0100 |
commit | 8b9c2db8360d575e5f156cdbcf7685ddd166e10e (patch) | |
tree | b2d503190daefb1feb665760ddca2883ecd3e0e2 | |
parent | 69d0c56afa584cc6e2e82ebadb53d08ee02655eb (diff) | |
download | gitlab-ce-fix/gh-performance.tar.gz |
wip - added more fetch stufffix/gh-performance
-rw-r--r-- | app/models/concerns/mirror_common.rb | 10 | ||||
-rw-r--r-- | app/services/projects/import_service.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/github_import/importer.rb | 14 | ||||
-rw-r--r-- | lib/gitlab/popen.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/shell.rb | 19 |
5 files changed, 45 insertions, 6 deletions
diff --git a/app/models/concerns/mirror_common.rb b/app/models/concerns/mirror_common.rb index be034ec073d..f48f903b799 100644 --- a/app/models/concerns/mirror_common.rb +++ b/app/models/concerns/mirror_common.rb @@ -1,5 +1,15 @@ module MirrorCommon # TODO: Refactor in EE + def storage_path + @project.repository_storage_path + end + + def add_remote(name, url) + raw_repository.remote_add(name, url) + rescue Rugged::ConfigError + raw_repository.remote_update(name, url: url) + end + def set_remote_as_mirror(name) config = raw_repository.rugged.config diff --git a/app/services/projects/import_service.rb b/app/services/projects/import_service.rb index 1c5a549feb9..ac18befe41c 100644 --- a/app/services/projects/import_service.rb +++ b/app/services/projects/import_service.rb @@ -11,6 +11,8 @@ module Projects success rescue => e + puts e.message + puts e.backtrace.join("\n") error(e.message) end diff --git a/lib/gitlab/github_import/importer.rb b/lib/gitlab/github_import/importer.rb index eea4a91f17d..bb93813d84d 100644 --- a/lib/gitlab/github_import/importer.rb +++ b/lib/gitlab/github_import/importer.rb @@ -129,6 +129,10 @@ module Gitlab end def import_pull_requests + puts 'a' + project.repository.fetch_mirror(project.import_url) + puts 'b' + fetch_resources(:pull_requests, repo, state: :all, sort: :created, direction: :asc, per_page: 100) do |pull_requests| pull_requests.each do |raw| gh_pull_request = PullRequestFormatter.new(project, raw, client) @@ -136,7 +140,6 @@ module Gitlab next unless gh_pull_request.valid? begin - restore_source_branch(gh_pull_request) unless gh_pull_request.source_branch_exists? restore_target_branch(gh_pull_request) unless gh_pull_request.target_branch_exists? merge_request = gh_pull_request.create! @@ -151,15 +154,16 @@ module Gitlab clean_up_restored_branches(gh_pull_request) end end + + if project.merge_requests.count > 400 + raise Projects::ImportService::Error, + "Reached 400" + end end project.repository.after_remove_branch end - def restore_source_branch(pull_request) - project.repository.fetch_ref(repo_url, "pull/#{pull_request.number}/head", pull_request.source_branch_name) - end - def restore_target_branch(pull_request) project.repository.create_branch(pull_request.target_branch_name, pull_request.target_branch_sha) end diff --git a/lib/gitlab/popen.rb b/lib/gitlab/popen.rb index 4bc5cda8cb5..f62725a19d5 100644 --- a/lib/gitlab/popen.rb +++ b/lib/gitlab/popen.rb @@ -24,9 +24,13 @@ module Gitlab yield(stdin) if block_given? stdin.close + err = stderr.read + cmd_output << stdout.read - cmd_output << stderr.read + cmd_output << err cmd_status = wait_thr.value.exitstatus + + puts '>>> ' + err unless cmd_status.zero? end [cmd_output, cmd_status] diff --git a/lib/gitlab/shell.rb b/lib/gitlab/shell.rb index da8d8ddb8ed..22c985ff63c 100644 --- a/lib/gitlab/shell.rb +++ b/lib/gitlab/shell.rb @@ -88,6 +88,25 @@ module Gitlab true end + # Fetch remote for repository + # + # name - project path with namespace + # remote - remote name + # forced - should we use --force flag? + # + # Ex. + # fetch_remote("gitlab/gitlab-ci", "upstream") + # + def fetch_remote(storage, name, remote, forced: false, no_tags: false) + args = [gitlab_shell_projects_path, 'fetch-remote', storage, "#{name}.git", remote, '600'] + args << '--force' if forced + args << '--no-tags' if no_tags + + output, status = Popen.popen(args) + raise Error, output unless status.zero? + true + end + # Move repository # storage - project's storage path # path - project path with namespace |