Commit e8a9e822 authored by Shinya Maeda's avatar Shinya Maeda

Merge branch '31869_remove_duplicates_from_releases_importer' into 'master'

Remove Duplicates from Releases Importer

See merge request gitlab-org/gitlab!78904
parents 032df049 6e662f74
...@@ -21,10 +21,12 @@ module Gitlab ...@@ -21,10 +21,12 @@ module Gitlab
end end
def already_imported?(release) def already_imported?(release)
existing_tags.include?(release.tag_name) existing_tags.include?(release.tag_name) || release.tag_name.nil?
end end
def build(release) def build(release)
existing_tags.add(release.tag_name)
{ {
name: release.name, name: release.name,
tag: release.tag_name, tag: release.tag_name,
......
...@@ -25,7 +25,7 @@ module Gitlab ...@@ -25,7 +25,7 @@ module Gitlab
end end
def valid? def valid?
!raw_data.draft !raw_data.draft && raw_data.tag_name.present?
end end
end end
end end
......
...@@ -52,6 +52,12 @@ RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter do ...@@ -52,6 +52,12 @@ RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter do
expect { importer.execute }.to change { Release.count }.by(1) expect { importer.execute }.to change { Release.count }.by(1)
end 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 end
describe '#build_releases' do describe '#build_releases' do
...@@ -79,6 +85,24 @@ RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter do ...@@ -79,6 +85,24 @@ RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter do
expect(release[:description]).to eq('Release for tag 1.0') expect(release[:description]).to eq('Release for tag 1.0')
end 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 end
describe '#build' do describe '#build' do
......
...@@ -63,5 +63,13 @@ RSpec.describe Gitlab::LegacyGithubImport::ReleaseFormatter do ...@@ -63,5 +63,13 @@ RSpec.describe Gitlab::LegacyGithubImport::ReleaseFormatter do
expect(release.valid?).to eq false expect(release.valid?).to eq false
end end
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
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