Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/github_import/importer')
-rw-r--r--spec/lib/gitlab/github_import/importer/attachments/base_importer_spec.rb2
-rw-r--r--spec/lib/gitlab/github_import/importer/attachments/issues_importer_spec.rb67
-rw-r--r--spec/lib/gitlab/github_import/importer/attachments/merge_requests_importer_spec.rb68
-rw-r--r--spec/lib/gitlab/github_import/importer/attachments/notes_importer_spec.rb79
-rw-r--r--spec/lib/gitlab/github_import/importer/attachments/releases_importer_spec.rb67
-rw-r--r--spec/lib/gitlab/github_import/importer/collaborators_importer_spec.rb2
-rw-r--r--spec/lib/gitlab/github_import/importer/diff_notes_importer_spec.rb2
-rw-r--r--spec/lib/gitlab/github_import/importer/events/commented_spec.rb69
-rw-r--r--spec/lib/gitlab/github_import/importer/events/merged_spec.rb27
-rw-r--r--spec/lib/gitlab/github_import/importer/events/reviewed_spec.rb85
-rw-r--r--spec/lib/gitlab/github_import/importer/issue_event_importer_spec.rb12
-rw-r--r--spec/lib/gitlab/github_import/importer/issue_events_importer_spec.rb4
-rw-r--r--spec/lib/gitlab/github_import/importer/issues_importer_spec.rb2
-rw-r--r--spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb2
-rw-r--r--spec/lib/gitlab/github_import/importer/notes_importer_spec.rb2
-rw-r--r--spec/lib/gitlab/github_import/importer/protected_branches_importer_spec.rb4
-rw-r--r--spec/lib/gitlab/github_import/importer/pull_requests/review_importer_spec.rb7
-rw-r--r--spec/lib/gitlab/github_import/importer/pull_requests/review_requests_importer_spec.rb6
-rw-r--r--spec/lib/gitlab/github_import/importer/pull_requests/reviews_importer_spec.rb2
-rw-r--r--spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb2
-rw-r--r--spec/lib/gitlab/github_import/importer/replay_events_importer_spec.rb139
-rw-r--r--spec/lib/gitlab/github_import/importer/single_endpoint_diff_notes_importer_spec.rb2
-rw-r--r--spec/lib/gitlab/github_import/importer/single_endpoint_issue_events_importer_spec.rb211
-rw-r--r--spec/lib/gitlab/github_import/importer/single_endpoint_issue_notes_importer_spec.rb2
-rw-r--r--spec/lib/gitlab/github_import/importer/single_endpoint_merge_request_notes_importer_spec.rb2
25 files changed, 766 insertions, 101 deletions
diff --git a/spec/lib/gitlab/github_import/importer/attachments/base_importer_spec.rb b/spec/lib/gitlab/github_import/importer/attachments/base_importer_spec.rb
index 5e60be44621..bc1b32661b8 100644
--- a/spec/lib/gitlab/github_import/importer/attachments/base_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/attachments/base_importer_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::GithubImport::Importer::Attachments::BaseImporter do
+RSpec.describe Gitlab::GithubImport::Importer::Attachments::BaseImporter, feature_category: :importers do
subject(:importer) { importer_class.new(project, client) }
let(:project) { instance_double(Project, id: 1) }
diff --git a/spec/lib/gitlab/github_import/importer/attachments/issues_importer_spec.rb b/spec/lib/gitlab/github_import/importer/attachments/issues_importer_spec.rb
index b44f1ec85f3..20152020897 100644
--- a/spec/lib/gitlab/github_import/importer/attachments/issues_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/attachments/issues_importer_spec.rb
@@ -10,39 +10,68 @@ RSpec.describe Gitlab::GithubImport::Importer::Attachments::IssuesImporter, feat
let(:client) { instance_double(Gitlab::GithubImport::Client) }
describe '#sequential_import', :clean_gitlab_redis_cache do
- let_it_be(:issue_1) { create(:issue, project: project) }
- let_it_be(:issue_2) { create(:issue, project: project) }
+ let_it_be(:issue) { create(:issue, project: project) }
- let(:importer_stub) { instance_double('Gitlab::GithubImport::Importer::NoteAttachmentsImporter') }
- let(:importer_attrs) { [instance_of(Gitlab::GithubImport::Representation::NoteText), project, client] }
+ let_it_be(:issue_with_attachment) do
+ create(:issue,
+ project: project,
+ description: "![image](https://user-images.githubusercontent.com/1/uuid-1.png)"
+ )
+ end
+
+ it 'selects both issues, and selects only properties it needs' do
+ stubbed_collection = class_double(Issue, each_batch: [])
+
+ expect(project.issues).to receive(:id_not_in).with([]).and_return(stubbed_collection)
+ expect(stubbed_collection).to receive(:select).with(:id, :description, :iid).and_return(stubbed_collection)
- it 'imports each project issue attachments' do
- expect(project.issues).to receive(:id_not_in).with([]).and_return(project.issues)
- expect(project.issues).to receive(:select).with(:id, :description, :iid).and_call_original
+ importer.sequential_import
+ end
- expect_next_instances_of(
- Gitlab::GithubImport::Importer::NoteAttachmentsImporter, 2, false, *importer_attrs
- ) do |note_attachments_importer|
- expect(note_attachments_importer).to receive(:execute)
+ it 'executes importer only for the issue with an attachment' do
+ expect_next_instance_of(
+ Gitlab::GithubImport::Importer::NoteAttachmentsImporter,
+ have_attributes(record_db_id: issue_with_attachment.id),
+ project,
+ client
+ ) do |importer|
+ expect(importer).to receive(:execute)
end
importer.sequential_import
end
- context 'when issue is already processed' do
- it "doesn't import this issue attachments" do
- importer.mark_as_imported(issue_1)
+ context 'when flag is disabled' do
+ before do
+ stub_feature_flags(github_importer_attachments: false)
+ end
- expect(project.issues).to receive(:id_not_in).with([issue_1.id.to_s]).and_call_original
- expect_next_instance_of(
- Gitlab::GithubImport::Importer::NoteAttachmentsImporter, *importer_attrs
- ) do |note_attachments_importer|
- expect(note_attachments_importer).to receive(:execute)
+ it 'executes importer for both issues' do
+ expect_next_instances_of(Gitlab::GithubImport::Importer::NoteAttachmentsImporter, 2) do |importer|
+ expect(importer).to receive(:execute)
end
importer.sequential_import
end
end
+
+ context 'when issue has already been processed' do
+ before do
+ importer.mark_as_imported(issue_with_attachment)
+ end
+
+ it 'does not select issues that were processed' do
+ expect(project.issues).to receive(:id_not_in).with([issue_with_attachment.id.to_s]).and_call_original
+
+ importer.sequential_import
+ end
+
+ it 'does not execute importer for the issue with an attachment' do
+ expect(Gitlab::GithubImport::Importer::NoteAttachmentsImporter).not_to receive(:new)
+
+ importer.sequential_import
+ end
+ end
end
describe '#sidekiq_worker_class' do
diff --git a/spec/lib/gitlab/github_import/importer/attachments/merge_requests_importer_spec.rb b/spec/lib/gitlab/github_import/importer/attachments/merge_requests_importer_spec.rb
index 381cb17bb52..5ed6dce8507 100644
--- a/spec/lib/gitlab/github_import/importer/attachments/merge_requests_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/attachments/merge_requests_importer_spec.rb
@@ -10,39 +10,69 @@ RSpec.describe Gitlab::GithubImport::Importer::Attachments::MergeRequestsImporte
let(:client) { instance_double(Gitlab::GithubImport::Client) }
describe '#sequential_import', :clean_gitlab_redis_cache do
- let_it_be(:merge_request_1) { create(:merge_request, source_project: project, target_branch: 'feature1') }
- let_it_be(:merge_request_2) { create(:merge_request, source_project: project, target_branch: 'feature2') }
+ let_it_be(:mr) { create(:merge_request, source_project: project, target_branch: 'feature1') }
+
+ let_it_be(:mr_with_attachment) do
+ create(:merge_request,
+ source_project: project,
+ target_branch: 'feature2',
+ description: "![image](https://user-images.githubusercontent.com/1/uuid-1.png)"
+ )
+ end
+
+ it 'selects both merge requests, and selects only properties it needs' do
+ stubbed_collection = class_double(MergeRequest, each_batch: [])
- let(:importer_stub) { instance_double('Gitlab::GithubImport::Importer::NoteAttachmentsImporter') }
- let(:importer_attrs) { [instance_of(Gitlab::GithubImport::Representation::NoteText), project, client] }
+ expect(project.merge_requests).to receive(:id_not_in).with([]).and_return(stubbed_collection)
+ expect(stubbed_collection).to receive(:select).with(:id, :description, :iid).and_return(stubbed_collection)
- it 'imports each project merge request attachments' do
- expect(project.merge_requests).to receive(:id_not_in).with([]).and_return(project.merge_requests)
- expect(project.merge_requests).to receive(:select).with(:id, :description, :iid).and_call_original
+ importer.sequential_import
+ end
- expect_next_instances_of(
- Gitlab::GithubImport::Importer::NoteAttachmentsImporter, 2, false, *importer_attrs
- ) do |note_attachments_importer|
- expect(note_attachments_importer).to receive(:execute)
+ it 'executes importer only for the merge request with an attachment' do
+ expect_next_instance_of(
+ Gitlab::GithubImport::Importer::NoteAttachmentsImporter,
+ have_attributes(record_db_id: mr_with_attachment.id),
+ project,
+ client
+ ) do |importer|
+ expect(importer).to receive(:execute)
end
importer.sequential_import
end
- context 'when merge request is already processed' do
- it "doesn't import this merge request attachments" do
- importer.mark_as_imported(merge_request_1)
+ context 'when flag is disabled' do
+ before do
+ stub_feature_flags(github_importer_attachments: false)
+ end
- expect(project.merge_requests).to receive(:id_not_in).with([merge_request_1.id.to_s]).and_call_original
- expect_next_instance_of(
- Gitlab::GithubImport::Importer::NoteAttachmentsImporter, *importer_attrs
- ) do |note_attachments_importer|
- expect(note_attachments_importer).to receive(:execute)
+ it 'executes importer for both merge requests' do
+ expect_next_instances_of(Gitlab::GithubImport::Importer::NoteAttachmentsImporter, 2) do |importer|
+ expect(importer).to receive(:execute)
end
importer.sequential_import
end
end
+
+ context 'when merge request has already been processed' do
+ before do
+ importer.mark_as_imported(mr_with_attachment)
+ end
+
+ it 'does not select merge requests that were processed' do
+ expect(project.merge_requests).to receive(:id_not_in).with([mr_with_attachment.id.to_s]).and_call_original
+
+ importer.sequential_import
+ end
+
+ it 'does not execute importer for the merge request with an attachment' do
+ expect(Gitlab::GithubImport::Importer::NoteAttachmentsImporter).not_to receive(:new)
+
+ importer.sequential_import
+ end
+ end
end
describe '#sidekiq_worker_class' do
diff --git a/spec/lib/gitlab/github_import/importer/attachments/notes_importer_spec.rb b/spec/lib/gitlab/github_import/importer/attachments/notes_importer_spec.rb
index 5b3ad032702..da0ee1ed0dd 100644
--- a/spec/lib/gitlab/github_import/importer/attachments/notes_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/attachments/notes_importer_spec.rb
@@ -10,30 +10,75 @@ RSpec.describe Gitlab::GithubImport::Importer::Attachments::NotesImporter, featu
let(:client) { instance_double(Gitlab::GithubImport::Client) }
describe '#sequential_import', :clean_gitlab_redis_cache do
- let_it_be(:note_1) { create(:note, project: project) }
- let_it_be(:note_2) { create(:note, project: project) }
- let_it_be(:system_note) { create(:note, :system, project: project) }
+ let_it_be(:note) { create(:note, project: project) }
- let(:importer_stub) { instance_double('Gitlab::GithubImport::Importer::NoteAttachmentsImporter') }
- let(:importer_attrs) { [instance_of(Gitlab::GithubImport::Representation::NoteText), project, client] }
+ let_it_be(:note_with_attachment) do
+ create(:note,
+ project: project,
+ note: "![image](https://user-images.githubusercontent.com/1/uuid-1.png)"
+ )
+ end
+
+ let_it_be(:system_note_with_attachment) do
+ create(:note,
+ :system,
+ project: project,
+ note: "![image](https://user-images.githubusercontent.com/1/uuid-1.png)"
+ )
+ end
- it 'imports each project user note' do
- expect(project.notes).to receive(:id_not_in).with([]).and_call_original
- expect(Gitlab::GithubImport::Importer::NoteAttachmentsImporter).to receive(:new)
- .with(*importer_attrs).twice.and_return(importer_stub)
- expect(importer_stub).to receive(:execute).twice
+ it 'selects only user notes, and selects only properties it needs' do
+ stubbed_collection = class_double(Note, each_batch: [])
+
+ expect(project.notes).to receive(:id_not_in).with([]).and_return(stubbed_collection)
+ expect(stubbed_collection).to receive(:user).and_return(stubbed_collection)
+ expect(stubbed_collection)
+ .to receive(:select).with(:id, :note, :system, :noteable_type)
+ .and_return(stubbed_collection)
importer.sequential_import
end
- context 'when note is already processed' do
- it "doesn't import this note" do
- importer.mark_as_imported(note_1)
+ it 'executes importer only for the note with an attachment' do
+ expect_next_instance_of(
+ Gitlab::GithubImport::Importer::NoteAttachmentsImporter,
+ have_attributes(record_db_id: note_with_attachment.id),
+ project,
+ client
+ ) do |importer|
+ expect(importer).to receive(:execute)
+ end
+
+ importer.sequential_import
+ end
+
+ context 'when flag is disabled' do
+ before do
+ stub_feature_flags(github_importer_attachments: false)
+ end
+
+ it 'executes importer for both user notes' do
+ expect_next_instances_of(Gitlab::GithubImport::Importer::NoteAttachmentsImporter, 2) do |importer|
+ expect(importer).to receive(:execute)
+ end
+
+ importer.sequential_import
+ end
+ end
+
+ context 'when note has already been processed' do
+ before do
+ importer.mark_as_imported(note_with_attachment)
+ end
+
+ it 'does not select notes that were processed' do
+ expect(project.notes).to receive(:id_not_in).with([note_with_attachment.id.to_s]).and_call_original
+
+ importer.sequential_import
+ end
- expect(project.notes).to receive(:id_not_in).with([note_1.id.to_s]).and_call_original
- expect(Gitlab::GithubImport::Importer::NoteAttachmentsImporter).to receive(:new)
- .with(*importer_attrs).once.and_return(importer_stub)
- expect(importer_stub).to receive(:execute).once
+ it 'does not execute importer for the note with an attachment' do
+ expect(Gitlab::GithubImport::Importer::NoteAttachmentsImporter).not_to receive(:new)
importer.sequential_import
end
diff --git a/spec/lib/gitlab/github_import/importer/attachments/releases_importer_spec.rb b/spec/lib/gitlab/github_import/importer/attachments/releases_importer_spec.rb
index c1c19c40afb..cf51760d966 100644
--- a/spec/lib/gitlab/github_import/importer/attachments/releases_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/attachments/releases_importer_spec.rb
@@ -10,31 +10,64 @@ RSpec.describe Gitlab::GithubImport::Importer::Attachments::ReleasesImporter, fe
let(:client) { instance_double(Gitlab::GithubImport::Client) }
describe '#sequential_import', :clean_gitlab_redis_cache do
- let_it_be(:release_1) { create(:release, project: project) }
- let_it_be(:release_2) { create(:release, project: project) }
+ let_it_be(:release) { create(:release, project: project) }
- let(:importer_stub) { instance_double('Gitlab::GithubImport::Importer::NoteAttachmentsImporter') }
- let(:importer_attrs) { [instance_of(Gitlab::GithubImport::Representation::NoteText), project, client] }
+ let_it_be(:release_with_attachment) do
+ create(:release,
+ project: project,
+ description: "![image](https://user-images.githubusercontent.com/1/uuid-1.png)"
+ )
+ end
- it 'imports each project release' do
- expect(project.releases).to receive(:id_not_in).with([]).and_return(project.releases)
- expect(project.releases).to receive(:select).with(:id, :description, :tag).and_call_original
+ it 'selects both releases, and selects only properties it needs' do
+ stubbed_collection = class_double(Release, each_batch: [])
- expect(Gitlab::GithubImport::Importer::NoteAttachmentsImporter).to receive(:new)
- .with(*importer_attrs).twice.and_return(importer_stub)
- expect(importer_stub).to receive(:execute).twice
+ expect(project.releases).to receive(:id_not_in).with([]).and_return(stubbed_collection)
+ expect(stubbed_collection).to receive(:select).with(:id, :description, :tag).and_return(stubbed_collection)
importer.sequential_import
end
- context 'when note is already processed' do
- it "doesn't import this release" do
- importer.mark_as_imported(release_1)
+ it 'executes importer only for the release with an attachment' do
+ expect_next_instance_of(
+ Gitlab::GithubImport::Importer::NoteAttachmentsImporter,
+ have_attributes(record_db_id: release_with_attachment.id),
+ project,
+ client
+ ) do |importer|
+ expect(importer).to receive(:execute)
+ end
+
+ importer.sequential_import
+ end
+
+ context 'when flag is disabled' do
+ before do
+ stub_feature_flags(github_importer_attachments: false)
+ end
+
+ it 'executes importer for both releases' do
+ expect_next_instances_of(Gitlab::GithubImport::Importer::NoteAttachmentsImporter, 2) do |importer|
+ expect(importer).to receive(:execute)
+ end
+
+ importer.sequential_import
+ end
+ end
+
+ context 'when release has already been processed' do
+ before do
+ importer.mark_as_imported(release_with_attachment)
+ end
+
+ it 'does not select releases that were processed' do
+ expect(project.releases).to receive(:id_not_in).with([release_with_attachment.id.to_s]).and_call_original
+
+ importer.sequential_import
+ end
- expect(project.releases).to receive(:id_not_in).with([release_1.id.to_s]).and_call_original
- expect(Gitlab::GithubImport::Importer::NoteAttachmentsImporter).to receive(:new)
- .with(*importer_attrs).once.and_return(importer_stub)
- expect(importer_stub).to receive(:execute).once
+ it 'does not execute importer for the release with an attachment' do
+ expect(Gitlab::GithubImport::Importer::NoteAttachmentsImporter).not_to receive(:new)
importer.sequential_import
end
diff --git a/spec/lib/gitlab/github_import/importer/collaborators_importer_spec.rb b/spec/lib/gitlab/github_import/importer/collaborators_importer_spec.rb
index c1e9bed5681..d0d3e6c6da8 100644
--- a/spec/lib/gitlab/github_import/importer/collaborators_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/collaborators_importer_spec.rb
@@ -83,7 +83,7 @@ RSpec.describe Gitlab::GithubImport::Importer::CollaboratorsImporter, feature_ca
it 'imports each collaborator in parallel' do
expect(Gitlab::GithubImport::ImportCollaboratorWorker).to receive(:perform_in)
- .with(1, project.id, an_instance_of(Hash), an_instance_of(String))
+ .with(an_instance_of(Float), project.id, an_instance_of(Hash), an_instance_of(String))
waiter = importer.parallel_import
diff --git a/spec/lib/gitlab/github_import/importer/diff_notes_importer_spec.rb b/spec/lib/gitlab/github_import/importer/diff_notes_importer_spec.rb
index 1eb146ea958..ed74e978f16 100644
--- a/spec/lib/gitlab/github_import/importer/diff_notes_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/diff_notes_importer_spec.rb
@@ -102,7 +102,7 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNotesImporter, feature_catego
.and_yield(github_comment)
expect(Gitlab::GithubImport::ImportDiffNoteWorker).to receive(:perform_in)
- .with(1, project.id, an_instance_of(Hash), an_instance_of(String))
+ .with(an_instance_of(Float), project.id, an_instance_of(Hash), an_instance_of(String))
waiter = importer.parallel_import
diff --git a/spec/lib/gitlab/github_import/importer/events/commented_spec.rb b/spec/lib/gitlab/github_import/importer/events/commented_spec.rb
new file mode 100644
index 00000000000..bd3bea87688
--- /dev/null
+++ b/spec/lib/gitlab/github_import/importer/events/commented_spec.rb
@@ -0,0 +1,69 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::Importer::Events::Commented, feature_category: :importers do
+ subject(:importer) { described_class.new(project, client) }
+
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:user) { create(:user) }
+
+ let(:client) { instance_double('Gitlab::GithubImport::Client') }
+ let(:issuable) { create(:issue, project: project) }
+
+ let(:issue_event) do
+ Gitlab::GithubImport::Representation::IssueEvent.new(
+ id: 1196850910,
+ actor: { id: user.id, login: user.username },
+ event: 'commented',
+ created_at: '2022-07-27T14:41:11Z',
+ updated_at: '2022-07-27T14:41:11Z',
+ body: 'This is my note',
+ issue: { number: issuable.iid, pull_request: issuable.is_a?(MergeRequest) }
+ )
+ end
+
+ let(:extended_events) { true }
+
+ before do
+ allow_next_instance_of(Gitlab::GithubImport::IssuableFinder) do |finder|
+ allow(finder).to receive(:database_id).and_return(issuable.id)
+ end
+ allow_next_instance_of(Gitlab::GithubImport::UserFinder) do |finder|
+ allow(finder).to receive(:find).with(user.id, user.username).and_return(user.id)
+ end
+ allow_next_instance_of(Gitlab::GithubImport::Settings) do |setting|
+ allow(setting).to receive(:extended_events?).and_return(extended_events)
+ end
+ end
+
+ shared_examples 'new note' do
+ it 'creates a note' do
+ expect { importer.execute(issue_event) }.to change { Note.count }.by(1)
+
+ expect(issuable.notes.last).to have_attributes(
+ note: 'This is my note',
+ author_id: user.id,
+ noteable_type: issuable.class.name.to_s
+ )
+ end
+
+ context 'when extended_events is disabled' do
+ let(:extended_events) { false }
+
+ it 'does not create a note' do
+ expect { importer.execute(issue_event) }.not_to change { Note.count }
+ end
+ end
+ end
+
+ context 'with Issue' do
+ it_behaves_like 'new note'
+ end
+
+ context 'with MergeRequest' do
+ let(:issuable) { create(:merge_request, source_project: project, target_project: project) }
+
+ it_behaves_like 'new note'
+ end
+end
diff --git a/spec/lib/gitlab/github_import/importer/events/merged_spec.rb b/spec/lib/gitlab/github_import/importer/events/merged_spec.rb
index 4ea62557dd6..30bc8aabe12 100644
--- a/spec/lib/gitlab/github_import/importer/events/merged_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/events/merged_spec.rb
@@ -11,6 +11,7 @@ RSpec.describe Gitlab::GithubImport::Importer::Events::Merged, feature_category:
let(:client) { instance_double('Gitlab::GithubImport::Client') }
let(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let(:commit_id) { nil }
+ let(:extended_events) { false }
let(:issue_event) do
Gitlab::GithubImport::Representation::IssueEvent.from_json_hash(
@@ -32,6 +33,9 @@ RSpec.describe Gitlab::GithubImport::Importer::Events::Merged, feature_category:
allow_next_instance_of(Gitlab::GithubImport::UserFinder) do |finder|
allow(finder).to receive(:find).with(user.id, user.username).and_return(user.id)
end
+ allow_next_instance_of(Gitlab::GithubImport::Settings) do |setting|
+ allow(setting).to receive(:extended_events?).and_return(extended_events)
+ end
end
it 'creates expected event and state event' do
@@ -71,4 +75,27 @@ RSpec.describe Gitlab::GithubImport::Importer::Events::Merged, feature_category:
expect(state_event.source_commit).to eq commit_id[0..40]
end
end
+
+ describe 'extended events' do
+ context 'when using extended events' do
+ let(:extended_events) { true }
+
+ it 'creates a merged by note' do
+ expect { importer.execute(issue_event) }.to change { Note.count }.by(1)
+
+ last_note = merge_request.notes.last
+ expect(last_note.created_at).to eq(issue_event.created_at)
+ expect(last_note.author).to eq(project.owner)
+ expect(last_note.note).to eq("*Merged by: #{user.username} at #{issue_event.created_at}*")
+ end
+ end
+
+ context 'when not using extended events' do
+ let(:extended_events) { false }
+
+ it 'does not create a merged by note' do
+ expect { importer.execute(issue_event) }.not_to change { Note.count }
+ end
+ end
+ end
end
diff --git a/spec/lib/gitlab/github_import/importer/events/reviewed_spec.rb b/spec/lib/gitlab/github_import/importer/events/reviewed_spec.rb
new file mode 100644
index 00000000000..f60a9d65269
--- /dev/null
+++ b/spec/lib/gitlab/github_import/importer/events/reviewed_spec.rb
@@ -0,0 +1,85 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::Importer::Events::Reviewed, feature_category: :importers do
+ subject(:importer) { described_class.new(project, client) }
+
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:user) { create(:user) }
+
+ let(:client) { instance_double('Gitlab::GithubImport::Client') }
+ let(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
+ let(:extended_events) { true }
+
+ let(:issue_event) do
+ Gitlab::GithubImport::Representation::IssueEvent.new(
+ id: 1196850910,
+ actor: { id: user.id, login: user.username },
+ event: 'reviewed',
+ submitted_at: '2022-07-27T14:41:11Z',
+ body: 'This is my review',
+ state: state,
+ issue: { number: merge_request.iid, pull_request: true }
+ )
+ end
+
+ let(:state) { 'commented' }
+
+ before do
+ allow_next_instance_of(Gitlab::GithubImport::IssuableFinder) do |finder|
+ allow(finder).to receive(:database_id).and_return(merge_request.id)
+ end
+ allow_next_instance_of(Gitlab::GithubImport::UserFinder) do |finder|
+ allow(finder).to receive(:find).with(user.id, user.username).and_return(user.id)
+ end
+ allow_next_instance_of(Gitlab::GithubImport::Settings) do |setting|
+ allow(setting).to receive(:extended_events?).and_return(extended_events)
+ end
+ end
+
+ it 'creates a review note', :aggregate_failures do
+ expect { importer.execute(issue_event) }.to change { Note.count }.by(1)
+
+ last_note = merge_request.notes.last
+ expect(last_note.note).to include("This is my review")
+ expect(last_note.author).to eq(user)
+ expect(last_note.created_at).to eq(issue_event.submitted_at)
+ end
+
+ it 'does not create a reviewer for the Merge Request', :aggregate_failures do
+ expect { importer.execute(issue_event) }.not_to change { MergeRequestReviewer.count }
+ end
+
+ context 'when stage is approved' do
+ let(:state) { 'approved' }
+
+ it 'creates an approval for the Merge Request', :aggregate_failures do
+ expect { importer.execute(issue_event) }.to change { Approval.count }.by(1).and change { Note.count }.by(2)
+
+ expect(merge_request.approved_by_users.reload).to include(user)
+ expect(merge_request.approvals.last.created_at).to eq(issue_event.submitted_at)
+
+ note = merge_request.notes.where(system: false).last
+ expect(note.note).to include("This is my review")
+ expect(note.author).to eq(user)
+ expect(note.created_at).to eq(issue_event.submitted_at)
+
+ system_note = merge_request.notes.where(system: true).last
+ expect(system_note.note).to eq('approved this merge request')
+ expect(system_note.author).to eq(user)
+ expect(system_note.created_at).to eq(issue_event.submitted_at)
+ expect(system_note.system_note_metadata.action).to eq('approved')
+ end
+ end
+
+ context 'when extended events is false' do
+ let(:extended_events) { false }
+
+ it 'does nothing' do
+ expect { importer.execute(issue_event) }
+ .to not_change { Note.count }
+ .and not_change { Approval.count }
+ end
+ end
+end
diff --git a/spec/lib/gitlab/github_import/importer/issue_event_importer_spec.rb b/spec/lib/gitlab/github_import/importer/issue_event_importer_spec.rb
index 2389489e867..ffe6c237506 100644
--- a/spec/lib/gitlab/github_import/importer/issue_event_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/issue_event_importer_spec.rb
@@ -115,6 +115,18 @@ RSpec.describe Gitlab::GithubImport::Importer::IssueEventImporter, :clean_gitlab
it_behaves_like 'triggers specific event importer', Gitlab::GithubImport::Importer::Events::Merged
end
+ context "when it's commented issue event" do
+ let(:event_name) { 'commented' }
+
+ it_behaves_like 'triggers specific event importer', Gitlab::GithubImport::Importer::Events::Commented
+ end
+
+ context "when it's reviewed issue event" do
+ let(:event_name) { 'reviewed' }
+
+ it_behaves_like 'triggers specific event importer', Gitlab::GithubImport::Importer::Events::Reviewed
+ end
+
context "when it's unknown issue event" do
let(:event_name) { 'fake' }
diff --git a/spec/lib/gitlab/github_import/importer/issue_events_importer_spec.rb b/spec/lib/gitlab/github_import/importer/issue_events_importer_spec.rb
index f7ee6fee6dc..7e926b3af46 100644
--- a/spec/lib/gitlab/github_import/importer/issue_events_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/issue_events_importer_spec.rb
@@ -13,7 +13,7 @@ RSpec.describe Gitlab::GithubImport::Importer::IssueEventsImporter, feature_cate
struct = Struct.new(
:id, :node_id, :url, :actor, :event, :commit_id, :commit_url, :label, :rename, :milestone, :source,
:assignee, :assigner, :review_requester, :requested_reviewer, :issue, :created_at, :performed_via_github_app,
- keyword_init: true
+ :body, :updated_at, :submitted_at, :state, keyword_init: true
)
struct.new(id: rand(10), event: 'closed', created_at: '2022-04-26 18:30:53 UTC')
end
@@ -82,7 +82,7 @@ RSpec.describe Gitlab::GithubImport::Importer::IssueEventsImporter, feature_cate
allow(importer).to receive(:each_object_to_import).and_yield(issue_event)
expect(Gitlab::GithubImport::ImportIssueEventWorker).to receive(:perform_in).with(
- 1, project.id, an_instance_of(Hash), an_instance_of(String)
+ an_instance_of(Float), project.id, an_instance_of(Hash), an_instance_of(String)
)
waiter = importer.parallel_import
diff --git a/spec/lib/gitlab/github_import/importer/issues_importer_spec.rb b/spec/lib/gitlab/github_import/importer/issues_importer_spec.rb
index 9451d1dfc37..93466497ceb 100644
--- a/spec/lib/gitlab/github_import/importer/issues_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/issues_importer_spec.rb
@@ -96,7 +96,7 @@ RSpec.describe Gitlab::GithubImport::Importer::IssuesImporter, feature_category:
expect(Gitlab::GithubImport::ImportIssueWorker)
.to receive(:perform_in)
- .with(1, project.id, an_instance_of(Hash), an_instance_of(String))
+ .with(an_instance_of(Float), project.id, an_instance_of(Hash), an_instance_of(String))
waiter = importer.parallel_import
diff --git a/spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb b/spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb
index a5ec39b4177..eaf4d41df43 100644
--- a/spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb
@@ -123,7 +123,7 @@ RSpec.describe Gitlab::GithubImport::Importer::LfsObjectsImporter, feature_categ
end
expect(Gitlab::GithubImport::ImportLfsObjectWorker).to receive(:perform_in)
- .with(1, project.id, an_instance_of(Hash), an_instance_of(String))
+ .with(an_instance_of(Float), project.id, an_instance_of(Hash), an_instance_of(String))
waiter = importer.parallel_import
diff --git a/spec/lib/gitlab/github_import/importer/notes_importer_spec.rb b/spec/lib/gitlab/github_import/importer/notes_importer_spec.rb
index 92d3071c826..722470cbc1d 100644
--- a/spec/lib/gitlab/github_import/importer/notes_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/notes_importer_spec.rb
@@ -88,7 +88,7 @@ RSpec.describe Gitlab::GithubImport::Importer::NotesImporter, feature_category:
.and_yield(github_comment)
expect(Gitlab::GithubImport::ImportNoteWorker).to receive(:perform_in)
- .with(1, project.id, an_instance_of(Hash), an_instance_of(String))
+ .with(an_instance_of(Float), project.id, an_instance_of(Hash), an_instance_of(String))
waiter = importer.parallel_import
diff --git a/spec/lib/gitlab/github_import/importer/protected_branches_importer_spec.rb b/spec/lib/gitlab/github_import/importer/protected_branches_importer_spec.rb
index b0892767fb3..b2fc1bea39e 100644
--- a/spec/lib/gitlab/github_import/importer/protected_branches_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/protected_branches_importer_spec.rb
@@ -145,7 +145,7 @@ RSpec.describe Gitlab::GithubImport::Importer::ProtectedBranchesImporter, featur
it 'imports each protected branch in parallel' do
expect(Gitlab::GithubImport::ImportProtectedBranchWorker)
.to receive(:perform_in)
- .with(1, project.id, an_instance_of(Hash), an_instance_of(String))
+ .with(an_instance_of(Float), project.id, an_instance_of(Hash), an_instance_of(String))
expect(Gitlab::GithubImport::ObjectCounter)
.to receive(:increment).with(project, :protected_branch, :fetched)
@@ -166,7 +166,7 @@ RSpec.describe Gitlab::GithubImport::Importer::ProtectedBranchesImporter, featur
# when user has no admin rights on repo
let(:unknown_protection_branch) { branch_struct.new(name: 'development', protection: nil) }
- let(:page_counter) { instance_double(Gitlab::GithubImport::PageCounter) }
+ let(:page_counter) { instance_double(Gitlab::Import::PageCounter) }
before do
allow(client).to receive(:branches).with(project.import_source)
diff --git a/spec/lib/gitlab/github_import/importer/pull_requests/review_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_requests/review_importer_spec.rb
index 6846c99fb63..1651774b5ce 100644
--- a/spec/lib/gitlab/github_import/importer/pull_requests/review_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/pull_requests/review_importer_spec.rb
@@ -30,6 +30,12 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequests::ReviewImporter,
expect(merge_request.reviewers).to contain_exactly(author)
end
+ context 'when add_reviewer option is false' do
+ it 'does not change Merge Request reviewers' do
+ expect { subject.execute(add_reviewer: false) }.not_to change { MergeRequestReviewer.count }
+ end
+ end
+
context 'when reviewer already exists' do
before do
create(
@@ -309,6 +315,7 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequests::ReviewImporter,
extra.reverse_merge(
author: { id: 999, login: 'author' },
merge_request_id: merge_request.id,
+ merge_request_iid: merge_request.iid,
review_type: type,
note: 'note',
submitted_at: submitted_at.to_s
diff --git a/spec/lib/gitlab/github_import/importer/pull_requests/review_requests_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_requests/review_requests_importer_spec.rb
index 1977815e3a0..7ba88b4fa79 100644
--- a/spec/lib/gitlab/github_import/importer/pull_requests/review_requests_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/pull_requests/review_requests_importer_spec.rb
@@ -116,10 +116,10 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequests::ReviewRequestsImpor
it 'schedule import for each merge request reviewers' do
expect(Gitlab::GithubImport::PullRequests::ImportReviewRequestWorker)
- .to receive(:perform_in).with(1, *expected_worker_payload.first)
+ .to receive(:perform_in).with(an_instance_of(Float), *expected_worker_payload.first)
expect(Gitlab::GithubImport::PullRequests::ImportReviewRequestWorker)
- .to receive(:perform_in).with(1, *expected_worker_payload.second)
+ .to receive(:perform_in).with(an_instance_of(Float), *expected_worker_payload.second)
expect(Gitlab::GithubImport::ObjectCounter)
.to receive(:increment).twice.with(project, :pull_request_review_request, :fetched)
@@ -137,7 +137,7 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequests::ReviewRequestsImpor
it "doesn't schedule import this merge request reviewers" do
expect(Gitlab::GithubImport::PullRequests::ImportReviewRequestWorker)
- .to receive(:perform_in).with(1, *expected_worker_payload.second)
+ .to receive(:perform_in).with(an_instance_of(Float), *expected_worker_payload.second)
expect(Gitlab::GithubImport::ObjectCounter)
.to receive(:increment).once.with(project, :pull_request_review_request, :fetched)
diff --git a/spec/lib/gitlab/github_import/importer/pull_requests/reviews_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_requests/reviews_importer_spec.rb
index f5779f300b8..94248f60a0b 100644
--- a/spec/lib/gitlab/github_import/importer/pull_requests/reviews_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/pull_requests/reviews_importer_spec.rb
@@ -69,7 +69,7 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequests::ReviewsImporter, fe
end
it 'skips cached pages' do
- Gitlab::GithubImport::PageCounter
+ Gitlab::Import::PageCounter
.new(project, "merge_request/#{merge_request.id}/pull_request_reviews")
.set(2)
diff --git a/spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb
index 1a0adbbe3a3..4c6b6a81d35 100644
--- a/spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb
@@ -106,7 +106,7 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestsImporter, feature_cat
expect(Gitlab::GithubImport::ImportPullRequestWorker)
.to receive(:perform_in)
- .with(1, project.id, an_instance_of(Hash), an_instance_of(String))
+ .with(an_instance_of(Float), project.id, an_instance_of(Hash), an_instance_of(String))
waiter = importer.parallel_import
diff --git a/spec/lib/gitlab/github_import/importer/replay_events_importer_spec.rb b/spec/lib/gitlab/github_import/importer/replay_events_importer_spec.rb
new file mode 100644
index 00000000000..2b21232c642
--- /dev/null
+++ b/spec/lib/gitlab/github_import/importer/replay_events_importer_spec.rb
@@ -0,0 +1,139 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::Importer::ReplayEventsImporter, feature_category: :importers do
+ let_it_be(:association) { create(:merged_merge_request) }
+ let_it_be(:project) { association.project }
+ let(:user1) { build(:user1) }
+ let(:user2) { build(:user2) }
+ let(:user3) { build(:user3) }
+ let(:client) { instance_double(Gitlab::GithubImport::Client) }
+
+ let(:representation) do
+ Gitlab::GithubImport::Representation::ReplayEvent.new(
+ issuable_type: association.class.name.to_s, issuable_iid: association.iid
+ )
+ end
+
+ let(:events) do
+ [
+ {
+ requested_reviewer: { id: 1, login: 'user1' },
+ event: 'review_requested'
+ },
+ {
+ requested_reviewer: { id: 1, login: 'user1' },
+ event: 'review_request_removed'
+ },
+ {
+ requested_reviewer: { id: 2, login: 'user2' },
+ event: 'review_requested'
+ },
+ {
+ requested_reviewer: { id: 2, login: 'user2' },
+ event: 'review_request_removed'
+ },
+ {
+ requested_reviewer: { id: 2, login: 'user2' },
+ event: 'review_requested'
+ },
+ {
+ requested_reviewer: { id: 3, login: 'user3' },
+ event: 'review_requested'
+ }
+ ]
+ end
+
+ subject(:importer) { described_class.new(representation, project, client) }
+
+ describe '#execute' do
+ before do
+ representations = events.map { |e| Gitlab::GithubImport::Representation::IssueEvent.from_json_hash(e) }
+
+ allow_next_instance_of(Gitlab::GithubImport::EventsCache) do |events_cache|
+ allow(events_cache).to receive(:events).with(association).and_return(representations)
+ end
+ end
+
+ context 'when association is a MergeRequest' do
+ it 'imports reviewers' do
+ representation = instance_double(Gitlab::GithubImport::Representation::PullRequests::ReviewRequests)
+
+ expect(Gitlab::GithubImport::Representation::PullRequests::ReviewRequests).to receive(:from_json_hash).with(
+ merge_request_id: association.id,
+ merge_request_iid: association.iid,
+ users: [
+ { id: 2, login: 'user2' },
+ { id: 3, login: 'user3' }
+ ]
+ ).and_return(representation)
+
+ expect_next_instance_of(
+ Gitlab::GithubImport::Importer::PullRequests::ReviewRequestImporter, anything, project, client
+ ) do |review_impoter|
+ expect(review_impoter).to receive(:execute)
+ end
+
+ importer.execute
+ end
+
+ context 'when reviewer is a team' do
+ let(:events) do
+ [
+ {
+ event: 'review_requested',
+ requested_team: { name: 'backend-team' }
+ },
+ {
+ event: 'review_requested',
+ requested_team: { name: 'frontend-team' }
+ },
+ {
+ event: 'review_request_removed',
+ requested_team: { name: 'frontend-team' }
+ }
+ ]
+ end
+
+ it 'ignores the events and do not assign the reviewers' do
+ expect(Gitlab::GithubImport::Representation::PullRequests::ReviewRequests).to receive(:from_json_hash).with(
+ merge_request_id: association.id,
+ merge_request_iid: association.iid,
+ users: []
+ ).and_call_original
+
+ importer.execute
+ end
+ end
+ end
+
+ context 'when association is not found' do
+ let(:representation) do
+ Gitlab::GithubImport::Representation::ReplayEvent.new(
+ issuable_type: association.class.name.to_s, issuable_iid: -1
+ )
+ end
+
+ it 'does not read events' do
+ expect(Gitlab::GithubImport::EventsCache).not_to receive(:new)
+
+ importer.execute
+ end
+ end
+
+ context 'when issueable type is not supported' do
+ let(:representation) do
+ Gitlab::GithubImport::Representation::ReplayEvent.new(
+ issuable_type: 'Issue', issuable_iid: association.iid
+ )
+ end
+
+ it 'does not read events' do
+ expect(Gitlab::GithubImport::EventsCache).not_to receive(:new)
+
+ importer.execute
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/github_import/importer/single_endpoint_diff_notes_importer_spec.rb b/spec/lib/gitlab/github_import/importer/single_endpoint_diff_notes_importer_spec.rb
index 6fe0494d7cd..d2e63eba954 100644
--- a/spec/lib/gitlab/github_import/importer/single_endpoint_diff_notes_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/single_endpoint_diff_notes_importer_spec.rb
@@ -53,7 +53,7 @@ RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointDiffNotesImporter d
end
it 'skips cached pages' do
- Gitlab::GithubImport::PageCounter
+ Gitlab::Import::PageCounter
.new(project, "merge_request/#{merge_request.id}/pull_request_comments")
.set(2)
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 91f89f0779c..19142b94519 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
@@ -3,9 +3,9 @@
require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter, feature_category: :importers do
- let(:client) { double }
+ let(:client) { Gitlab::GithubImport::Client.new('token') }
- let_it_be(:project) { create(:project, :import_started, import_source: 'http://somegithub.com') }
+ let_it_be(:project) { create(:project, :import_started, import_source: 'foo/bar') }
let!(:issuable) { create(:issue, project: project) }
@@ -88,23 +88,32 @@ RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter
describe '#each_object_to_import', :clean_gitlab_redis_cache do
let(:issue_event) do
struct = Struct.new(:id, :event, :created_at, :issue, keyword_init: true)
- struct.new(id: 1, event: 'closed', created_at: '2022-04-26 18:30:53 UTC')
+ struct.new(id: 1, event: event_name, created_at: '2022-04-26 18:30:53 UTC')
end
+ let(:event_name) { 'closed' }
+
+ let(:page_events) { [issue_event] }
+
let(:page) do
instance_double(
Gitlab::GithubImport::Client::Page,
- number: 1, objects: [issue_event]
+ number: 1, objects: page_events
)
end
- let(:page_counter) { instance_double(Gitlab::GithubImport::PageCounter) }
+ let(:page_counter) { instance_double(Gitlab::Import::PageCounter) }
+
+ let(:extended_events) { true }
before do
allow(Gitlab::Redis::SharedState).to receive(:with).and_return('OK')
allow(client).to receive(:each_page).once.with(:issue_timeline,
project.import_source, issuable.iid, { state: 'all', sort: 'created', direction: 'asc', page: 1 }
).and_yield(page)
+ allow_next_instance_of(Gitlab::GithubImport::Settings) do |setting|
+ allow(setting).to receive(:extended_events?).and_return(extended_events)
+ end
end
context 'with issues' do
@@ -152,7 +161,7 @@ RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter
end
it 'triggers page number increment' do
- expect(Gitlab::GithubImport::PageCounter)
+ expect(Gitlab::Import::PageCounter)
.to receive(:new).with(project, 'issues/1/issue_timeline')
.and_return(page_counter)
expect(page_counter).to receive(:current).and_return(1)
@@ -166,7 +175,7 @@ RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter
context 'when page is already processed' do
before do
- page_counter = Gitlab::GithubImport::PageCounter.new(
+ page_counter = Gitlab::Import::PageCounter.new(
project, subject.page_counter_id(issuable)
)
page_counter.set(page.number)
@@ -190,10 +199,7 @@ RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter
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
+ let(:event_name) { 'not_supported_event' }
it "doesn't process this event" do
counter = 0
@@ -201,5 +207,188 @@ RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter
expect(counter).to eq 0
end
end
+
+ describe 'increment object counter' do
+ it 'increments counter' do
+ expect(Gitlab::GithubImport::ObjectCounter).to receive(:increment).with(project, :issue_event, :fetched)
+
+ subject.each_object_to_import { |event| event }
+ end
+
+ context 'when event should increment a mapped fetched counter' do
+ before do
+ stub_const('Gitlab::GithubImport::Importer::IssueEventImporter::EVENT_COUNTER_MAP', {
+ 'closed' => 'custom_type'
+ })
+ end
+
+ it 'increments the mapped fetched counter' do
+ expect(Gitlab::GithubImport::ObjectCounter).to receive(:increment).with(project, 'custom_type', :fetched)
+
+ subject.each_object_to_import { |event| event }
+ end
+
+ context 'when extended_events is disabled' do
+ let(:extended_events) { false }
+
+ it 'increments the issue_event fetched counter' do
+ expect(Gitlab::GithubImport::ObjectCounter).to receive(:increment).with(project, :issue_event, :fetched)
+
+ subject.each_object_to_import { |event| event }
+ end
+ end
+ end
+ end
+
+ describe 'save events' do
+ shared_examples 'saves event' do
+ it 'saves event' do
+ expect(Gitlab::GithubImport::Representation::IssueEvent).to receive(:from_api_response).with(issue_event.to_h)
+ .and_call_original
+
+ expect_next_instance_of(Gitlab::GithubImport::EventsCache) do |events_cache|
+ expect(events_cache).to receive(:add).with(
+ issuable,
+ an_instance_of(Gitlab::GithubImport::Representation::IssueEvent)
+ )
+ end
+
+ subject.each_object_to_import { |event| event }
+ end
+ end
+
+ context 'when event is review_requested' do
+ let(:event_name) { 'review_requested' }
+
+ it_behaves_like 'saves event'
+ end
+
+ context 'when event is review_request_removed' do
+ let(:event_name) { 'review_request_removed' }
+
+ it_behaves_like 'saves event'
+ end
+
+ context 'when event is closed' do
+ let(:event_name) { 'closed' }
+
+ it 'does not save event' do
+ expect_next_instance_of(Gitlab::GithubImport::EventsCache) do |events_cache|
+ expect(events_cache).not_to receive(:add)
+ end
+
+ subject.each_object_to_import { |event| event }
+ end
+ end
+
+ context 'when extended_events is disabled' do
+ let(:event_name) { 'review_requested' }
+ let(:extended_events) { false }
+
+ it 'does not save event' do
+ expect(Gitlab::GithubImport::EventsCache).not_to receive(:new)
+
+ subject.each_object_to_import { |event| event }
+ end
+ end
+ end
+
+ describe 'after batch processed' do
+ context 'when events should be replayed' do
+ let(:event_name) { 'review_requested' }
+
+ it 'enqueues worker to replay events' do
+ allow(Gitlab::JobWaiter).to receive(:generate_key).and_return('job_waiter_key')
+
+ expect(Gitlab::GithubImport::ReplayEventsWorker).to receive(:perform_async)
+ .with(
+ project.id,
+ { 'issuable_type' => issuable.class.name.to_s, 'issuable_iid' => issuable.iid },
+ 'job_waiter_key'
+ )
+
+ subject.each_object_to_import { |event| event }
+ end
+ end
+
+ context 'when events are not relevant' do
+ let(:event_name) { 'closed' }
+
+ it 'does not replay events' do
+ expect(Gitlab::GithubImport::ReplayEventsWorker).not_to receive(:perform_async)
+
+ subject.each_object_to_import { |event| event }
+ end
+ end
+
+ context 'when extended_events is disabled' do
+ let(:extended_events) { false }
+
+ it 'does not replay events' do
+ expect(Gitlab::GithubImport::ReplayEventsWorker).not_to receive(:perform_async)
+
+ subject.each_object_to_import { |event| event }
+ end
+ end
+ end
+ end
+
+ describe '#execute', :clean_gitlab_redis_cache do
+ let(:extended_events) { false }
+
+ before do
+ allow_next_instance_of(Gitlab::GithubImport::Settings) do |setting|
+ allow(setting).to receive(:extended_events?).and_return(extended_events)
+ end
+
+ stub_request(:get, 'https://api.github.com/rate_limit')
+ .to_return(status: 200, headers: { 'X-RateLimit-Limit' => 5000, 'X-RateLimit-Remaining' => 5000 })
+
+ events = [
+ {
+ id: 1,
+ event: 'review_requested',
+ created_at: '2022-04-26 18:30:53 UTC',
+ issue: {
+ number: issuable.iid,
+ pull_request: true
+ }
+ }
+ ]
+
+ endpoint = 'https://api.github.com/repos/foo/bar/issues/1/timeline' \
+ '?direction=asc&page=1&per_page=100&sort=created&state=all'
+
+ stub_request(:get, endpoint)
+ .to_return(status: 200, body: events.to_json, headers: { 'Content-Type' => 'application/json' })
+ end
+
+ context 'when extended_events is disabled' do
+ it 'enqueues importer worker' do
+ expect { subject.execute }.to change { Gitlab::GithubImport::ReplayEventsWorker.jobs.size }.by(0)
+ .and change { Gitlab::GithubImport::ImportIssueEventWorker.jobs.size }.by(1)
+ end
+
+ it 'returns job waiter with the correct remaining jobs count' do
+ job_waiter = subject.execute
+
+ expect(job_waiter.jobs_remaining).to eq(1)
+ end
+ end
+
+ context 'when extended_events is enabled' do
+ let(:extended_events) { true }
+
+ it 'enqueues importer worker and replay worker' do
+ expect { subject.execute }.to change { Gitlab::GithubImport::ReplayEventsWorker.jobs.size }.by(1)
+ .and change { Gitlab::GithubImport::ImportIssueEventWorker.jobs.size }.by(1)
+ end
+
+ it 'returns job waiter with the correct remaining jobs count' do
+ job_waiter = subject.execute
+
+ expect(job_waiter.jobs_remaining).to eq(2)
+ end
+ end
end
end
diff --git a/spec/lib/gitlab/github_import/importer/single_endpoint_issue_notes_importer_spec.rb b/spec/lib/gitlab/github_import/importer/single_endpoint_issue_notes_importer_spec.rb
index 88613244c8b..c0f0d86d625 100644
--- a/spec/lib/gitlab/github_import/importer/single_endpoint_issue_notes_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/single_endpoint_issue_notes_importer_spec.rb
@@ -52,7 +52,7 @@ RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointIssueNotesImporter
end
it 'skips cached pages' do
- Gitlab::GithubImport::PageCounter
+ Gitlab::Import::PageCounter
.new(project, "issue/#{issue.id}/issue_comments")
.set(2)
diff --git a/spec/lib/gitlab/github_import/importer/single_endpoint_merge_request_notes_importer_spec.rb b/spec/lib/gitlab/github_import/importer/single_endpoint_merge_request_notes_importer_spec.rb
index 601cd7a8f15..2d981a3d14f 100644
--- a/spec/lib/gitlab/github_import/importer/single_endpoint_merge_request_notes_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/single_endpoint_merge_request_notes_importer_spec.rb
@@ -53,7 +53,7 @@ RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointMergeRequestNotesIm
end
it 'skips cached pages' do
- Gitlab::GithubImport::PageCounter
+ Gitlab::Import::PageCounter
.new(project, "merge_request/#{merge_request.id}/issue_comments")
.set(2)