From 32b2ff26011a5274bdb8a3dd41ad360a67c3148a Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Fri, 19 Jan 2018 13:04:14 +0000 Subject: Adds remote messsage when project is created in a push over SSH or HTTP --- lib/api/helpers/internal_helpers.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/api/helpers/internal_helpers.rb') 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(?#{Gitlab::PathRegex.full_namespace_route_regex})\/(?#{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] -- cgit v1.2.1 From bc78ae6985ee37f9ac2ffc2dbf6f445078d16038 Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Mon, 22 Jan 2018 18:10:56 +0000 Subject: Add specs --- lib/api/helpers/internal_helpers.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'lib/api/helpers/internal_helpers.rb') diff --git a/lib/api/helpers/internal_helpers.rb b/lib/api/helpers/internal_helpers.rb index c0fcae43638..fd568c5ef30 100644 --- a/lib/api/helpers/internal_helpers.rb +++ b/lib/api/helpers/internal_helpers.rb @@ -64,6 +64,15 @@ 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 + } + end + private def project_path_regex @@ -71,11 +80,13 @@ module API end def project_match - @match ||= params[:project].match(project_path_regex).captures + @project_match ||= params[:project].match(project_path_regex) end - def namespace - @namespace ||= Namespace.find_by_path_or_name(project_match[:namespace_id]) + def project_namespace + return unless project_match + + @project_namespace ||= Namespace.find_by_path_or_name(project_match[:namespace_id]) end # rubocop:disable Gitlab/ModuleWithInstanceVariables -- cgit v1.2.1 From e42a548f1dac02577d0c1731fef508dab68c45a5 Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Thu, 25 Jan 2018 12:26:52 +0000 Subject: Move new project on push logic to a service --- lib/api/helpers/internal_helpers.rb | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) (limited to 'lib/api/helpers/internal_helpers.rb') 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(?#{Gitlab::PathRegex.full_namespace_route_regex})\/(?#{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 -- cgit v1.2.1 From dc229c076cdc0ef6e7f3f74f6e462c22880ff08c Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Fri, 26 Jan 2018 14:28:08 +0000 Subject: Abstracts ProjectMoved and ProjectCreated into a BaseProject --- lib/api/helpers/internal_helpers.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/api/helpers/internal_helpers.rb') diff --git a/lib/api/helpers/internal_helpers.rb b/lib/api/helpers/internal_helpers.rb index 2340e962918..bff245fe9a2 100644 --- a/lib/api/helpers/internal_helpers.rb +++ b/lib/api/helpers/internal_helpers.rb @@ -1,6 +1,8 @@ module API module Helpers module InternalHelpers + include Gitlab::Utils::StrongMemoize + attr_reader :redirected_path def wiki? @@ -65,13 +67,15 @@ module API end def project_namespace - @project_namespace ||= project&.namespace || Namespace.find_by_full_path(project_match[:namespace_path]) + strong_memoize(:project_namespace) do + project&.namespace || Namespace.find_by_full_path(project_match[:namespace_path]) + end end private def project_match - @project_match ||= params[:project].match(Gitlab::PathRegex.full_project_git_path_regex) + @project_match ||= params[:project].match(Gitlab::PathRegex.full_project_git_path_regex) || {} end # rubocop:disable Gitlab/ModuleWithInstanceVariables -- cgit v1.2.1 From 1e56b3f476f9779ec747534e94156a6b8076209c Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Fri, 2 Feb 2018 15:27:30 +0000 Subject: Moves project creationg to git access check for git push --- lib/api/helpers/internal_helpers.rb | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'lib/api/helpers/internal_helpers.rb') diff --git a/lib/api/helpers/internal_helpers.rb b/lib/api/helpers/internal_helpers.rb index bff245fe9a2..cd59da6fc70 100644 --- a/lib/api/helpers/internal_helpers.rb +++ b/lib/api/helpers/internal_helpers.rb @@ -1,8 +1,6 @@ module API module Helpers module InternalHelpers - include Gitlab::Utils::StrongMemoize - attr_reader :redirected_path def wiki? @@ -49,10 +47,6 @@ 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 @@ -66,16 +60,18 @@ module API false end - def project_namespace - strong_memoize(:project_namespace) do - project&.namespace || Namespace.find_by_full_path(project_match[:namespace_path]) - end + def project_path + project&.path || project_path_match[:project_path] + end + + def namespace_path + project&.namespace&.full_path || project_path_match[:namespace_path] end private - def project_match - @project_match ||= params[:project].match(Gitlab::PathRegex.full_project_git_path_regex) || {} + def project_path_match + @project_path_match ||= params[:project].match(Gitlab::PathRegex.full_project_git_path_regex) || {} end # rubocop:disable Gitlab/ModuleWithInstanceVariables -- cgit v1.2.1