Commit 653f5936 authored by Sean McGivern's avatar Sean McGivern

Merge branch '199264-import-software-licenses' into 'master'

Correct licenses with an invalid SPDX identifier

See merge request gitlab-org/gitlab!24829
parents 75db5147 2b705677
......@@ -8,8 +8,8 @@ class ImportSoftwareLicensesWorker
def perform
catalogue.each do |spdx_license|
if unknown_licenses[spdx_license.name]
unknown_licenses_with(spdx_license.name)
if licenses[spdx_license.name]
licenses_with(spdx_license.name)
.update_all(spdx_identifier: spdx_license.id)
else
SoftwareLicense.safe_find_or_create_by!(
......@@ -22,13 +22,13 @@ class ImportSoftwareLicensesWorker
private
def unknown_licenses
@unknown_licenses ||=
unknown_licenses_with(catalogue.map(&:name)).grouped_by_name.count
def licenses
@licenses ||=
licenses_with(catalogue.map(&:name)).grouped_by_name.count
end
def unknown_licenses_with(name)
SoftwareLicense.unknown.by_name(name)
def licenses_with(name)
SoftwareLicense.by_name(name)
end
def catalogue
......
---
title: Update invalid SPDX identifiers in software licenses table
merge_request: 24829
author:
type: fixed
......@@ -39,5 +39,15 @@ describe ImportSoftwareLicensesWorker do
expect { subject.perform }.not_to change(SoftwareLicense, :count)
end
end
context 'when a license has an invalid SPDX identifier' do
before do
apache.update_column(:spdx_identifier, 'invalid')
subject.perform
end
it { expect(apache.reload.spdx_identifier).to eql(spdx_apache_license.id) }
it { expect(SoftwareLicense.pluck(:spdx_identifier)).to contain_exactly(spdx_apache_license.id, spdx_mit_license.id, spdx_bsd_license.id) }
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