Create a repository updated event when updating the default branch

parent fda055db
......@@ -78,6 +78,13 @@ module EE
log_geo_updated_event
end
override :after_change_head
def after_change_head
super
ensure
log_geo_updated_event
end
def log_geo_updated_event
return unless ::Gitlab::Geo.primary?
......
......@@ -6,7 +6,7 @@ module Geo
def sync_repository
fetch_repository
update_default_branch
update_root_ref
mark_sync_as_successful
rescue Gitlab::Shell::Error => e
# In some cases repository does not exist, the only way to know about this is to parse the error text.
......@@ -46,7 +46,7 @@ module Geo
end
# Update the default branch querying the remote to determine its HEAD
def update_default_branch
def update_root_ref
root_ref = repository.find_remote_root_ref(GEO_REMOTE_NAME)
project.change_head(root_ref) if root_ref.present?
end
......
......@@ -3,8 +3,12 @@ require 'spec_helper'
describe Repository do
include RepoHelpers
include ::EE::GeoHelpers
TestBlob = Struct.new(:path)
set(:primary_node) { create(:geo_node, :primary) }
set(:secondary_node) { create(:geo_node) }
let(:project) { create(:project, :repository) }
let(:repository) { project.repository }
......@@ -116,8 +120,6 @@ describe Repository do
end
describe '#keep_around' do
set(:primary_node) { create(:geo_node, :primary) }
set(:secondary_node) { create(:geo_node) }
let(:sha) { sample_commit.id }
context 'on a Geo primary' do
......@@ -174,4 +176,20 @@ describe Repository do
repository.code_owners_blob
end
end
describe '#after_change_head' do
it 'creates a RepositoryUpdatedEvent on a Geo primary' do
stub_current_geo_node(primary_node)
expect { repository.after_change_head }
.to change { ::Geo::RepositoryUpdatedEvent.count }.by(1)
end
it 'does not create a RepositoryUpdatedEvent on a Geo secondary' do
stub_current_geo_node(secondary_node)
expect { repository.after_change_head }
.not_to change { ::Geo::RepositoryUpdatedEvent.count }
end
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