Skip to content

Commit

Permalink
Decision Applier: Merge manual and system packages
Browse files Browse the repository at this point in the history
This will enable merging manual added dependencies with
detected dependencies. This is usefull if a package will
be detected but e.g. license information is missing.
This change will use data from decision (homepage, approval, license)
and apply it to system package maching the manual one.
Currently manual decisions override the whole system package
which results in losing information (e.g. package_manager)
  • Loading branch information
forelabs committed May 12, 2020
1 parent 204798c commit c690532
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/license_finder/decision_applier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module LicenseFinder
class DecisionApplier
def initialize(options)
@decisions = options.fetch(:decisions)
@all_packages = decisions.packages + options.fetch(:packages)
@all_packages = options.fetch(:packages).to_set + @decisions.packages.to_set
@acknowledged = apply_decisions
end

Expand All @@ -28,10 +28,14 @@ def any_packages?

def apply_decisions
all_packages
.map { |package| with_decided_licenses(package) }
.map { |package| with_approval(package) }
.map { |package| with_homepage(package) }
.reject { |package| ignored?(package) }
.map do |package|
with_homepage(
with_approval(
with_decided_licenses(package)
)
)
end
end

def ignored?(package)
Expand Down
9 changes: 9 additions & 0 deletions spec/lib/license_finder/decision_applier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ module LicenseFinder

describe '#acknowledged' do
it 'combines manual and system packages' do
decision_applier = described_class.new(
decisions: Decisions.new.add_package('system', nil).license('system', 'MIT'),
packages: [Package.new('system', '1.0.0')]
)
package = decision_applier.acknowledged.first
expect([package.name, package.version, package.licenses.first.name]).to match_array %w[system 1.0.0 MIT]
end

it 'merges manual packages with system packages' do
decision_applier = described_class.new(
decisions: Decisions.new.add_package('manual', nil),
packages: [Package.new('system')]
Expand Down

0 comments on commit c690532

Please sign in to comment.