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