From 84d1bd786125c1c14a3ba5f63e38a4cc736a9027 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 16 Jan 2024 10:42:19 +0000 Subject: Add latest changes from gitlab-org/gitlab@16-8-stable-ee --- .../single_endpoint_issue_events_importer.rb | 49 +++++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb') diff --git a/lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb b/lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb index d7fa098a775..126a0b8fa4a 100644 --- a/lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb +++ b/lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb @@ -30,9 +30,11 @@ module Gitlab compose_associated_id!(parent_record, associated) - return if already_imported?(associated) || importer_class::SUPPORTED_EVENTS.exclude?(associated[:event]) + return if already_imported?(associated) || supported_events.exclude?(associated[:event]) - Gitlab::GithubImport::ObjectCounter.increment(project, object_type, :fetched) + cache_event(parent_record, associated) + + increment_object_counter(associated[:event]) pull_request = parent_record.is_a? MergeRequest associated[:issue] = { number: parent_record.iid, pull_request: pull_request } @@ -64,6 +66,12 @@ module Gitlab :issue_event end + def increment_object_counter(event_name) + counter_type = importer_class::EVENT_COUNTER_MAP[event_name] if import_settings.extended_events? + counter_type ||= object_type + Gitlab::GithubImport::ObjectCounter.increment(project, counter_type, :fetched) + end + def collection_method :issue_timeline end @@ -98,6 +106,43 @@ module Gitlab event[:id] = "cross-reference##{issuable.iid}-in-#{event.dig(:source, :issue, :id)}" end + + def import_settings + @import_settings ||= Gitlab::GithubImport::Settings.new(project) + end + + def after_batch_processed(parent) + return unless import_settings.extended_events? + + events = events_cache.events(parent) + + return if events.empty? + + hash = Representation::ReplayEvent.new(issuable_type: parent.class.name.to_s, issuable_iid: parent.iid) + .to_hash.deep_stringify_keys + ReplayEventsWorker.perform_async(project.id, hash, job_waiter.key.to_s) + job_waiter.jobs_remaining = Gitlab::Cache::Import::Caching.increment(job_waiter_remaining_cache_key) + end + + def supported_events + return importer_class::EXTENDED_SUPPORTED_EVENTS if import_settings.extended_events? + + importer_class::SUPPORTED_EVENTS + end + + def cache_event(parent_record, associated) + return unless import_settings.extended_events? + + return if Importer::ReplayEventsImporter::SUPPORTED_EVENTS.exclude?(associated[:event]) + + representation = representation_class.from_api_response(associated) + + events_cache.add(parent_record, representation) + end + + def events_cache + @events_cache ||= EventsCache.new(project) + end end end end -- cgit v1.2.3