Commit c0505e1c authored by Michael Kozono's avatar Michael Kozono

Merge branch '32347-creating-events-on-design-creation' into 'master'

Creating events when design is created

Closes #32347

See merge request gitlab-org/gitlab!17349
parents b4f6419d 52c31165
......@@ -537,6 +537,7 @@ module EE
super
repository.log_geo_updated_event
wiki.repository.log_geo_updated_event
design_repository.log_geo_updated_event
end
override :import?
......
......@@ -95,10 +95,6 @@ module EE
::Geo::RepositoryUpdatedService.new(self).execute
end
def geo_updated_event_source
repo_type.wiki? ? Geo::RepositoryUpdatedEvent::WIKI : Geo::RepositoryUpdatedEvent::REPOSITORY
end
def code_owners_blob(ref: 'HEAD')
possible_code_owner_blobs = ::Gitlab::CodeOwners::FILE_PATHS.map { |path| [ref, path] }
blobs_at(possible_code_owner_blobs).compact.first
......
......@@ -7,11 +7,22 @@ module Geo
REPOSITORY = 0
WIKI = 1
DESIGN = 2
REPOSITORY_TYPE_MAP = {
::Gitlab::GlRepository::PROJECT => REPOSITORY,
::Gitlab::GlRepository::WIKI => WIKI,
::Gitlab::GlRepository::DESIGN => DESIGN
}.freeze
belongs_to :project
enum source: { repository: REPOSITORY, wiki: WIKI }
enum source: { repository: REPOSITORY, wiki: WIKI, design: DESIGN }
validates :project, presence: true
def self.source_for(repository)
REPOSITORY_TYPE_MAP[repository.repo_type]
end
end
end
......@@ -22,6 +22,9 @@ module DesignManagement
uploaded_designs = upload_designs!
skipped_designs = designs - uploaded_designs
# Create a Geo event so changes will be replicated to secondary node(s)
repository.log_geo_updated_event
success({ designs: uploaded_designs, skipped_designs: skipped_designs })
rescue ::ActiveRecord::RecordInvalid => e
error(e.message)
......
......@@ -11,12 +11,16 @@ module Geo
@params = params
@refs = params.fetch(:refs, [])
@changes = params.fetch(:changes, [])
@source = repository.geo_updated_event_source
@source = Geo::RepositoryUpdatedEvent.source_for(repository)
end
def execute
return false unless Gitlab::Geo.primary?
if source == Geo::RepositoryUpdatedEvent::DESIGN && Feature.disabled?(:enable_geo_design_sync)
return false
end
reset_repository_checksum!
create_repository_updated_event!
......@@ -36,6 +40,9 @@ module Geo
end
def reset_repository_checksum!
# We don't yet support verification for Design repositories
return if source == Geo::RepositoryUpdatedEvent::DESIGN
return if repository_state.nil?
repository_state.update!(
......
# frozen_string_literal: true
module EE
module Gitlab
module GlRepository
module RepoType
def design?
self == DESIGN
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::GlRepository::RepoType do
set(:project) { create(:project) }
describe Gitlab::GlRepository::DESIGN do
it_behaves_like 'a repo type' do
let(:expected_identifier) { "design-#{project.id}" }
let(:expected_id) { project.id.to_s }
let(:expected_suffix) { ".design" }
let(:expected_repository) { project.design_repository }
end
it "knows its type" do
expect(described_class).to be_design
expect(described_class).not_to be_project
end
end
end
......@@ -12,6 +12,6 @@ RSpec.describe Geo::RepositoryUpdatedEvent, type: :model do
end
describe '#source' do
it { is_expected.to define_enum_for(:source).with([:repository, :wiki]) }
it { is_expected.to define_enum_for(:source).with([:repository, :wiki, :design]) }
end
end
......@@ -1318,6 +1318,7 @@ describe Project do
let(:project) { create(:project) }
let(:repository_updated_service) { instance_double('::Geo::RepositoryUpdatedService') }
let(:wiki_updated_service) { instance_double('::Geo::RepositoryUpdatedService') }
let(:design_updated_service) { instance_double('::Geo::RepositoryUpdatedService') }
before do
create(:import_state, project: project)
......@@ -1331,6 +1332,11 @@ describe Project do
.to receive(:new)
.with(project.wiki.repository)
.and_return(wiki_updated_service)
allow(::Geo::RepositoryUpdatedService)
.to receive(:new)
.with(project.design_repository)
.and_return(design_updated_service)
end
it 'calls Geo::RepositoryUpdatedService when running on a Geo primary node' do
......@@ -1338,6 +1344,7 @@ describe Project do
expect(repository_updated_service).to receive(:execute).once
expect(wiki_updated_service).to receive(:execute).once
expect(design_updated_service).to receive(:execute).once
project.after_import
end
......
......@@ -183,6 +183,14 @@ describe DesignManagement::SaveDesignsService do
expect(updated_designs.first.versions.size).to eq(1)
end
end
it 'calls repository#log_geo_updated_event' do
expect(design_repository).to receive(:log_geo_updated_event)
allow_any_instance_of(described_class).to receive(:repository).and_return(design_repository)
run_service
end
end
context 'when a design has not changed since its previous version' do
......
......@@ -85,5 +85,19 @@ describe Geo::RepositoryUpdatedService do
let(:method_prefix) { 'wiki' }
end
end
context 'when design repository is being updated' do
let(:repository) { project.design_repository }
it 'creates a design repository updated event' do
expect { subject.execute }.to change(Geo::RepositoryUpdatedEvent, :count).by(1)
end
it 'does not create a design repository updated event when feature is disabled' do
stub_feature_flags(enable_geo_design_sync: false)
expect { subject.execute }.not_to change(Geo::RepositoryUpdatedEvent, :count)
end
end
end
end
......@@ -40,3 +40,5 @@ module Gitlab
end
end
end
Gitlab::GlRepository::RepoType.prepend_if_ee('EE::Gitlab::GlRepository::RepoType')
......@@ -4,36 +4,6 @@ require 'spec_helper'
describe Gitlab::GlRepository::RepoType do
set(:project) { create(:project) }
shared_examples 'a repo type' do
describe "#identifier_for_subject" do
subject { described_class.identifier_for_subject(project) }
it { is_expected.to eq(expected_identifier) }
end
describe "#fetch_id" do
it "finds an id match in the identifier" do
expect(described_class.fetch_id(expected_identifier)).to eq(expected_id)
end
it 'does not break on other identifiers' do
expect(described_class.fetch_id("wiki-noid")).to eq(nil)
end
end
describe "#path_suffix" do
subject { described_class.path_suffix }
it { is_expected.to eq(expected_suffix) }
end
describe "#repository_for" do
it "finds the repository for the repo type" do
expect(described_class.repository_for(project)).to eq(expected_repository)
end
end
end
describe Gitlab::GlRepository::PROJECT do
it_behaves_like 'a repo type' do
let(:expected_identifier) { "project-#{project.id}" }
......
# frozen_string_literal: true
shared_examples 'a repo type' do
describe "#identifier_for_subject" do
subject { described_class.identifier_for_subject(project) }
it { is_expected.to eq(expected_identifier) }
end
describe "#fetch_id" do
it "finds an id match in the identifier" do
expect(described_class.fetch_id(expected_identifier)).to eq(expected_id)
end
it 'does not break on other identifiers' do
expect(described_class.fetch_id("wiki-noid")).to eq(nil)
end
end
describe "#path_suffix" do
subject { described_class.path_suffix }
it { is_expected.to eq(expected_suffix) }
end
describe "#repository_for" do
it "finds the repository for the repo type" do
expect(described_class.repository_for(project)).to eq(expected_repository)
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