Commit c8066b36 authored by Nick Thomas's avatar Nick Thomas

EE: Extract a Git::{Base,Tag,Branch}HooksService

parent 940e6cae
......@@ -142,3 +142,5 @@ module Git
end
end
end
Git::BranchHooksService.prepend(::EE::Git::BranchHooksService)
......@@ -92,4 +92,4 @@ module Git
end
end
Git::BranchPushService.prepend(EE::Git::BranchPushService)
Git::BranchPushService.prepend(::EE::Git::BranchPushService)
......@@ -34,3 +34,5 @@ module Git
end
end
end
Git::TagHooksService.prepend(::EE::Git::TagHooksService)
......@@ -12,5 +12,3 @@ module Git
end
end
end
Git::TagPushService.prepend(EE::Git::TagPushService)
# frozen_string_literal: true
module EE
module Git
module BranchHooksService
extend ::Gitlab::Utils::Override
private
override :pipeline_options
def pipeline_options
mirror_update = project.mirror? &&
project.repository.up_to_date_with_upstream?(branch_name)
{ mirror_update: mirror_update }
end
end
end
end
......@@ -5,28 +5,33 @@ module EE
module BranchPushService
extend ::Gitlab::Utils::Override
protected
override :execute_related_hooks
def execute_related_hooks
if should_index_commits?
::ElasticCommitIndexerWorker.perform_async(project.id, params[:oldrev], params[:newrev])
end
override :execute
def execute
enqueue_elasticsearch_indexing
super
end
private
def should_index_commits?
default_branch? &&
project.use_elasticsearch? &&
::Gitlab::Redis::SharedState.with { |redis| !redis.sismember(:elastic_projects_indexing, project.id) }
def enqueue_elasticsearch_indexing
return unless should_index_commits?
::ElasticCommitIndexerWorker.perform_async(
project.id,
params[:oldrev],
params[:newrev]
)
end
override :pipeline_options
def pipeline_options
{ mirror_update: project.mirror? && project.repository.up_to_date_with_upstream?(branch_name) }
def should_index_commits?
return false unless default_branch?
return false unless project.use_elasticsearch?
# Check that we're not already indexing this project
::Gitlab::Redis::SharedState.with do |redis|
!redis.sismember(:elastic_projects_indexing, project.id)
end
end
end
end
......
......@@ -2,7 +2,7 @@
module EE
module Git
module TagPushService
module TagHooksService
extend ::Gitlab::Utils::Override
private
......
......@@ -22,8 +22,14 @@ describe PostReceive do
allow_any_instance_of(Gitlab::DataBuilder::Repository).to receive(:update).and_return(fake_hook_data)
# silence hooks so we can isolate
allow_any_instance_of(Key).to receive(:post_create_hook).and_return(true)
allow_any_instance_of(Git::TagPushService).to receive(:execute).and_return(true)
allow_any_instance_of(Git::BranchPushService).to receive(:execute).and_return(true)
expect_next_instance_of(Git::TagPushService) do |service|
expect(service).to receive(:execute).and_return(true)
end
expect_next_instance_of(Git::BranchPushService) do |service|
expect(service).to receive(:execute).and_return(true)
end
end
it 'calls Geo::RepositoryUpdatedService when running on a Geo primary node' do
......
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