licensed 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 188fefd78d80c7a9d36985fde025efada389711a
4
+ data.tar.gz: 9cd69efe41165826cfeca9ba29ab930a9718afbd
5
+ SHA512:
6
+ metadata.gz: bf8b94250ef319e828bf0740056087057e744e3f460f841293c2cef95d8c31dc7f25a484f97b9fbf4a1f3af873a95e6f23f5ea653c9808e868d1a856fb946bb4
7
+ data.tar.gz: 23f5f40eb1620bbae7370a0bde096becd916dd49f76703413939271509d975f612c1c22864f423b8d962934d5b91e54d49829d70e77d116ba3993476b61091f0
@@ -0,0 +1,3 @@
1
+ {
2
+ "cwd": "test/fixtures"
3
+ }
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ test/fixtures/bower_components
11
+ test/fixtures/node_modules
12
+ vendor/licenses
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in licensed.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 GitHub, Inc. and contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,96 @@
1
+ # Licensed
2
+
3
+ Licensed is a Ruby gem to cache and verify the licenses of dependencies.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'licensed', :group => 'development'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ - `licensed cache`: Cache licenses and metadata in `vendor/licenses`
20
+
21
+ - `licensed verify`: Check for issues with the licenses of dependencies. For example:
22
+
23
+ ```
24
+ $ bundle exec licensed verify
25
+ Verifying licenses for 3 dependencies
26
+
27
+ Warnings:
28
+
29
+ vendor/licenses/rubygem/bundler.txt:
30
+ - license needs reviewed: mit.
31
+
32
+ vendor/licenses/rubygem/licensee.txt:
33
+ - missing license data
34
+
35
+ vendor/licenses/bower/jquery.txt:
36
+ - license needs reviewed: mit.
37
+ - cached license data out of date
38
+
39
+ 3 dependencies checked, 3 warnings found.
40
+ ```
41
+
42
+ ### Configuration
43
+
44
+ Configuration is managed by `vendor/licenses/config.yml`.
45
+
46
+ ```yml
47
+ # Dependencies with these licenses are approved by default.
48
+ whitelist:
49
+ - mit
50
+ - apache-2.0
51
+ - bsd-2-clause
52
+ - bsd-3-clause
53
+ - cc0-1.0
54
+
55
+ # These dependencies are explicitly ignored.
56
+ ignored:
57
+ rubygem:
58
+ - some-internal-gem
59
+
60
+ bower:
61
+ - some-internal-package
62
+
63
+ # These dependencies have been reviewed.
64
+ reviewed:
65
+ rubygem:
66
+ - bcrypt-ruby
67
+
68
+ bower:
69
+ - classlist # public domain
70
+ - octicons
71
+ ```
72
+
73
+ ### Sources
74
+
75
+ Dependencies from Bundler, NPM, and Bower will be automatically detected. You can disable any of them in `vendor/licenses/config.yml`:
76
+
77
+ ```yml
78
+ sources:
79
+ rubygem: false
80
+ npm: false
81
+ bower: false
82
+ ```
83
+
84
+ ## Development
85
+
86
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
87
+
88
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
89
+
90
+ ## Contributing
91
+
92
+ Bug reports and pull requests are welcome on GitHub at https://github.com/github/licensed. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
93
+
94
+ ## License
95
+
96
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "licensed"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,11 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Install bower fixtures
8
+ bower install
9
+
10
+ # Install bower fixtures
11
+ cd test/fixtures && npm install
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "licensed/cli"
4
+ Licensed::CLI.start
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ warn "The `licensor` command has been renamed to `licensed` and is deprecated."
4
+
5
+ load File.expand_path("../licensed", __FILE__)
@@ -0,0 +1,39 @@
1
+ require "licensed/version"
2
+ require "licensed/configuration"
3
+ require "licensed/license"
4
+ require "licensed/dependency"
5
+ require "licensed/source/bundler"
6
+ require "licensed/source/bower"
7
+ require "licensed/source/npm"
8
+ require "licensed/command/cache"
9
+ require "licensed/command/verify"
10
+ require "licensed/ui/shell"
11
+ require "octokit"
12
+
13
+ module Licensed
14
+ class << self
15
+ attr_accessor :use_github
16
+ end
17
+
18
+ self.use_github = true
19
+
20
+ GITHUB_URL = %r{\Ahttps://github.com/([a-z0-9]+(-[a-z0-9]+)*/(\w|\.|\-)+)}
21
+ LICENSE_CONTENT_TYPE = "application/vnd.github.drax-preview+json"
22
+
23
+ def self.from_github(url)
24
+ return unless use_github && match = GITHUB_URL.match(url)
25
+
26
+ license_url = Octokit::Repository.path(match[1]) + "/license"
27
+ response = octokit.get license_url, :accept => LICENSE_CONTENT_TYPE
28
+ [
29
+ response["license"]["key"],
30
+ Base64.decode64(response["content"]).force_encoding('UTF-8')
31
+ ]
32
+ rescue Octokit::NotFound
33
+ nil
34
+ end
35
+
36
+ def self.octokit
37
+ @octokit ||= Octokit::Client.new(:access_token => ENV["GITHUB_TOKEN"])
38
+ end
39
+ end
@@ -0,0 +1,33 @@
1
+ require "licensed"
2
+ require "thor"
3
+
4
+ module Licensed
5
+ class CLI < Thor
6
+
7
+ desc "cache", "Cache the licenses of dependencies"
8
+ method_option :force, :type => :boolean,
9
+ :desc => "Overwrite licenses even if version has not changed."
10
+ method_option :offline, :type => :boolean,
11
+ :desc => "Do not make network calls."
12
+ def cache
13
+ Licensed.use_github = false if options[:offline]
14
+ run Licensed::Command::Cache.new(config), force: options[:force]
15
+ end
16
+
17
+ desc "verify", "Verify licenses of dependencies"
18
+ def verify
19
+ run Licensed::Command::Verify.new(config)
20
+ end
21
+
22
+ private
23
+
24
+ def config
25
+ @config ||= Configuration.new
26
+ end
27
+
28
+ def run(command, *args)
29
+ command.run(*args)
30
+ exit command.success?
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,56 @@
1
+ module Licensed
2
+ module Command
3
+ class Cache
4
+ attr_reader :config
5
+
6
+ def initialize(config)
7
+ @config = config
8
+ end
9
+
10
+ def run(force: false)
11
+ @config.sources.each do |source|
12
+ @config.ui.info "Caching licenses for #{source.type} dependencies:"
13
+
14
+ source.dependencies.each do |dependency|
15
+ next if @config.ignored?(dependency)
16
+
17
+ filename = @config.path.join("#{source.type}/#{dependency["name"]}.txt")
18
+
19
+ if File.exist?(filename)
20
+ license = Licensed::License.read(filename)
21
+
22
+ # Version did not change, no need to re-cache
23
+ if !force && dependency["version"] == license["version"]
24
+ @config.ui.info " Using #{dependency["name"]} (#{dependency["version"]})"
25
+ next
26
+ end
27
+ end
28
+
29
+ @config.ui.info " Caching #{dependency["name"]} (#{dependency["version"]})"
30
+
31
+ dependency.detect_license!
32
+ dependency.save(filename)
33
+ end
34
+
35
+ # Clean up dependencies that have been removed
36
+ names = source.dependencies.map do |dependency|
37
+ dependency["name"] unless @config.ignored?(dependency)
38
+ end.compact
39
+
40
+ Dir.glob(@config.path.join("#{source.type}/*.txt")).each do |file|
41
+ FileUtils.rm(file) unless names.include?(File.basename(file, ".txt"))
42
+ end
43
+ end
44
+
45
+ @config.ui.confirm "License caching complete!"
46
+ @config.sources.each do |source|
47
+ @config.ui.confirm "* #{source.type} dependencies: #{source.dependencies.size}"
48
+ end
49
+ end
50
+
51
+ def success?
52
+ true
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,72 @@
1
+ require 'yaml'
2
+
3
+ module Licensed
4
+ module Command
5
+ class Verify
6
+ attr_reader :config
7
+
8
+ def initialize(config)
9
+ @config = config
10
+ end
11
+
12
+ def approved?(dependency)
13
+ @config.whitelisted?(dependency) ||
14
+ @config.reviewed?(dependency)
15
+ end
16
+
17
+ def dependencies
18
+ @dependencies ||= @config.sources.map(&:dependencies).flatten
19
+ end
20
+
21
+ def run
22
+ @config.ui.info "Verifying licenses for #{dependencies.size} dependencies"
23
+
24
+ @results = dependencies.map do |dependency|
25
+ next if @config.ignored?(dependency)
26
+ filename = @config.path.join("#{dependency["type"]}/#{dependency["name"]}.txt")
27
+
28
+ warnings = []
29
+
30
+ if File.exists?(filename)
31
+ license = License.read(filename)
32
+
33
+ if license["version"] != dependency["version"]
34
+ warnings << "cached license data out of date"
35
+ end
36
+ warnings << "missing license text" if license.text.strip.empty?
37
+ unless approved?(license)
38
+ warnings << "license needs reviewed: #{license["license"]}."
39
+ end
40
+ else
41
+ warnings << "missing license data"
42
+ end
43
+
44
+ if warnings.size > 0
45
+ @config.ui.error("F", false)
46
+ [filename, warnings]
47
+ else
48
+ @config.ui.confirm(".", false)
49
+ nil
50
+ end
51
+ end.compact
52
+
53
+ unless success?
54
+ @config.ui.warn "\n\nWarnings:"
55
+
56
+ @results.each do |filename, warnings|
57
+ @config.ui.info "\n#{filename}:"
58
+ warnings.each do |warning|
59
+ @config.ui.error " - #{warning}"
60
+ end
61
+ end
62
+ end
63
+
64
+ puts "\n#{dependencies.size} dependencies checked, #{@results.size} warnings found."
65
+ end
66
+
67
+ def success?
68
+ @results.empty?
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,70 @@
1
+ require "pathname"
2
+
3
+ module Licensed
4
+ class Configuration < Hash
5
+ attr_accessor :ui
6
+
7
+ def initialize
8
+ super()
9
+ update config_path.exist? ? YAML.load_file(config_path) : {}
10
+
11
+ self["sources"] ||= {}
12
+ self["reviewed"] ||= {}
13
+ self["ignored"] ||= {}
14
+ self["whitelist"] ||= []
15
+
16
+ @ui = Licensed::UI::Shell.new
17
+ end
18
+
19
+ def path
20
+ Pathname.new("vendor/licenses")
21
+ end
22
+
23
+ def config_path
24
+ path.join("config.yml")
25
+ end
26
+
27
+ def pwd
28
+ Pathname.new(Dir.pwd)
29
+ end
30
+
31
+ def sources
32
+ @sources ||= [
33
+ Source::Bundler.new(self),
34
+ Source::Bower.new(self),
35
+ Source::NPM.new(self)
36
+ ].select(&:enabled?)
37
+ end
38
+
39
+ def enabled?(source_type)
40
+ self["sources"].fetch(source_type, true)
41
+ end
42
+
43
+ # Is the given dependency approved?
44
+ def reviewed?(dependency)
45
+ Array(self["reviewed"][dependency["type"]]).include?(dependency["name"])
46
+ end
47
+
48
+ # Is the given dependency ignored?
49
+ def ignored?(dependency)
50
+ Array(self["ignored"][dependency["type"]]).include?(dependency["name"])
51
+ end
52
+
53
+ # Is the license of the dependency whitelisted?
54
+ def whitelisted?(dependency)
55
+ Array(self["whitelist"]).include?(dependency["license"])
56
+ end
57
+
58
+ def ignore(dependency)
59
+ (self["ignored"][dependency["type"]] ||= []) << dependency["name"]
60
+ end
61
+
62
+ def review(dependency)
63
+ (self["reviewed"][dependency["type"]] ||= []) << dependency["name"]
64
+ end
65
+
66
+ def whitelist(license)
67
+ self["whitelist"] << license
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,50 @@
1
+ require "licensee"
2
+
3
+ module Licensed
4
+ class Dependency < License
5
+ LEGAL_FILES = /\A(COPYING|NOTICE|LEGAL)(?:\..*)?\z/i
6
+
7
+ attr_reader :path
8
+
9
+ def initialize(path, metadata = {})
10
+ @path = path
11
+ super metadata
12
+ end
13
+
14
+ def project
15
+ @project ||= Licensee::FSProject.new(path, detect_packages: true, detect_readme: true)
16
+ end
17
+
18
+ def detect_license!
19
+ if project.license_file
20
+ license = project.license.key if project.license
21
+ else
22
+ # No license file detected, see if there is one in the GitHub repository
23
+ license, content = Licensed.from_github(self["homepage"])
24
+
25
+ # No license in the GitHub repository, see if there is one in the README
26
+ if !license && project.readme
27
+ license = project.license.key if project.license
28
+ content = project.readme.content
29
+ end
30
+ end
31
+
32
+ self["license"] = license || package_manager_license || "other"
33
+ self.text = ([content] + self.notices).compact.join("\n" + "-" * 80 + "\n")
34
+ end
35
+
36
+ def package_manager_license
37
+ project.license.key if project.license
38
+ end
39
+
40
+ # Extract legal notices from the dependency source
41
+ def notices
42
+ files = Dir.foreach(path).select do |file|
43
+ File.file?(File.join(path, file)) && file.match(LEGAL_FILES)
44
+ end
45
+ files.unshift project.license_file.filename if project.license_file
46
+
47
+ files.uniq.map { |f| File.read(File.join(path, f)) }
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,42 @@
1
+ require "yaml"
2
+ require "fileutils"
3
+ require "forwardable"
4
+
5
+ module Licensed
6
+ class License
7
+ YAML_FRONTMATTER_PATTERN = /\A---\s*\n(.*?\n?)^---\s*$\n?(.*)\z/m
8
+ LEGAL_FILES = /\A(COPYING|NOTICE|LEGAL)(?:\..*)?\z/i
9
+
10
+ # Read an existing license file
11
+ #
12
+ # filename - A String path to the file
13
+ #
14
+ # Returns a Licensed::License
15
+ def self.read(filename)
16
+ match = File.read(filename).match(YAML_FRONTMATTER_PATTERN)
17
+ new(YAML.load(match[1]), match[2])
18
+ end
19
+
20
+ extend Forwardable
21
+ def_delegators :@metadata, :[], :[]=
22
+
23
+ # The license text and other legal notices
24
+ attr_accessor :text
25
+
26
+ # Construct a new license
27
+ #
28
+ # filename - the String path of the file
29
+ # metadata - a Hash of the metadata for the package
30
+ # text - a String of the license text and other legal notices
31
+ def initialize(metadata = {}, text = nil)
32
+ @metadata = metadata
33
+ @text = text
34
+ end
35
+
36
+ # Save the metadata and license to a file
37
+ def save(filename)
38
+ FileUtils.mkdir_p(File.dirname(filename))
39
+ File.write(filename, YAML.dump(@metadata) + "---\n#{text}")
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,48 @@
1
+ require "json"
2
+
3
+ module Licensed
4
+ module Source
5
+ class Bower
6
+ def initialize(config)
7
+ @config = config
8
+ end
9
+
10
+ def type
11
+ "bower"
12
+ end
13
+
14
+ def enabled?
15
+ return false unless @config.enabled?(type)
16
+
17
+ [@config.pwd.join(".bowerrc"), @config.pwd.join("bower.json")].any? do |path|
18
+ File.exist?(path)
19
+ end
20
+ end
21
+
22
+ def dependencies
23
+ @dependencies ||= Dir.glob(bower_path.join("*/.bower.json")).map do |file|
24
+ package = JSON.parse(File.read(file))
25
+ Dependency.new(File.dirname(file), {
26
+ "type" => type,
27
+ "name" => package["name"],
28
+ "version" => package["version"],
29
+ "summary" => package["description"],
30
+ "homepage" => package["homepage"]
31
+ })
32
+ end
33
+ end
34
+
35
+ def bower_config
36
+ @bower_config ||= begin
37
+ path = @config.pwd.join(".bowerrc")
38
+ path.exist? ? JSON.parse(path.read) : {}
39
+ end
40
+ end
41
+
42
+ def bower_path
43
+ pwd = bower_config["cwd"] ? Pathname.new(bower_config["cwd"]) : @config.pwd
44
+ pwd.join bower_config["directory"] || "bower_components"
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,49 @@
1
+ require "bundler"
2
+
3
+ module Licensed
4
+ module Source
5
+ class Bundler
6
+ def initialize(config)
7
+ @config = config
8
+ end
9
+
10
+ def enabled?
11
+ @config.enabled?(type) && File.exist?(lockfile_path)
12
+ end
13
+
14
+ def type
15
+ "rubygem"
16
+ end
17
+
18
+ def dependencies
19
+ @dependencies ||= definition.specs_for(groups).map do |spec|
20
+ Dependency.new(spec.gem_dir, {
21
+ "type" => type,
22
+ "name" => spec.name,
23
+ "version" => spec.version.to_s,
24
+ "summary" => spec.summary,
25
+ "homepage" => spec.homepage
26
+ })
27
+ end
28
+ end
29
+
30
+ # Build the bundler definition
31
+ def definition
32
+ @definition ||= ::Bundler::Definition.build(gemfile_path, lockfile_path, nil)
33
+ end
34
+
35
+ def groups
36
+ definition.groups - [:test, :development]
37
+ end
38
+
39
+ def gemfile_path
40
+ @config.pwd.join "Gemfile"
41
+ end
42
+
43
+ def lockfile_path
44
+ @config.pwd.join "Gemfile.lock"
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,47 @@
1
+ require "json"
2
+
3
+ module Licensed
4
+ module Source
5
+ class NPM
6
+ def initialize(config)
7
+ @config = config
8
+ end
9
+
10
+ def type
11
+ "npm"
12
+ end
13
+
14
+ def enabled?
15
+ @config.enabled?(type) && File.exist?(@config.pwd.join("package.json"))
16
+ end
17
+
18
+ def dependencies
19
+ return @dependencies if defined?(@dependencies)
20
+
21
+ packages = recursive_dependencies(JSON.parse(command)["dependencies"])
22
+
23
+ @dependencies = packages.map do |name, package|
24
+ Dependency.new(package["realPath"], {
25
+ "type" => type,
26
+ "name" => package["name"],
27
+ "version" => package["version"],
28
+ "summary" => package["description"],
29
+ "homepage" => package["homepage"]
30
+ })
31
+ end
32
+ end
33
+
34
+ def command
35
+ `npm list --json --production --long`
36
+ end
37
+
38
+ def recursive_dependencies(dependencies, result = {})
39
+ dependencies.each do |name, dependency|
40
+ (result[name] ||= {}).update(dependency)
41
+ recursive_dependencies(dependency["dependencies"] || {}, result)
42
+ end
43
+ result
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,50 @@
1
+ require "thor"
2
+
3
+ module Licensed
4
+ module UI
5
+ class Shell
6
+ LEVELS = %w(silent error warn confirm info debug)
7
+
8
+ def initialize
9
+ @shell = STDOUT.tty? ? Thor::Base.shell.new : Thor::Shell::Basic.new
10
+ @level = ENV['DEBUG'] ? "debug" : "info"
11
+ end
12
+
13
+ def debug(msg, newline = true)
14
+ @shell.say msg, nil, newline if level?("debug")
15
+ end
16
+
17
+ def info(msg, newline = true)
18
+ @shell.say msg, nil, newline if level?("info")
19
+ end
20
+
21
+ def confirm(msg, newline = true)
22
+ @shell.say msg, :green, newline if level?("confirm")
23
+ end
24
+
25
+ def warn(msg, newline = true)
26
+ @shell.say msg, :yellow, newline if level?("warn")
27
+ end
28
+
29
+ def error(msg, newline = true)
30
+ @shell.say msg, :red, newline if level?("error")
31
+ end
32
+
33
+ def level=(level)
34
+ raise ArgumentError unless LEVELS.include?(level.to_s)
35
+ @level = level
36
+ end
37
+
38
+ def level?(name = nil)
39
+ name ? LEVELS.index(name) <= LEVELS.index(@level) : @level
40
+ end
41
+
42
+ def silence
43
+ old_level, @level = @level, "silent"
44
+ yield
45
+ ensure
46
+ @level = old_level
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module Licensed
2
+ VERSION = "0.6.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'licensed/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "licensed"
8
+ spec.version = Licensed::VERSION
9
+ spec.authors = ["GitHub"]
10
+ spec.email = ["opensource@github.com"]
11
+
12
+ spec.summary = %q{extract and validate the licenses of dependencies.}
13
+ spec.description = File.read("README.md")
14
+ spec.homepage = "https://github.com/github/licensed"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "licensee", "~> 8.0"
23
+ spec.add_dependency "thor", "~>0.19"
24
+ spec.add_dependency "octokit", "~>4.0"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.10"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "minitest", "~> 5.8"
29
+ spec.add_development_dependency "vcr", "~> 2.9"
30
+ spec.add_development_dependency "webmock", "~> 1.21"
31
+ end
metadata ADDED
@@ -0,0 +1,279 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: licensed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - GitHub
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: licensee
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '8.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '8.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.19'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.19'
41
+ - !ruby/object:Gem::Dependency
42
+ name: octokit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '5.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.9'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.9'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.21'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.21'
125
+ description: |
126
+ # Licensed
127
+
128
+ Licensed is a Ruby gem to cache and verify the licenses of dependencies.
129
+
130
+ ## Installation
131
+
132
+ Add this line to your application's Gemfile:
133
+
134
+ ```ruby
135
+ gem 'licensed', :group => 'development'
136
+ ```
137
+
138
+ And then execute:
139
+
140
+ $ bundle
141
+
142
+ ## Usage
143
+
144
+ - `licensed cache`: Cache licenses and metadata in `vendor/licenses`
145
+
146
+ - `licensed verify`: Check for issues with the licenses of dependencies. For example:
147
+
148
+ ```
149
+ $ bundle exec licensed verify
150
+ Verifying licenses for 3 dependencies
151
+
152
+ Warnings:
153
+
154
+ vendor/licenses/rubygem/bundler.txt:
155
+ - license needs reviewed: mit.
156
+
157
+ vendor/licenses/rubygem/licensee.txt:
158
+ - missing license data
159
+
160
+ vendor/licenses/bower/jquery.txt:
161
+ - license needs reviewed: mit.
162
+ - cached license data out of date
163
+
164
+ 3 dependencies checked, 3 warnings found.
165
+ ```
166
+
167
+ ### Configuration
168
+
169
+ Configuration is managed by `vendor/licenses/config.yml`.
170
+
171
+ ```yml
172
+ # Dependencies with these licenses are approved by default.
173
+ whitelist:
174
+ - mit
175
+ - apache-2.0
176
+ - bsd-2-clause
177
+ - bsd-3-clause
178
+ - cc0-1.0
179
+
180
+ # These dependencies are explicitly ignored.
181
+ ignored:
182
+ rubygem:
183
+ - some-internal-gem
184
+
185
+ bower:
186
+ - some-internal-package
187
+
188
+ # These dependencies have been reviewed.
189
+ reviewed:
190
+ rubygem:
191
+ - bcrypt-ruby
192
+
193
+ bower:
194
+ - classlist # public domain
195
+ - octicons
196
+ ```
197
+
198
+ ### Sources
199
+
200
+ Dependencies from Bundler, NPM, and Bower will be automatically detected. You can disable any of them in `vendor/licenses/config.yml`:
201
+
202
+ ```yml
203
+ sources:
204
+ rubygem: false
205
+ npm: false
206
+ bower: false
207
+ ```
208
+
209
+ ## Development
210
+
211
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
212
+
213
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
214
+
215
+ ## Contributing
216
+
217
+ Bug reports and pull requests are welcome on GitHub at https://github.com/github/licensed. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
218
+
219
+ ## License
220
+
221
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
222
+ email:
223
+ - opensource@github.com
224
+ executables:
225
+ - licensed
226
+ - licensor
227
+ extensions: []
228
+ extra_rdoc_files: []
229
+ files:
230
+ - ".bowerrc"
231
+ - ".gitignore"
232
+ - ".travis.yml"
233
+ - CODE_OF_CONDUCT.md
234
+ - Gemfile
235
+ - LICENSE.txt
236
+ - README.md
237
+ - Rakefile
238
+ - bin/console
239
+ - bin/setup
240
+ - exe/licensed
241
+ - exe/licensor
242
+ - lib/licensed.rb
243
+ - lib/licensed/cli.rb
244
+ - lib/licensed/command/cache.rb
245
+ - lib/licensed/command/verify.rb
246
+ - lib/licensed/configuration.rb
247
+ - lib/licensed/dependency.rb
248
+ - lib/licensed/license.rb
249
+ - lib/licensed/source/bower.rb
250
+ - lib/licensed/source/bundler.rb
251
+ - lib/licensed/source/npm.rb
252
+ - lib/licensed/ui/shell.rb
253
+ - lib/licensed/version.rb
254
+ - licensed.gemspec
255
+ homepage: https://github.com/github/licensed
256
+ licenses:
257
+ - MIT
258
+ metadata: {}
259
+ post_install_message:
260
+ rdoc_options: []
261
+ require_paths:
262
+ - lib
263
+ required_ruby_version: !ruby/object:Gem::Requirement
264
+ requirements:
265
+ - - ">="
266
+ - !ruby/object:Gem::Version
267
+ version: '0'
268
+ required_rubygems_version: !ruby/object:Gem::Requirement
269
+ requirements:
270
+ - - ">="
271
+ - !ruby/object:Gem::Version
272
+ version: '0'
273
+ requirements: []
274
+ rubyforge_project:
275
+ rubygems_version: 2.4.5.1
276
+ signing_key:
277
+ specification_version: 4
278
+ summary: extract and validate the licenses of dependencies.
279
+ test_files: []