1
0
mirror of https://github.com/github/choosealicense.com synced 2024-12-23 05:10:11 +01:00
choosealicense.com/script/check-approval

74 lines
1.6 KiB
Plaintext
Raw Normal View History

2016-01-18 16:16:40 -05:00
#!/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'
2016-01-18 16:39:03 -05:00
require 'fuzzy_match'
2016-01-18 16:16:40 -05:00
# 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
2016-01-18 17:05:02 -05:00
current = license_ids.include?(license)
rows << ["Current license", current]
2016-01-18 16:16:40 -05:00
rows << :separator
2016-01-18 17:05:02 -05:00
eligible = !!(!current && spdx && approved_licenses.include?(license))
2016-01-18 16:20:33 -05:00
rows << ["Eligible", eligible]
2016-01-18 16:16:40 -05:00
puts Terminal::Table.new title: "License: #{license}", rows: rows
2016-01-18 16:19:29 -05:00
puts
puts "Code search: https://github.com/search?q=#{license}+filename%3ALICENSE&type=Code"
2016-01-18 16:39:03 -05:00
if spdx.nil?
puts
puts "SPDX ID not found. Some possible matches:"
puts
2016-01-18 17:05:02 -05:00
2016-01-18 16:39:03 -05:00
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