mirror of
https://github.com/github/choosealicense.com
synced 2024-12-22 12:50:24 +01:00
Merge pull request #318 from github/approval-script
Add script to check approval of a license.
This commit is contained in:
commit
58e9faeedf
6
Gemfile
6
Gemfile
@ -3,6 +3,12 @@ source "https://rubygems.org"
|
||||
gem "github-pages"
|
||||
gem "jekyll-seo-tag"
|
||||
|
||||
group :development do
|
||||
gem 'colored'
|
||||
gem 'terminal-table'
|
||||
gem 'fuzzy_match'
|
||||
end
|
||||
|
||||
group :test do
|
||||
gem 'html-proofer', '2.5.2'
|
||||
gem "rake"
|
||||
|
@ -26,6 +26,7 @@ GEM
|
||||
multipart-post (>= 1.2, < 3)
|
||||
fast-stemmer (1.0.2)
|
||||
ffi (1.9.10)
|
||||
fuzzy_match (2.1.0)
|
||||
gemoji (2.1.0)
|
||||
github-pages (43)
|
||||
RedCloth (= 4.2.9)
|
||||
@ -166,12 +167,15 @@ PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
colored
|
||||
fuzzy_match
|
||||
github-pages
|
||||
html-proofer (= 2.5.2)
|
||||
jekyll-seo-tag
|
||||
nokogiri
|
||||
rake
|
||||
rspec
|
||||
terminal-table
|
||||
|
||||
BUNDLED WITH
|
||||
1.11.2
|
||||
|
73
script/check-approval
Executable file
73
script/check-approval
Executable file
@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env ruby
|
||||
# Checks if a given license meets the approval criteria to be added to choosealicense.com
|
||||
# See https://github.com/github/choosealicense.com/blob/gh-pages/CONTRIBUTING.md#adding-a-license
|
||||
# Usage: script/check-approval [SPDX LICENSE ID]
|
||||
|
||||
require_relative '../spec/spec_helper'
|
||||
require 'terminal-table'
|
||||
require 'colored'
|
||||
require 'fuzzy_match'
|
||||
|
||||
# Display usage instructions
|
||||
if ARGV.count != 1
|
||||
puts File.open(__FILE__).read.scan(/^# .*/)[0...3].join("\n").gsub(/^# /,"")
|
||||
end
|
||||
|
||||
class TrueClass
|
||||
def to_s
|
||||
"Yes".green
|
||||
end
|
||||
end
|
||||
|
||||
class FalseClass
|
||||
def to_s
|
||||
"No".red
|
||||
end
|
||||
end
|
||||
|
||||
license = ARGV[0].downcase.strip
|
||||
approvals = {
|
||||
"OSI": osi_approved_licenses,
|
||||
"FSF": fsf_approved_licenses,
|
||||
"OD": od_approved_licenses
|
||||
}
|
||||
|
||||
id, spdx = find_spdx(license)
|
||||
rows = []
|
||||
|
||||
if spdx.nil?
|
||||
id = "Invalid".red
|
||||
name = "None".red
|
||||
else
|
||||
id = id.green
|
||||
name = spdx["name"].green
|
||||
end
|
||||
|
||||
rows << ["SPDX ID", id]
|
||||
rows << ["SPDX Name", name]
|
||||
|
||||
approvals.each do |name, licenses|
|
||||
rows << ["#{name} approved", licenses.include?(license)]
|
||||
end
|
||||
|
||||
current = license_ids.include?(license)
|
||||
rows << ["Current license", current]
|
||||
|
||||
rows << :separator
|
||||
eligible = !!(!current && spdx && approved_licenses.include?(license))
|
||||
rows << ["Eligible", eligible]
|
||||
|
||||
puts Terminal::Table.new title: "License: #{license}", rows: rows
|
||||
puts
|
||||
puts "Code search: https://github.com/search?q=#{license}+filename%3ALICENSE&type=Code"
|
||||
|
||||
if spdx.nil?
|
||||
puts
|
||||
puts "SPDX ID not found. Some possible matches:"
|
||||
puts
|
||||
|
||||
fm = FuzzyMatch.new(spdx_ids)
|
||||
matches = fm.find_all_with_score(license)
|
||||
matches = matches[0...5].map { |record, _dice, _levin| record }
|
||||
matches.each { |l| puts "* #{l}" }
|
||||
end
|
@ -19,7 +19,14 @@ def config
|
||||
end
|
||||
|
||||
def licenses
|
||||
site.collections["licenses"].docs.map { |l| l.to_liquid.merge("id" => l.basename(".txt")) }
|
||||
site.collections["licenses"].docs.map do |license|
|
||||
id = File.basename(license.basename, ".txt")
|
||||
license.to_liquid.merge("id" => id)
|
||||
end
|
||||
end
|
||||
|
||||
def license_ids
|
||||
licenses.map { |l| l["id"] }
|
||||
end
|
||||
|
||||
def families
|
||||
|
Loading…
x
Reference in New Issue
Block a user