1
0
mirror of https://github.com/github/choosealicense.com synced 2024-12-22 12:50:24 +01:00
choosealicense.com/script/check-approval
W. Trevor King 45369acf79 check-approval: Fix missing license_ids variable
Avoid:

   $ ./script/check-approval MIT
   ./script/check-approval:55:in `<main>': undefined local variable or method `license_ids' for main:Object (NameError)

The license_ids line was added in e505eb8f (check if license is aleady
a license, 2016-01-18, #318), but license_ids was removed from the
helper in b99e7ab0 (replace 'id' variables with 'spdx_lcase' to
minimize confusion, 2016-06-01, #424).  This commit restores the old
code locally, since this script is the only consumer.
2018-01-03 11:58:21 -08:00

77 lines
1.7 KiB
Ruby
Executable File

#!/usr/bin/env ruby
# frozen_string_literal: true
# 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 |approver, licenses|
rows << ["#{approver} approved", licenses.include?(license)]
end
license_ids = licenses.map { |l| l['id'] }
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