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
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-07 18:09:30 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-07 18:09:30 +0300
commitc6b3ec3f56fa32a0e0ed3de0d0878d25f1adaddf (patch)
tree967afee9a510ff9dd503ebd83706dc760ec2e3ed /lib
parent903ccf7c93eb9490c76857bffe744249cc07de09 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/import_export/project/legacy_tree_saver.rb68
-rw-r--r--lib/gitlab/repository_url_builder.rb33
-rw-r--r--lib/gitlab/shell.rb8
3 files changed, 33 insertions, 76 deletions
diff --git a/lib/gitlab/import_export/project/legacy_tree_saver.rb b/lib/gitlab/import_export/project/legacy_tree_saver.rb
deleted file mode 100644
index 2ed98f52c58..00000000000
--- a/lib/gitlab/import_export/project/legacy_tree_saver.rb
+++ /dev/null
@@ -1,68 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
- module ImportExport
- module Project
- class LegacyTreeSaver
- attr_reader :full_path
-
- def initialize(project:, current_user:, shared:, params: {})
- @params = params
- @project = project
- @current_user = current_user
- @shared = shared
- @full_path = File.join(@shared.export_path, ImportExport.project_filename)
- end
-
- def save
- project_tree = tree_saver.serialize(@project, reader.project_tree)
- fix_project_tree(project_tree)
- tree_saver.save(project_tree, @shared.export_path, ImportExport.project_filename)
-
- true
- rescue => e
- @shared.error(e)
- false
- end
-
- private
-
- # Aware that the resulting hash needs to be pure-hash and
- # does not include any AR objects anymore, only objects that run `.to_json`
- def fix_project_tree(project_tree)
- if @params[:description].present?
- project_tree['description'] = @params[:description]
- end
-
- project_tree['project_members'] += group_members_array
- end
-
- def reader
- @reader ||= Gitlab::ImportExport::Reader.new(shared: @shared)
- end
-
- def group_members_array
- group_members.as_json(reader.group_members_tree).each do |group_member|
- group_member['source_type'] = 'Project' # Make group members project members of the future import
- end
- end
-
- def group_members
- return [] unless @current_user.can?(:admin_group, @project.group)
-
- # We need `.where.not(user_id: nil)` here otherwise when a group has an
- # invitee, it would make the following query return 0 rows since a NULL
- # user_id would be present in the subquery
- # See http://stackoverflow.com/questions/129077/not-in-clause-and-null-values
- non_null_user_ids = @project.project_members.where.not(user_id: nil).select(:user_id)
-
- GroupMembersFinder.new(@project.group).execute.where.not(user_id: non_null_user_ids)
- end
-
- def tree_saver
- @tree_saver ||= Gitlab::ImportExport::LegacyRelationTreeSaver.new
- end
- end
- end
- end
-end
diff --git a/lib/gitlab/repository_url_builder.rb b/lib/gitlab/repository_url_builder.rb
new file mode 100644
index 00000000000..2b88af1f77c
--- /dev/null
+++ b/lib/gitlab/repository_url_builder.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module RepositoryUrlBuilder
+ class << self
+ def build(path, protocol: :ssh)
+ # TODO: See https://gitlab.com/gitlab-org/gitlab/-/issues/213021
+ path = path.sub('@snippets', 'snippets')
+
+ case protocol
+ when :ssh
+ ssh_url(path)
+ when :http
+ http_url(path)
+ else
+ raise NotImplementedError.new("No URL builder defined for protocol #{protocol}")
+ end
+ end
+
+ private
+
+ def ssh_url(path)
+ Gitlab.config.gitlab_shell.ssh_path_prefix + "#{path}.git"
+ end
+
+ def http_url(path)
+ root = Gitlab::CurrentSettings.custom_http_clone_url_root.presence || Gitlab::Routing.url_helpers.root_url
+
+ Gitlab::Utils.append_path(root, "#{path}.git")
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/shell.rb b/lib/gitlab/shell.rb
index 1f8a45e5481..24f49f6b943 100644
--- a/lib/gitlab/shell.rb
+++ b/lib/gitlab/shell.rb
@@ -47,14 +47,6 @@ module Gitlab
@version ||= File.read(gitlab_shell_version_file).chomp if File.readable?(gitlab_shell_version_file)
end
- # Return a SSH url for a given project path
- #
- # @param [String] full_path project path (URL)
- # @return [String] SSH URL
- def url_to_repo(full_path)
- Gitlab.config.gitlab_shell.ssh_path_prefix + "#{full_path}.git"
- end
-
private
def gitlab_shell_path