Commit 37fbd5b3 authored by Aleksei Lipniagov's avatar Aleksei Lipniagov

Merge branch 'kassio/import-status-api' into 'master'

Add line number and import_type to the import status API

See merge request gitlab-org/gitlab!75331
parents f5fbcdac 7d784019
...@@ -10,6 +10,7 @@ module API ...@@ -10,6 +10,7 @@ module API
end end
expose :relation_key, as: :relation_name expose :relation_key, as: :relation_name
expose :relation_index, as: :line_number
end end
end end
end end
...@@ -4,6 +4,7 @@ module API ...@@ -4,6 +4,7 @@ module API
module Entities module Entities
class ProjectImportStatus < ProjectIdentity class ProjectImportStatus < ProjectIdentity
expose :import_status expose :import_status
expose :import_type
expose :correlation_id do |project, _options| expose :correlation_id do |project, _options|
project.import_state&.correlation_id project.import_state&.correlation_id
end end
......
...@@ -107,7 +107,7 @@ module API ...@@ -107,7 +107,7 @@ module API
params do params do
requires :id, type: String, desc: 'The ID of a project' requires :id, type: String, desc: 'The ID of a project'
end end
desc 'Get a project export status' do desc 'Get a project import status' do
detail 'This feature was introduced in GitLab 10.6.' detail 'This feature was introduced in GitLab 10.6.'
success Entities::ProjectImportStatus success Entities::ProjectImportStatus
end end
......
...@@ -10,6 +10,8 @@ FactoryBot.define do ...@@ -10,6 +10,8 @@ FactoryBot.define do
exception_class { 'RuntimeError' } exception_class { 'RuntimeError' }
exception_message { 'Something went wrong' } exception_message { 'Something went wrong' }
source { 'method_call' } source { 'method_call' }
relation_key { 'issues' }
relation_index { 1 }
correlation_id_value { SecureRandom.uuid } correlation_id_value { SecureRandom.uuid }
trait :hard_failure do trait :hard_failure do
......
...@@ -16,7 +16,8 @@ RSpec.describe API::Entities::ProjectImportFailedRelation do ...@@ -16,7 +16,8 @@ RSpec.describe API::Entities::ProjectImportFailedRelation do
exception_class: import_failure.exception_class, exception_class: import_failure.exception_class,
exception_message: nil, exception_message: nil,
relation_name: import_failure.relation_key, relation_name: import_failure.relation_key,
source: import_failure.source source: import_failure.source,
line_number: import_failure.relation_index
) )
end end
end end
......
...@@ -2,17 +2,18 @@ ...@@ -2,17 +2,18 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe API::Entities::ProjectImportStatus do RSpec.describe API::Entities::ProjectImportStatus, :aggregate_failures do
describe '#as_json' do describe '#as_json' do
subject { entity.as_json } subject { entity.as_json }
let(:correlation_id) { 'cid' } let(:correlation_id) { 'cid' }
context 'when no import state exists' do context 'when no import state exists' do
let(:entity) { described_class.new(build(:project)) } let(:entity) { described_class.new(build(:project, import_type: 'import_type')) }
it 'includes basic fields and no failures' do it 'includes basic fields and no failures' do
expect(subject[:import_status]).to eq('none') expect(subject[:import_status]).to eq('none')
expect(subject[:import_type]).to eq('import_type')
expect(subject[:correlation_id]).to be_nil expect(subject[:correlation_id]).to be_nil
expect(subject[:import_error]).to be_nil expect(subject[:import_error]).to be_nil
expect(subject[:failed_relations]).to eq([]) expect(subject[:failed_relations]).to eq([])
...@@ -20,11 +21,12 @@ RSpec.describe API::Entities::ProjectImportStatus do ...@@ -20,11 +21,12 @@ RSpec.describe API::Entities::ProjectImportStatus do
end end
context 'when import has not finished yet' do context 'when import has not finished yet' do
let(:project) { create(:project, :import_scheduled, import_correlation_id: correlation_id) } let(:project) { create(:project, :import_scheduled, import_type: 'import_type', import_correlation_id: correlation_id) }
let(:entity) { described_class.new(project) } let(:entity) { described_class.new(project, import_type: 'import_type') }
it 'includes basic fields and no failures', :aggregate_failures do it 'includes basic fields and no failures' do
expect(subject[:import_status]).to eq('scheduled') expect(subject[:import_status]).to eq('scheduled')
expect(subject[:import_type]).to eq('import_type')
expect(subject[:correlation_id]).to eq(correlation_id) expect(subject[:correlation_id]).to eq(correlation_id)
expect(subject[:import_error]).to be_nil expect(subject[:import_error]).to be_nil
expect(subject[:failed_relations]).to eq([]) expect(subject[:failed_relations]).to eq([])
...@@ -32,25 +34,43 @@ RSpec.describe API::Entities::ProjectImportStatus do ...@@ -32,25 +34,43 @@ RSpec.describe API::Entities::ProjectImportStatus do
end end
context 'when import has finished with failed relations' do context 'when import has finished with failed relations' do
let(:project) { create(:project, :import_finished, import_correlation_id: correlation_id) } let(:project) { create(:project, :import_finished, import_type: 'import_type', import_correlation_id: correlation_id) }
let(:entity) { described_class.new(project) } let(:entity) { described_class.new(project) }
it 'includes basic fields with failed relations', :aggregate_failures do it 'includes basic fields with failed relations' do
create(:import_failure, :hard_failure, project: project, correlation_id_value: correlation_id) create(
:import_failure,
:hard_failure,
project: project,
correlation_id_value: correlation_id,
relation_key: 'issues',
relation_index: 1
)
# Doesn't show soft failures
create(:import_failure, :soft_failure)
expect(subject[:import_status]).to eq('finished') expect(subject[:import_status]).to eq('finished')
expect(subject[:import_type]).to eq('import_type')
expect(subject[:correlation_id]).to eq(correlation_id) expect(subject[:correlation_id]).to eq(correlation_id)
expect(subject[:import_error]).to be_nil expect(subject[:import_error]).to be_nil
expect(subject[:failed_relations]).not_to be_empty expect(subject[:failed_relations].length).to eq(1)
failure = subject[:failed_relations].last
expect(failure[:exception_class]).to eq('RuntimeError')
expect(failure[:source]).to eq('method_call')
expect(failure[:relation_name]).to eq('issues')
expect(failure[:line_number]).to eq(1)
end end
end end
context 'when import has failed' do context 'when import has failed' do
let(:project) { create(:project, :import_failed, import_correlation_id: correlation_id, import_last_error: 'error') } let(:project) { create(:project, :import_failed, import_type: 'import_type', import_correlation_id: correlation_id, import_last_error: 'error') }
let(:entity) { described_class.new(project) } let(:entity) { described_class.new(project) }
it 'includes basic fields with import error', :aggregate_failures do it 'includes basic fields with import error' do
expect(subject[:import_status]).to eq('failed') expect(subject[:import_status]).to eq('failed')
expect(subject[:import_type]).to eq('import_type')
expect(subject[:correlation_id]).to eq(correlation_id) expect(subject[:correlation_id]).to eq(correlation_id)
expect(subject[:import_error]).to eq('error') expect(subject[:import_error]).to eq('error')
expect(subject[:failed_relations]).to eq([]) expect(subject[:failed_relations]).to eq([])
......
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