Skip to content

Commit

Permalink
[Added] --homepage option to dependencies add
Browse files Browse the repository at this point in the history
- Uses most recently added homepage for dependencies

[finish #164251236]

Signed-off-by: Vikram Yadav <vyadav@pivotal.io>
  • Loading branch information
Serafima Ostrovskaya authored and Pivotal committed May 28, 2019
1 parent 3aea529 commit b7f7ef8
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ you should manually research what the actual license is. When you
have established the real license, you can record it with:

```sh
$ license_finder licenses add my_unknown_dependency MIT
$ license_finder licenses add my_unknown_dependency MIT --homepage="www.unknown-code.org"
```

This command would assign the MIT license to the dependency
`my_unknown_dependency`.
`my_unknown_dependency`. It will also set its homepage to `wwww.unknown-code.org`.


### Adding Hidden Dependencies
Expand Down
7 changes: 7 additions & 0 deletions features/features/configure/add_dependencies_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
expect(developer).not_to be_seeing 'manual_dep'
end

specify 'can be simultaneously homepaged' do
developer.execute_command 'license_finder dependencies add manual Whatever --homepage=some-homepage'

developer.run_license_finder(nil, '--columns="name" "homepage"')
expect(developer).to be_seeing 'manual, some-homepage'
end

specify 'appear in the CLI' do
developer.execute_command 'license_finder dependencies add manual_dep Whatever'
expect(developer).to be_seeing 'manual_dep'
Expand Down
4 changes: 3 additions & 1 deletion lib/license_finder/cli/dependencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ class Dependencies < Base
include MakesDecisions

method_option :approve, type: :boolean, desc: 'Approve the added dependency'
method_option :homepage, type: :string, desc: 'Source of the added dependency'
auditable
desc 'add DEPENDENCY LICENSE [VERSION] [--approve]', 'Add a dependency that is not managed by a package manager, optionally approving it at the same time'
desc 'add DEPENDENCY LICENSE [VERSION] [--homepage=HOMEPAGE] [--approve]', 'Add a dependency that is not managed by a package manager, optionally approving it at the same time'
def add(name, license, version = nil)
modifying do
decisions
.add_package(name, version, txn)
.license(name, license, txn)
decisions.homepage(name, options[:homepage], txn) if options[:homepage]
decisions.approve(name, txn) if options[:approve]
end
if options[:approve]
Expand Down
7 changes: 7 additions & 0 deletions lib/license_finder/decision_applier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ 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) }
end

Expand All @@ -45,6 +46,12 @@ def with_decided_licenses(package)
package
end

def with_homepage(package)
homepage = decisions.homepage_of(package.name)
package.homepage = homepage if homepage
package
end

def with_approval(package)
if package.licenses.all? { |license| decisions.blacklisted?(license) }
package.blacklisted!
Expand Down
11 changes: 11 additions & 0 deletions lib/license_finder/decisions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def licenses_of(name)
@licenses[name]
end

def homepage_of(name)
@homepages[name]
end

def approval_of(name, version = nil)
if !@approvals.key?(name)
nil
Expand Down Expand Up @@ -62,6 +66,7 @@ def initialize
@decisions = []
@packages = Set.new
@licenses = Hash.new { |h, k| h[k] = Set.new }
@homepages = {}
@approvals = {}
@whitelisted = Set.new
@blacklisted = Set.new
Expand Down Expand Up @@ -93,6 +98,12 @@ def unlicense(name, lic, txn = {})
self
end

def homepage(name, homepage, txn = {})
@decisions << [:homepage, name, homepage, txn]
@homepages[name] = homepage
self
end

def approve(name, txn = {})
@decisions << [:approve, name, txn]

Expand Down
4 changes: 3 additions & 1 deletion lib/license_finder/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ def initialize(name, version = nil, options = {})

## DESCRIPTION

attr_accessor :homepage

attr_reader :name, :version, :authors,
:summary, :description, :homepage,
:summary, :description,
:children, :parents, :groups

## APPROVAL
Expand Down
9 changes: 9 additions & 0 deletions spec/lib/license_finder/cli/dependencies_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ module CLI
expect(approval.why).to eq 'We really need this'
expect(approval.safe_versions).to eq ['1.0.0.RELEASE']
end

it 'has a --homepage=HOMEPAGE option to add a homepage to the added dependency' do
subject.options = { homepage: 'some-homepage' }
silence_stdout do
subject.add('js_dep', 'MIT')
end
homepage = subject.decisions.homepage_of('js_dep')
expect(homepage).to eq 'some-homepage'
end
end

describe 'remove' do
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/license_finder/decision_applier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ module LicenseFinder
expect(decision_applier.acknowledged.last.licenses).to eq Set.new([License.find_by_name('MIT')])
end

it 'applies decided homepage' do
decisions = Decisions.new
.add_package('manual', nil)
.homepage('manual', 'some-homepage')
decision_applier = described_class.new(decisions: decisions, packages: [])
expect(decision_applier.acknowledged.last.homepage).to eq 'some-homepage'
end

it 'ignores specific packages' do
decisions = Decisions.new
.add_package('manual', nil)
Expand Down
33 changes: 33 additions & 0 deletions spec/lib/license_finder/decisions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ module LicenseFinder
end
end

describe '.homepage' do
it 'will report homepage for a dependency' do
homepage = subject
.homepage('dep', 'home-page/dep')
.homepage_of('dep')
expect(homepage).to eq 'home-page/dep'
end

it 'will report overwritten homepages' do
homepages = subject
.homepage('dep', 'home-page/dep')
.homepage('dep', 'other-page/dep')
.homepage_of('dep')
expect(homepages).to eq 'other-page/dep'
end
end

describe '.approve' do
it 'will report a dependency as approved' do
decisions = subject.approve('dep')
Expand Down Expand Up @@ -302,6 +319,22 @@ def roundtrip(decisions)
expect(licenses).to eq [License.find_by_name('GPL')].to_set
end

it 'can restore homepage' do
homepage = roundtrip(
subject.homepage('dep', 'home-page/dep')
).homepage_of('dep')
expect(homepage).to eq 'home-page/dep'
end

it 'can restore overwritten homepages' do
homepage = roundtrip(
subject
.homepage('dep', 'home-page/dep')
.homepage('dep', 'other-page/dep')
).homepage_of('dep')
expect(homepage).to eq 'other-page/dep'
end

it 'can restore approvals without versions' do
time = Time.now.getutc
roundtrip(subject.approve('dep', who: 'Somebody', why: 'Some reason', when: time))
Expand Down

0 comments on commit b7f7ef8

Please sign in to comment.