summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorTiago Botelho <tiagonbotelho@hotmail.com>2018-01-25 12:26:52 +0000
committerTiago Botelho <tiagonbotelho@hotmail.com>2018-02-06 13:35:35 +0000
commite42a548f1dac02577d0c1731fef508dab68c45a5 (patch)
tree9781b82ec0da58683ebeb0fd0ba2062a9ce10e43 /lib/api
parentbc78ae6985ee37f9ac2ffc2dbf6f445078d16038 (diff)
downloadgitlab-ce-e42a548f1dac02577d0c1731fef508dab68c45a5.tar.gz
Move new project on push logic to a service
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/helpers/internal_helpers.rb29
-rw-r--r--lib/api/internal.rb16
2 files changed, 14 insertions, 31 deletions
diff --git a/lib/api/helpers/internal_helpers.rb b/lib/api/helpers/internal_helpers.rb
index fd568c5ef30..2340e962918 100644
--- a/lib/api/helpers/internal_helpers.rb
+++ b/lib/api/helpers/internal_helpers.rb
@@ -29,10 +29,6 @@ module API
{}
end
- def receive_pack?
- params[:action] == 'git-receive-pack'
- end
-
def fix_git_env_repository_paths(env, repository_path)
if obj_dir_relative = env['GIT_OBJECT_DIRECTORY_RELATIVE'].presence
env['GIT_OBJECT_DIRECTORY'] = File.join(repository_path, obj_dir_relative)
@@ -51,6 +47,10 @@ module API
::Users::ActivityService.new(actor, 'Git SSH').execute if commands.include?(params[:action])
end
+ def receive_pack?
+ params[:action] == 'git-receive-pack'
+ end
+
def merge_request_urls
::MergeRequests::GetUrlsService.new(project).execute(params[:changes])
end
@@ -64,29 +64,14 @@ module API
false
end
- def project_params
- {
- description: "",
- path: Project.parse_project_id(project_match[:project_id]),
- namespace_id: project_namespace&.id,
- visibility_level: Gitlab::VisibilityLevel::PRIVATE.to_s
- }
+ def project_namespace
+ @project_namespace ||= project&.namespace || Namespace.find_by_full_path(project_match[:namespace_path])
end
private
- def project_path_regex
- @project_regex ||= /\A(?<namespace_id>#{Gitlab::PathRegex.full_namespace_route_regex})\/(?<project_id>#{Gitlab::PathRegex.project_git_route_regex})\z/.freeze
- end
-
def project_match
- @project_match ||= params[:project].match(project_path_regex)
- end
-
- def project_namespace
- return unless project_match
-
- @project_namespace ||= Namespace.find_by_path_or_name(project_match[:namespace_id])
+ @project_match ||= params[:project].match(Gitlab::PathRegex.full_project_git_path_regex)
end
# rubocop:disable Gitlab/ModuleWithInstanceVariables
diff --git a/lib/api/internal.rb b/lib/api/internal.rb
index b7475af2044..841a34eb67f 100644
--- a/lib/api/internal.rb
+++ b/lib/api/internal.rb
@@ -51,13 +51,11 @@ module API
return { status: false, message: e.message }
end
- if user && project.blank? && receive_pack?
- @project = ::Projects::CreateService.new(user, project_params).execute
-
- if @project.saved?
- Gitlab::Checks::NewProject.new(user, @project, protocol).add_new_project_message
- else
- return { status: false, message: "Could not create project" }
+ if receive_pack? && project.blank?
+ begin
+ @project = ::Projects::CreateFromPushService.new(user, project_match[:project_path], project_namespace, protocol).execute
+ rescue Gitlab::GitAccess::ProjectCreationError => e
+ return { status: false, message: e.message }
end
end
@@ -218,10 +216,10 @@ module API
# key could be used
if user
redirect_message = Gitlab::Checks::ProjectMoved.fetch_redirect_message(user.id, project.id)
- new_project_message = Gitlab::Checks::NewProject.fetch_new_project_message(user.id, project.id)
+ project_created_message = Gitlab::Checks::ProjectCreated.fetch_project_created_message(user.id, project.id)
output[:redirected_message] = redirect_message if redirect_message
- output[:new_project_message] = new_project_message if new_project_message
+ output[:project_created_message] = project_created_message if project_created_message
end
output