Commit c1280d23 authored by James Fargher's avatar James Fargher

Merge branch 'id-move-ee-post-receive-into-service' into 'master'

Extract EE part of /post_receive into a service

See merge request gitlab-org/gitlab!30033
parents 83d05863 e8b6fdc5
......@@ -75,3 +75,5 @@ class PostReceiveService
::MergeRequests::GetUrlsService.new(project).execute(params[:changes])
end
end
PostReceiveService.prepend_if_ee('EE::PostReceiveService')
# frozen_string_literal: true
# EE extension of PostReceiveService class
module EE
module PostReceiveService
include ::Gitlab::Utils::StrongMemoize
extend ::Gitlab::Utils::Override
override :execute
def execute
response = super
response.add_basic_message(geo_redirect_to_primary_message) if display_geo_redirect_to_primary_message?
response.add_basic_message(geo_secondary_lag_message) if geo_display_secondary_lag_message?
response
end
private
def geo_redirect_to_primary_message
return unless geo_referred_node
strong_memoize(:geo_redirect_to_primary_message) do
url = "#{::Gitlab::Geo.current_node.url.chomp('/')}/#{project.full_path}.git"
::Gitlab::Geo.interacting_with_primary_message(url)
end
end
def geo_referred_node
strong_memoize(:geo_referred_node) do
::Gitlab::Geo::GitPushHttp.new(params[:identifier], params[:gl_repository]).fetch_referrer_node
end
end
def geo_secondary_lag_message
"Current replication lag: #{geo_current_replication_lag} seconds"
end
def geo_current_replication_lag
strong_memoize(:geo_current_replication_lag) do
geo_referred_node&.status&.db_replication_lag_seconds
end
end
def display_geo_redirect_to_primary_message?
::Gitlab::Geo.primary? && geo_redirect_to_primary_message
end
def geo_display_secondary_lag_message?
::Gitlab::Geo.primary? && geo_current_replication_lag.to_i > 0
end
end
end
......@@ -8,7 +8,6 @@ module EE
prepended do
helpers do
include ::Gitlab::Utils::StrongMemoize
extend ::Gitlab::Utils::Override
override :lfs_authentication_url
......@@ -16,45 +15,6 @@ module EE
project.lfs_http_url_to_repo(params[:operation])
end
override :ee_post_receive_response_hook
def ee_post_receive_response_hook(response)
response.add_basic_message(geo_redirect_to_primary_message) if display_geo_redirect_to_primary_message?
response.add_basic_message(geo_secondary_lag_message) if geo_display_secondary_lag_message?
end
def geo_display_secondary_lag_message?
::Gitlab::Geo.primary? && geo_current_replication_lag.to_i > 0
end
def geo_secondary_lag_message
"Current replication lag: #{geo_current_replication_lag} seconds"
end
def geo_current_replication_lag
strong_memoize(:geo_current_replication_lag) do
geo_referred_node&.status&.db_replication_lag_seconds
end
end
def geo_referred_node
strong_memoize(:geo_referred_node) do
::Gitlab::Geo::GitPushHttp.new(params[:identifier], params[:gl_repository]).fetch_referrer_node
end
end
def display_geo_redirect_to_primary_message?
::Gitlab::Geo.primary? && geo_redirect_to_primary_message
end
def geo_redirect_to_primary_message
return unless geo_referred_node
@geo_redirect_to_primary_message ||= begin
url = "#{::Gitlab::Geo.current_node.url.chomp('/')}/#{project.full_path}.git"
::Gitlab::Geo.interacting_with_primary_message(url)
end
end
override :check_allowed
def check_allowed(params)
ip = params.fetch(:check_ip, nil)
......
......@@ -30,10 +30,6 @@ module API
project.http_url_to_repo
end
def ee_post_receive_response_hook(response)
# Hook for EE to add messages
end
def check_allowed(params)
# This is a separate method so that EE can alter its behaviour more
# easily.
......@@ -216,8 +212,6 @@ module API
response = PostReceiveService.new(actor.user, repository, project, params).execute
ee_post_receive_response_hook(response)
present response, with: Entities::InternalPostReceive::Response
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment