Commit 4c8fe525 authored by Michael Kozono's avatar Michael Kozono

Refactor RepositoryUpdatedService initializer

So consumers don’t need to know about `source`.
parent 74d906ea
......@@ -520,7 +520,8 @@ module EE
override :after_import
def after_import
super
log_geo_events
repository.log_geo_updated_event
wiki.repository.log_geo_updated_event
end
override :import?
......@@ -573,13 +574,6 @@ module EE
# Board limits are disabled in EE, so this method is just a no-op.
end
def log_geo_events
return unless ::Gitlab::Geo.primary?
::Geo::RepositoryUpdatedService.new(self, source: ::Geo::RepositoryUpdatedEvent::REPOSITORY).execute
::Geo::RepositoryUpdatedService.new(self, source: ::Geo::RepositoryUpdatedEvent::WIKI).execute
end
override :after_rename_repository
def after_rename_repository(full_path_before, path_before)
super(full_path_before, path_before)
......
......@@ -81,8 +81,11 @@ module EE
def log_geo_updated_event
return unless ::Gitlab::Geo.primary?
source = is_wiki ? ::Geo::RepositoryUpdatedEvent::WIKI : ::Geo::RepositoryUpdatedEvent::REPOSITORY
::Geo::RepositoryUpdatedService.new(self.project, source: source).execute
::Geo::RepositoryUpdatedService.new(self).execute
end
def geo_updated_event_source
is_wiki ? Geo::RepositoryUpdatedEvent::WIKI : Geo::RepositoryUpdatedEvent::REPOSITORY
end
end
end
......@@ -63,7 +63,7 @@ module EE
end
def sync_wiki_on_enable
::Geo::RepositoryUpdatedService.new(project, source: ::Geo::RepositoryUpdatedEvent::WIKI).execute
::Geo::RepositoryUpdatedService.new(project.wiki.repository).execute
end
end
end
......
......@@ -16,7 +16,7 @@ module EE
def process_wiki_repository_update
if ::Gitlab::Geo.primary?
::Geo::RepositoryUpdatedService.new(project, source: ::Geo::RepositoryUpdatedEvent::WIKI).execute
::Geo::RepositoryUpdatedService.new(project.wiki.repository).execute
end
end
end
......
......@@ -4,12 +4,12 @@ module Geo
RepositoryUpdateError = Class.new(StandardError)
def initialize(project, params = {})
@project = project
def initialize(repository, params = {})
@project = repository.project
@params = params
@refs = params.fetch(:refs, [])
@changes = params.fetch(:changes, [])
@source = params.fetch(:source, Geo::RepositoryUpdatedEvent::REPOSITORY)
@source = repository.geo_updated_event_source
end
def execute
......
......@@ -12,7 +12,7 @@ module EE
super
if ::Gitlab::Geo.primary?
::Geo::RepositoryUpdatedService.new(post_received.project, refs: refs, changes: changes).execute
::Geo::RepositoryUpdatedService.new(post_received.project.repository, refs: refs, changes: changes).execute
end
end
......@@ -22,7 +22,7 @@ module EE
update_wiki_es_indexes(post_received)
if ::Gitlab::Geo.primary?
::Geo::RepositoryUpdatedService.new(post_received.project, source: ::Geo::RepositoryUpdatedEvent::WIKI).execute
::Geo::RepositoryUpdatedService.new(post_received.project.wiki.repository).execute
end
end
......
......@@ -1649,12 +1649,12 @@ describe Project do
before do
allow(::Geo::RepositoryUpdatedService)
.to receive(:new)
.with(project, source: Geo::RepositoryUpdatedEvent::REPOSITORY)
.with(project.repository)
.and_return(repository_updated_service)
allow(::Geo::RepositoryUpdatedService)
.to receive(:new)
.with(project, source: Geo::RepositoryUpdatedEvent::WIKI)
.with(project.wiki.repository)
.and_return(wiki_updated_service)
end
......
......@@ -13,7 +13,7 @@ describe Geo::RepositoryUpdatedService do
end
describe '#execute' do
subject { described_class.new(project, source: source) }
subject { described_class.new(repository) }
shared_examples 'repository being updated' do
context 'when not running on a primary node' do
......@@ -59,7 +59,7 @@ describe Geo::RepositoryUpdatedService do
end
it 'does not raise an error when project have never been verified' do
expect { described_class.new(create(:project)) }.not_to raise_error
expect { described_class.new(create(:project).repository) }.not_to raise_error
end
it 'raises a Geo::RepositoryUpdatedService::RepositoryUpdateError when an error occurs' do
......@@ -74,14 +74,14 @@ describe Geo::RepositoryUpdatedService do
context 'when repository is being updated' do
include_examples 'repository being updated' do
let(:source) { Geo::RepositoryUpdatedEvent::REPOSITORY }
let(:repository) { project.repository }
let(:method_prefix) { 'repository' }
end
end
context 'when wiki is being updated' do
include_examples 'repository being updated' do
let(:source) { Geo::RepositoryUpdatedEvent::WIKI }
let(:repository) { project.wiki.repository }
let(:method_prefix) { 'wiki' }
end
end
......
......@@ -23,7 +23,7 @@ describe WikiPages::CreateService do
allow(Gitlab::Geo).to receive(:primary?) { true }
repository_updated_service = instance_double('::Geo::RepositoryUpdatedService')
expect(::Geo::RepositoryUpdatedService).to receive(:new).with(project, source: Geo::RepositoryUpdatedEvent::WIKI) { repository_updated_service }
expect(::Geo::RepositoryUpdatedService).to receive(:new).with(project.wiki.repository) { repository_updated_service }
expect(repository_updated_service).to receive(:execute)
service.execute
......@@ -32,7 +32,7 @@ describe WikiPages::CreateService do
it 'does not call Geo::RepositoryUpdatedService when not running on a Geo primary node' do
allow(Gitlab::Geo).to receive(:primary?) { false }
expect(::Geo::RepositoryUpdatedService).not_to receive(:new).with(project, source: Geo::RepositoryUpdatedEvent::WIKI)
expect(::Geo::RepositoryUpdatedService).not_to receive(:new).with(project.wiki.repository)
service.execute
end
......
......@@ -16,7 +16,7 @@ describe WikiPages::DestroyService do
allow(Gitlab::Geo).to receive(:primary?) { true }
repository_updated_service = instance_double('::Geo::RepositoryUpdatedService')
expect(::Geo::RepositoryUpdatedService).to receive(:new).with(project, source: Geo::RepositoryUpdatedEvent::WIKI) { repository_updated_service }
expect(::Geo::RepositoryUpdatedService).to receive(:new).with(project.wiki.repository) { repository_updated_service }
expect(repository_updated_service).to receive(:execute)
service.execute(page)
......@@ -25,7 +25,7 @@ describe WikiPages::DestroyService do
it 'does not call Geo::RepositoryUpdatedService when not running on a Geo primary node' do
allow(Gitlab::Geo).to receive(:primary?) { false }
expect(::Geo::RepositoryUpdatedService).not_to receive(:new).with(project, source: Geo::RepositoryUpdatedEvent::WIKI)
expect(::Geo::RepositoryUpdatedService).not_to receive(:new).with(project.wiki.repository)
service.execute(page)
end
......
......@@ -24,7 +24,7 @@ describe WikiPages::UpdateService do
allow(Gitlab::Geo).to receive(:primary?) { true }
repository_updated_service = instance_double('::Geo::RepositoryUpdatedService')
expect(::Geo::RepositoryUpdatedService).to receive(:new).with(project, source: Geo::RepositoryUpdatedEvent::WIKI) { repository_updated_service }
expect(::Geo::RepositoryUpdatedService).to receive(:new).with(project.wiki.repository) { repository_updated_service }
expect(repository_updated_service).to receive(:execute)
service.execute(page)
......@@ -33,7 +33,7 @@ describe WikiPages::UpdateService do
it 'does not call Geo::RepositoryUpdatedService when not running on a Geo primary node' do
allow(Gitlab::Geo).to receive(:primary?) { false }
expect(::Geo::RepositoryUpdatedService).not_to receive(:new).with(project, source: Geo::RepositoryUpdatedEvent::WIKI)
expect(::Geo::RepositoryUpdatedService).not_to receive(:new).with(project.wiki.repository)
service.execute(page)
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