From 74c834a04f2ff8ba112d7d1fe18e46c2b96a0d5a Mon Sep 17 00:00:00 2001 From: Rodrigo Tomonari <rtomonari@gitlab.com> Date: Tue, 5 Dec 2023 16:01:44 +0000 Subject: [PATCH] Ignore non relevant events on GitHub Importer --- .../importer/issue_event_importer.rb | 15 +++++++++++++++ .../single_endpoint_issue_events_importer.rb | 3 ++- .../1_manage/import/import_github_repo_spec.rb | 2 +- .../single_endpoint_issue_events_importer_spec.rb | 15 ++++++++++++++- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/gitlab/github_import/importer/issue_event_importer.rb b/lib/gitlab/github_import/importer/issue_event_importer.rb index 80749aae93c7..e9397accbcd9 100644 --- a/lib/gitlab/github_import/importer/issue_event_importer.rb +++ b/lib/gitlab/github_import/importer/issue_event_importer.rb @@ -6,6 +6,21 @@ module Importer class IssueEventImporter attr_reader :issue_event, :project, :client + SUPPORTED_EVENTS = %w[ + assigned + closed + cross-referenced + demilestoned + labeled + milestoned + renamed + reopened + review_request_removed + review_requested + unassigned + unlabeled + ].freeze + # issue_event - An instance of `Gitlab::GithubImport::Representation::IssueEvent`. # project - An instance of `Project`. # client - An instance of `Gitlab::GithubImport::Client`. 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 e0a7e6479f53..d7fa098a7757 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 @@ -29,7 +29,8 @@ def each_associated(parent_record, associated) associated = associated.to_h compose_associated_id!(parent_record, associated) - return if already_imported?(associated) + + return if already_imported?(associated) || importer_class::SUPPORTED_EVENTS.exclude?(associated[:event]) Gitlab::GithubImport::ObjectCounter.increment(project, object_type, :fetched) diff --git a/qa/qa/specs/features/api/1_manage/import/import_github_repo_spec.rb b/qa/qa/specs/features/api/1_manage/import/import_github_repo_spec.rb index 9d0d81bdd911..f36b1faa82b7 100644 --- a/qa/qa/specs/features/api/1_manage/import/import_github_repo_spec.rb +++ b/qa/qa/specs/features/api/1_manage/import/import_github_repo_spec.rb @@ -31,7 +31,7 @@ def verify_status_data stats = imported_project.project_import_status.dig(:stats, :imported) expect(stats).to eq( issue: 1, - issue_event: 16, + issue_event: 10, pull_request: 1, pull_request_review: 2, pull_request_review_request: 1, diff --git a/spec/lib/gitlab/github_import/importer/single_endpoint_issue_events_importer_spec.rb b/spec/lib/gitlab/github_import/importer/single_endpoint_issue_events_importer_spec.rb index dde730d46d26..8f4d62e53d6a 100644 --- a/spec/lib/gitlab/github_import/importer/single_endpoint_issue_events_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/single_endpoint_issue_events_importer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter do +RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter, feature_category: :importers do let(:client) { double } let_it_be(:project) { create(:project, :import_started, import_source: 'http://somegithub.com') } @@ -192,5 +192,18 @@ expect(counter).to eq 0 end end + + context 'when event is not supported' do + let(:issue_event) do + struct = Struct.new(:id, :event, :created_at, :issue, keyword_init: true) + struct.new(id: 1, event: 'not_supported_event', created_at: '2022-04-26 18:30:53 UTC') + end + + it "doesn't process this event" do + counter = 0 + subject.each_object_to_import { counter += 1 } + expect(counter).to eq 0 + end + end end end -- GitLab