From 764906715176b53843e73ef57956aabff7692cd4 Mon Sep 17 00:00:00 2001 From: Mike Linksvayer Date: Sat, 25 Nov 2017 16:16:11 -0800 Subject: [PATCH 1/9] Test examples provided in 'using:' would be detected by licensee --- Gemfile | 1 + spec/license_meta_spec.rb | 29 ++++++++++++++++++++++++++++- spec/spec_helper.rb | 1 - 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 84fd12d..c92472d 100644 --- a/Gemfile +++ b/Gemfile @@ -16,6 +16,7 @@ end group :test do gem 'html-proofer', '~> 3.0' + gem 'licensee' gem 'nokogiri' gem 'rake' gem 'rspec' diff --git a/spec/license_meta_spec.rb b/spec/license_meta_spec.rb index b705913..6604066 100644 --- a/spec/license_meta_spec.rb +++ b/spec/license_meta_spec.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require 'licensee' require 'spec_helper' describe 'license meta' do @@ -19,6 +20,8 @@ describe 'license meta' do expect(missing).to be_empty end + examples = raw_fields['using'] || [] + it 'using contains 3 examples' do legacy = [ 'afl-3.0', @@ -43,9 +46,33 @@ describe 'license meta' do 'zlib' ] skip 'added before 3 using examples required' if legacy.include?(license['slug']) - examples = raw_fields['using'] || [] expect(examples.length).to eq(3) end + + context 'licensee detects using examples' do + module Licensee + class License + class << self + def license_dir + dir = ::File.dirname(__FILE__) + ::File.expand_path '../_licenses', dir + end + end + end + end + + examples.each do |example| + example_url = example.values[0] + if example_url.index('https://github.com/') == 0 + example_url.gsub!(%r{\Ahttps://github.com/(\w+/\w+)/blob/(\w+/\S+)\z}, 'https://raw.githubusercontent.com/\1/\2') + end + content = open(example_url).read + detected = Licensee::ProjectFiles::LicenseFile.new(content, 'LICENSE').license + it example_url do + expect(detected.key).to eq(license['slug']) + end + end + end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ab89492..4070ccf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'jekyll' -require 'open-uri' require 'json' require 'open-uri' require 'nokogiri' From 0e2a2653bdaeb110f13e2d5620db4368c4c7edf7 Mon Sep 17 00:00:00 2001 From: Mike Linksvayer Date: Sat, 25 Nov 2017 19:56:20 -0800 Subject: [PATCH 2/9] path item can include - --- spec/license_meta_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/license_meta_spec.rb b/spec/license_meta_spec.rb index 6604066..5642532 100644 --- a/spec/license_meta_spec.rb +++ b/spec/license_meta_spec.rb @@ -64,7 +64,7 @@ describe 'license meta' do examples.each do |example| example_url = example.values[0] if example_url.index('https://github.com/') == 0 - example_url.gsub!(%r{\Ahttps://github.com/(\w+/\w+)/blob/(\w+/\S+)\z}, 'https://raw.githubusercontent.com/\1/\2') + example_url.gsub!(%r{\Ahttps://github.com/([\w-]+/[\w-]+)/blob/([\w-]+/\S+)\z}, 'https://raw.githubusercontent.com/\1/\2') end content = open(example_url).read detected = Licensee::ProjectFiles::LicenseFile.new(content, 'LICENSE').license From 642783cf4b034681929b973722bd7648123a1ccd Mon Sep 17 00:00:00 2001 From: Mike Linksvayer Date: Sat, 25 Nov 2017 20:15:01 -0800 Subject: [PATCH 3/9] GPLv2 examples that can be detected --- _licenses/gpl-2.0.txt | 5 +++-- spec/license_meta_spec.rb | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/_licenses/gpl-2.0.txt b/_licenses/gpl-2.0.txt index 506fcea..6f0d042 100644 --- a/_licenses/gpl-2.0.txt +++ b/_licenses/gpl-2.0.txt @@ -13,8 +13,9 @@ how: Create a text file (typically named LICENSE or LICENSE.txt) in the root of note: The Free Software Foundation recommends taking the additional step of adding a boilerplate notice to the top of each file. The boilerplate can be found at the end of the license. using: - - Linux: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/COPYING - - WordPress: https://github.com/WordPress/WordPress/blob/master/license.txt + - AliSQL: https://github.com/alibaba/AliSQL/blob/master/COPYING + - Discourse: https://github.com/discourse/discourse/blob/master/LICENSE.txt + - Joomla!: https://github.com/joomla/joomla-cms/blob/staging/LICENSE.txt permissions: - commercial-use diff --git a/spec/license_meta_spec.rb b/spec/license_meta_spec.rb index 5642532..4420927 100644 --- a/spec/license_meta_spec.rb +++ b/spec/license_meta_spec.rb @@ -35,7 +35,6 @@ describe 'license meta' do 'cc-by-4.0', 'cc-by-sa-4.0', 'eupl-1.1', - 'gpl-2.0', 'lgpl-2.1', 'lgpl-3.0', 'lppl-1.3c', From 5130f12df10f01e597fca147064cda3577e1ebff Mon Sep 17 00:00:00 2001 From: Mike Linksvayer Date: Sat, 25 Nov 2017 20:27:20 -0800 Subject: [PATCH 4/9] Update GPLv3 examples --- _licenses/gpl-3.0.txt | 2 +- spec/license_meta_spec.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/_licenses/gpl-3.0.txt b/_licenses/gpl-3.0.txt index a533d7f..6011db0 100644 --- a/_licenses/gpl-3.0.txt +++ b/_licenses/gpl-3.0.txt @@ -14,9 +14,9 @@ how: Create a text file (typically named LICENSE or LICENSE.txt) in the root of note: The Free Software Foundation recommends taking the additional step of adding a boilerplate notice to the top of each file. The boilerplate can be found at the end of the license. using: + - Ansible: https://github.com/ansible/ansible/blob/devel/COPYING - Bash: https://git.savannah.gnu.org/cgit/bash.git/tree/COPYING - GIMP: https://git.gnome.org/browse/gimp/tree/COPYING - - Privacy Badger: https://github.com/EFForg/privacybadgerfirefox/blob/master/LICENSE permissions: - commercial-use diff --git a/spec/license_meta_spec.rb b/spec/license_meta_spec.rb index 4420927..a3923ad 100644 --- a/spec/license_meta_spec.rb +++ b/spec/license_meta_spec.rb @@ -64,6 +64,8 @@ describe 'license meta' do example_url = example.values[0] if example_url.index('https://github.com/') == 0 example_url.gsub!(%r{\Ahttps://github.com/([\w-]+/[\w-]+)/blob/([\w-]+/\S+)\z}, 'https://raw.githubusercontent.com/\1/\2') + elsif example_url.index('https://git.savannah.gnu.org/') == 0 || example_url.index('https://git.gnome.org/') == 0 + example_url.gsub!(%r{/tree/}, '/plain/') end content = open(example_url).read detected = Licensee::ProjectFiles::LicenseFile.new(content, 'LICENSE').license From 1a841848b3ad25af2dc2da39083358ca7d65d116 Mon Sep 17 00:00:00 2001 From: Mike Linksvayer Date: Sat, 25 Nov 2017 20:32:19 -0800 Subject: [PATCH 5/9] ECL-2.0 examples --- _licenses/ecl-2.0.txt | 2 +- spec/license_meta_spec.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/_licenses/ecl-2.0.txt b/_licenses/ecl-2.0.txt index ccc9267..2b0be47 100644 --- a/_licenses/ecl-2.0.txt +++ b/_licenses/ecl-2.0.txt @@ -12,7 +12,7 @@ note: The Apereo Foundation recommends taking the additional step of adding a bo using: - Sakai: https://github.com/sakaiproject/sakai/blob/master/LICENSE - OAE: https://github.com/oaeproject/Hilary/blob/master/LICENSE - - Opencast: https://bitbucket.org/opencast-community/opencast/src/905077ba5e6483f8c49869a1fc13bf9268790a79/LICENSE?at=develop + - Opencast: https://bitbucket.org/opencast-community/opencast/src/905077ba5e6483f8c49869a1fc13bf9268790a79/LICENSE permissions: - commercial-use diff --git a/spec/license_meta_spec.rb b/spec/license_meta_spec.rb index a3923ad..6c6400d 100644 --- a/spec/license_meta_spec.rb +++ b/spec/license_meta_spec.rb @@ -66,6 +66,8 @@ describe 'license meta' do example_url.gsub!(%r{\Ahttps://github.com/([\w-]+/[\w-]+)/blob/([\w-]+/\S+)\z}, 'https://raw.githubusercontent.com/\1/\2') elsif example_url.index('https://git.savannah.gnu.org/') == 0 || example_url.index('https://git.gnome.org/') == 0 example_url.gsub!(%r{/tree/}, '/plain/') + elsif example_url.index('https://bitbucket.org/') == 0 + example_url.gsub!(%r{/src/}, '/raw/') end content = open(example_url).read detected = Licensee::ProjectFiles::LicenseFile.new(content, 'LICENSE').license From d0caabb71edd06451ddc807cf9358e33ec9e813c Mon Sep 17 00:00:00 2001 From: Mike Linksvayer Date: Sat, 25 Nov 2017 20:38:49 -0800 Subject: [PATCH 6/9] ISC examples --- _licenses/isc.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_licenses/isc.txt b/_licenses/isc.txt index 2d8f0e1..8e34275 100644 --- a/_licenses/isc.txt +++ b/_licenses/isc.txt @@ -8,7 +8,7 @@ description: A permissive license lets people do anything with your code with pr how: Create a text file (typically named LICENSE or LICENSE.txt) in the root of your source code and copy the text of the license into the file. Replace [year] with the current year and [fullname] with the name (or names) of the copyright holders. using: - - documentation.js: https://github.com/documentationjs/documentation/blob/master/LICENSE + - Helix: https://github.com/tildeio/helix/blob/master/LICENSE - Node.js semver: https://github.com/npm/node-semver/blob/master/LICENSE - OpenStreetMap iD: https://github.com/openstreetmap/iD/blob/master/LICENSE.md From 1cca51a1287f32c67d321f2d58c3ee54d225a572 Mon Sep 17 00:00:00 2001 From: Mike Linksvayer Date: Sat, 25 Nov 2017 20:44:51 -0800 Subject: [PATCH 7/9] MIT --- _licenses/mit.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_licenses/mit.txt b/_licenses/mit.txt index 68784c8..5104ab2 100644 --- a/_licenses/mit.txt +++ b/_licenses/mit.txt @@ -10,9 +10,9 @@ description: A short and simple permissive license with conditions only requirin how: Create a text file (typically named LICENSE or LICENSE.txt) in the root of your source code and copy the text of the license into the file. Replace [year] with the current year and [fullname] with the name (or names) of the copyright holders. using: - - jQuery: https://github.com/jquery/jquery/blob/master/LICENSE.txt + - Babel: https://github.com/babel/babel/blob/master/LICENSE - .NET Core: https://github.com/dotnet/corefx/blob/master/LICENSE.TXT - - Rails: https://github.com/rails/rails/blob/master/activerecord/MIT-LICENSE + - Rails: https://github.com/rails/rails/blob/master/MIT-LICENSE permissions: - commercial-use From 2c9fa4907e318df197fbb1e9ea1802512b26f5bc Mon Sep 17 00:00:00 2001 From: Mike Linksvayer Date: Sat, 25 Nov 2017 20:57:24 -0800 Subject: [PATCH 8/9] don't attempt heavily templated NCSA and PostgreSQL for now --- spec/license_meta_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/license_meta_spec.rb b/spec/license_meta_spec.rb index 6c6400d..d7896bf 100644 --- a/spec/license_meta_spec.rb +++ b/spec/license_meta_spec.rb @@ -72,6 +72,7 @@ describe 'license meta' do content = open(example_url).read detected = Licensee::ProjectFiles::LicenseFile.new(content, 'LICENSE').license it example_url do + skip 'NCSA and PostgreSQL licenses hard to detect' if %(ncsa postgresql).include?(license['slug']) expect(detected.key).to eq(license['slug']) end end From 8630a017f8b2a3c0d6e8e1741ceb6c655d567439 Mon Sep 17 00:00:00 2001 From: Mike Linksvayer Date: Mon, 27 Nov 2017 12:56:25 -0800 Subject: [PATCH 9/9] @benbalter review suggestions --- spec/license_meta_spec.rb | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/spec/license_meta_spec.rb b/spec/license_meta_spec.rb index d7896bf..37a123e 100644 --- a/spec/license_meta_spec.rb +++ b/spec/license_meta_spec.rb @@ -60,20 +60,27 @@ describe 'license meta' do end end + slug = license['slug'] + examples.each do |example| example_url = example.values[0] - if example_url.index('https://github.com/') == 0 - example_url.gsub!(%r{\Ahttps://github.com/([\w-]+/[\w-]+)/blob/([\w-]+/\S+)\z}, 'https://raw.githubusercontent.com/\1/\2') - elsif example_url.index('https://git.savannah.gnu.org/') == 0 || example_url.index('https://git.gnome.org/') == 0 - example_url.gsub!(%r{/tree/}, '/plain/') - elsif example_url.index('https://bitbucket.org/') == 0 - example_url.gsub!(%r{/src/}, '/raw/') - end - content = open(example_url).read - detected = Licensee::ProjectFiles::LicenseFile.new(content, 'LICENSE').license - it example_url do - skip 'NCSA and PostgreSQL licenses hard to detect' if %(ncsa postgresql).include?(license['slug']) - expect(detected.key).to eq(license['slug']) + + context "the #{example_url} URL" do + let(:content) { open(example_url).read } + let(:detected) { Licensee::ProjectFiles::LicenseFile.new(content, 'LICENSE').license } + + if example_url.start_with?('https://github.com/') + example_url.gsub!(%r{\Ahttps://github.com/([\w-]+/[\w-]+)/blob/([\w-]+/\S+)\z}, 'https://raw.githubusercontent.com/\1/\2') + elsif example_url.start_with?('https://git.savannah.gnu.org/', 'https://git.gnome.org/') + example_url.gsub!(%r{/tree/}, '/plain/') + elsif example_url.start_with?('https://bitbucket.org/') + example_url.gsub!(%r{/src/}, '/raw/') + end + + it "is a #{slug} license" do + skip 'NCSA and PostgreSQL licenses hard to detect' if %(ncsa postgresql).include?(slug) + expect(detected.key).to eq(slug) + end end end end