Commit 6e662f74 authored by Allen Cook's avatar Allen Cook Committed by Shinya Maeda

Update ReleasesImporter to ignore nil/dup tags

Update LegacyBulkInsert to allow ignoring
conflicts on multiple keys / indexes
parent dcb79ad6
......@@ -21,10 +21,12 @@ module Gitlab
end
def already_imported?(release)
existing_tags.include?(release.tag_name)
existing_tags.include?(release.tag_name) || release.tag_name.nil?
end
def build(release)
existing_tags.add(release.tag_name)
{
name: release.name,
tag: release.tag_name,
......
......@@ -25,7 +25,7 @@ module Gitlab
end
def valid?
!raw_data.draft
!raw_data.draft && raw_data.tag_name.present?
end
end
end
......
......@@ -52,6 +52,12 @@ RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter do
expect { importer.execute }.to change { Release.count }.by(1)
end
it 'is idempotent' do
allow(importer).to receive(:each_release).and_return([github_release])
expect { importer.execute }.to change { Release.count }.by(1)
expect { importer.execute }.to change { Release.count }.by(0) # Idempotency check
end
end
describe '#build_releases' do
......@@ -79,6 +85,24 @@ RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter do
expect(release[:description]).to eq('Release for tag 1.0')
end
it 'does not create releases that have a NULL tag' do
null_tag_release = double(
name: 'NULL Test',
tag_name: nil
)
expect(importer).to receive(:each_release).and_return([null_tag_release])
expect(importer.build_releases).to be_empty
end
it 'does not create duplicate release tags' do
expect(importer).to receive(:each_release).and_return([github_release, github_release])
releases = importer.build_releases
expect(releases.length).to eq(1)
expect(releases[0][:description]).to eq('This is my release')
end
end
describe '#build' do
......
......@@ -63,5 +63,13 @@ RSpec.describe Gitlab::LegacyGithubImport::ReleaseFormatter do
expect(release.valid?).to eq false
end
end
context 'when release has NULL tag' do
let(:raw_data) { double(base_data.merge(tag_name: '')) }
it 'returns false' do
expect(release.valid?).to eq false
end
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