1
0
mirror of https://github.com/github/choosealicense.com synced 2024-12-22 04:40:09 +01:00

check for license compliance

This commit is contained in:
Ben Balter 2016-01-15 17:40:32 -05:00
parent b0e7fd5a60
commit 853f4c97b2
4 changed files with 74 additions and 27 deletions

1
.gitignore vendored
View File

@ -10,3 +10,4 @@ assets/vendor/qtip2/basic
Gemfile.lock
/.sass-cache
.ruby-version
/tmp

View File

@ -7,4 +7,5 @@ group :test do
gem "html-proofer"
gem "rake"
gem "rspec"
gem "nokogiri"
end

View File

@ -1,36 +1,31 @@
require 'spec_helper'
# List of licenses that need not be OSI approved
LICENSE_WHITELIST = %w[
unlicense
cc0-1.0
wtfpl
bsd-3-clause-clear
]
licenses.each do |license|
# "No license" isn't really a license, so no need to test
next if license["id"] == "no-license"
describe "The #{license["title"]} license" do
describe "SPDX compliance" do
# "No license" isn't really a license, so no need to test
unless license["id"] == "no-license"
it "#{license["id"]} should be a valid SPDX ID" do
expect(find_spdx(license["id"])).to_not be_nil
end
it "should be the proper SPDX name" do
spdx = find_spdx(license["id"])
expect(spdx[1]["name"].gsub(/ only$/,"")).to eql(license["title"])
end
let(:id) { license["id"] }
# CC0 and Unlicense are not OSI approved, but that's okay
unless LICENSE_WHITELIST.include? license["id"]
it "should be OSI approved" do
spdx = find_spdx(license["id"])
approved = spdx[1]["osiApproved"]
expect(approved).to eql(true)
end
end
end
it "has an SPDX ID" do
expect(spdx_ids).to include(id)
end
it "uses its SPDX name" do
spdx = find_spdx(id)
expect(spdx[1]["name"].gsub(/ only$/,"")).to eql(license["title"])
end
it "should be approved by OSI or FSF or OD" do
osi = osi_approved?(id)
fsf = fsf_approved?(id)
od = od_approved?(id)
approved = osi || fsf || od
msg = "The license must be approved by OSI, FSF, or OD. See https://git.io/vzCTV."
expect(approved).to eql(true), msg
end
end
end

View File

@ -1,6 +1,8 @@
require 'jekyll'
require 'open-uri'
require 'json'
require 'open-uri'
require 'nokogiri'
def config_file
File.expand_path "./_config.yml", source
@ -54,6 +56,54 @@ def spdx_list
$spdx ||= JSON.parse(open(url).read)
end
def spdx_ids
spdx_list.map { |name, properties| name.downcase }
end
def find_spdx(license)
spdx_list.find { |name, properties| name.downcase == license }
end
def osi_approved?(id)
spdx = find_spdx(id)
return false unless spdx
spdx[1]["osiApproved"]
end
def fsf_approved_licenses
$fsf_approved_licenses ||= begin
url = "https://www.gnu.org/licenses/license-list.en.html"
doc = Nokogiri::HTML(open(url).read)
list = doc.css(".green dt")
licenses = {}
list.each do |license|
a = license.css("a").find { |link| !link.text.nil? && !link.text.empty? && link.attr("id") }
next if a.nil?
id = a.attr("id").downcase
name = a.text.strip
licenses[id] = name
end
licenses
end
end
def fsf_approved?(id)
fsf_approved_licenses.keys.include?(id)
end
def od_approved_licenses
$od_approved_licenses ||= begin
url = "http://licenses.opendefinition.org/licenses/groups/od.json"
data = open(url).read
data = JSON.parse(data)
licenses = {}
data.each do |id, meta|
licenses[id.downcase] = meta["title"]
end
licenses
end
end
def od_approved?(id)
od_approved_licenses.keys.include?(id)
end