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:
parent
b0e7fd5a60
commit
853f4c97b2
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,3 +10,4 @@ assets/vendor/qtip2/basic
|
|||||||
Gemfile.lock
|
Gemfile.lock
|
||||||
/.sass-cache
|
/.sass-cache
|
||||||
.ruby-version
|
.ruby-version
|
||||||
|
/tmp
|
||||||
|
1
Gemfile
1
Gemfile
@ -7,4 +7,5 @@ group :test do
|
|||||||
gem "html-proofer"
|
gem "html-proofer"
|
||||||
gem "rake"
|
gem "rake"
|
||||||
gem "rspec"
|
gem "rspec"
|
||||||
|
gem "nokogiri"
|
||||||
end
|
end
|
||||||
|
@ -1,36 +1,31 @@
|
|||||||
require 'spec_helper'
|
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|
|
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 "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
|
let(:id) { license["id"] }
|
||||||
spdx = find_spdx(license["id"])
|
|
||||||
expect(spdx[1]["name"].gsub(/ only$/,"")).to eql(license["title"])
|
|
||||||
end
|
|
||||||
|
|
||||||
# CC0 and Unlicense are not OSI approved, but that's okay
|
it "has an SPDX ID" do
|
||||||
unless LICENSE_WHITELIST.include? license["id"]
|
expect(spdx_ids).to include(id)
|
||||||
it "should be OSI approved" do
|
end
|
||||||
spdx = find_spdx(license["id"])
|
|
||||||
approved = spdx[1]["osiApproved"]
|
it "uses its SPDX name" do
|
||||||
expect(approved).to eql(true)
|
spdx = find_spdx(id)
|
||||||
end
|
expect(spdx[1]["name"].gsub(/ only$/,"")).to eql(license["title"])
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
require 'jekyll'
|
require 'jekyll'
|
||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
require 'json'
|
require 'json'
|
||||||
|
require 'open-uri'
|
||||||
|
require 'nokogiri'
|
||||||
|
|
||||||
def config_file
|
def config_file
|
||||||
File.expand_path "./_config.yml", source
|
File.expand_path "./_config.yml", source
|
||||||
@ -54,6 +56,54 @@ def spdx_list
|
|||||||
$spdx ||= JSON.parse(open(url).read)
|
$spdx ||= JSON.parse(open(url).read)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def spdx_ids
|
||||||
|
spdx_list.map { |name, properties| name.downcase }
|
||||||
|
end
|
||||||
|
|
||||||
def find_spdx(license)
|
def find_spdx(license)
|
||||||
spdx_list.find { |name, properties| name.downcase == license }
|
spdx_list.find { |name, properties| name.downcase == license }
|
||||||
end
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user