summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorTiago Botelho <tiagonbotelho@hotmail.com>2018-01-19 13:04:14 +0000
committerTiago Botelho <tiagonbotelho@hotmail.com>2018-02-06 13:35:35 +0000
commit32b2ff26011a5274bdb8a3dd41ad360a67c3148a (patch)
tree56064e3de4e9ca505730bdf1af3597ba8ead499f /lib/api
parent35882e681b681f68a818bda9a8d2624edfecc219 (diff)
downloadgitlab-ce-32b2ff26011a5274bdb8a3dd41ad360a67c3148a.tar.gz
Adds remote messsage when project is created in a push over SSH or HTTP
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/helpers/internal_helpers.rb16
-rw-r--r--lib/api/internal.rb17
2 files changed, 28 insertions, 5 deletions
diff --git a/lib/api/helpers/internal_helpers.rb b/lib/api/helpers/internal_helpers.rb
index eb67de81a0d..c0fcae43638 100644
--- a/lib/api/helpers/internal_helpers.rb
+++ b/lib/api/helpers/internal_helpers.rb
@@ -29,6 +29,10 @@ 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)
@@ -62,6 +66,18 @@ module API
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
+ @match ||= params[:project].match(project_path_regex).captures
+ end
+
+ def namespace
+ @namespace ||= Namespace.find_by_path_or_name(project_match[:namespace_id])
+ end
+
# rubocop:disable Gitlab/ModuleWithInstanceVariables
def set_project
if params[:gl_repository]
diff --git a/lib/api/internal.rb b/lib/api/internal.rb
index a83f714a1f3..f641ef457a3 100644
--- a/lib/api/internal.rb
+++ b/lib/api/internal.rb
@@ -43,7 +43,7 @@ module API
access_checker_klass = wiki? ? Gitlab::GitAccessWiki : Gitlab::GitAccess
access_checker = access_checker_klass
- .new(actor, project, protocol, authentication_abilities: ssh_authentication_abilities, redirected_path: redirected_path, target_namespace: user.namespace)
+ .new(actor, project, protocol, authentication_abilities: ssh_authentication_abilities, redirected_path: redirected_path, target_namespace: namespace)
begin
access_checker.check(params[:action], params[:changes])
@@ -51,17 +51,21 @@ module API
return { status: false, message: e.message }
end
- if project.blank? && params[:action] == 'git-receive-pack'
+ if user && project.blank? && receive_pack?
project_params = {
description: "",
- path: params[:project].split('/').last.gsub("\.git", ''),
- namespace_id: user.namespace.id.to_s,
+ path: Project.parse_project_id(project_match[:project_name]),
+ namespace_id: namespace&.id,
visibility_level: Gitlab::VisibilityLevel::PRIVATE.to_s
}
@project = ::Projects::CreateService.new(user, project_params).execute
- return { status: false, message: "Could not create project" } unless @project.saved?
+ if @project.saved?
+ Gitlab::Checks::NewProject.new(user, @project, protocol).add_new_project_message
+ else
+ return { status: false, message: "Could not create project" }
+ end
end
log_user_activity(actor)
@@ -221,7 +225,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)
+
output[:redirected_message] = redirect_message if redirect_message
+ output[:new_project_message] = new_project_message if new_project_message
end
output