2016-01-18 22:16:40 +01:00
|
|
|
#!/usr/bin/env ruby
|
2017-01-18 22:31:19 +01:00
|
|
|
# frozen_string_literal: true
|
2017-03-27 02:19:44 +02:00
|
|
|
|
2016-01-18 22:16:40 +01:00
|
|
|
# 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 22:39:03 +01:00
|
|
|
require 'fuzzy_match'
|
2016-01-18 22:16:40 +01:00
|
|
|
|
|
|
|
# Display usage instructions
|
2022-01-06 02:50:10 +01:00
|
|
|
puts File.read(__FILE__).scan(/^# .*/)[0...3].join("\n").gsub(/^# /, '') if ARGV.count != 1
|
2016-01-18 22:16:40 +01:00
|
|
|
|
|
|
|
class TrueClass
|
|
|
|
def to_s
|
2016-02-08 21:37:19 +01:00
|
|
|
'Yes'.green
|
2016-01-18 22:16:40 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class FalseClass
|
|
|
|
def to_s
|
2016-02-08 21:37:19 +01:00
|
|
|
'No'.red
|
2016-01-18 22:16:40 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
license = ARGV[0].downcase.strip
|
|
|
|
approvals = {
|
2016-02-08 21:37:19 +01:00
|
|
|
'OSI' => osi_approved_licenses,
|
|
|
|
'FSF' => fsf_approved_licenses,
|
|
|
|
'OD' => od_approved_licenses
|
2016-01-18 22:16:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
id, spdx = find_spdx(license)
|
|
|
|
rows = []
|
|
|
|
|
|
|
|
if spdx.nil?
|
2016-02-08 21:37:19 +01:00
|
|
|
id = 'Invalid'.red
|
|
|
|
name = 'None'.red
|
2016-01-18 22:16:40 +01:00
|
|
|
else
|
|
|
|
id = id.green
|
2016-02-08 21:37:19 +01:00
|
|
|
name = spdx['name'].green
|
2016-01-18 22:16:40 +01:00
|
|
|
end
|
|
|
|
|
2016-02-08 21:37:19 +01:00
|
|
|
rows << ['SPDX ID', id]
|
|
|
|
rows << ['SPDX Name', name]
|
2016-01-18 22:16:40 +01:00
|
|
|
|
2016-02-08 21:37:19 +01:00
|
|
|
approvals.each do |approver, licenses|
|
|
|
|
rows << ["#{approver} approved", licenses.include?(license)]
|
2016-01-18 22:16:40 +01:00
|
|
|
end
|
|
|
|
|
2018-01-03 19:46:57 +01:00
|
|
|
license_ids = licenses.map { |l| l['id'] }
|
2016-01-18 23:05:02 +01:00
|
|
|
current = license_ids.include?(license)
|
2016-02-08 21:37:19 +01:00
|
|
|
rows << ['Current license', current]
|
2016-01-18 23:05:02 +01:00
|
|
|
|
2016-01-18 22:16:40 +01:00
|
|
|
rows << :separator
|
2016-02-08 21:37:19 +01:00
|
|
|
eligible = (!current && spdx && approved_licenses.include?(license))
|
|
|
|
rows << ['Eligible', eligible]
|
2016-01-18 22:16:40 +01:00
|
|
|
|
|
|
|
puts Terminal::Table.new title: "License: #{license}", rows: rows
|
2016-01-18 22:19:29 +01:00
|
|
|
puts
|
|
|
|
puts "Code search: https://github.com/search?q=#{license}+filename%3ALICENSE&type=Code"
|
2016-01-18 22:39:03 +01:00
|
|
|
|
|
|
|
if spdx.nil?
|
|
|
|
puts
|
2016-02-08 21:37:19 +01:00
|
|
|
puts 'SPDX ID not found. Some possible matches:'
|
2016-01-18 22:39:03 +01:00
|
|
|
puts
|
2016-01-18 23:05:02 +01:00
|
|
|
|
2016-01-18 22:39:03 +01: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
|