Merge branch 'license' into license-create
This commit is contained in:
commit
7b2e6644a7
@ -349,6 +349,8 @@ module Homebrew
|
|||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
def audit_license
|
def audit_license
|
||||||
|
return unless @new_formula
|
||||||
|
|
||||||
if !formula.license.blank?
|
if !formula.license.blank?
|
||||||
if @spdx_ids.key?(formula.license)
|
if @spdx_ids.key?(formula.license)
|
||||||
return unless @online
|
return unless @online
|
||||||
@ -356,7 +358,7 @@ module Homebrew
|
|||||||
user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*}, false)
|
user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*}, false)
|
||||||
return if user.nil?
|
return if user.nil?
|
||||||
|
|
||||||
github_license = get_repo_license_data(user, repo)
|
github_license = GitHub.get_repo_license(user, repo)
|
||||||
return if github_license && (github_license == formula.license)
|
return if github_license && (github_license == formula.license)
|
||||||
|
|
||||||
problem "License mismatch - Github license is: #{github_license}, "\
|
problem "License mismatch - Github license is: #{github_license}, "\
|
||||||
@ -369,18 +371,18 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_repo_license_data(user, repo)
|
# def get_github_repo_license_data(user, repo)
|
||||||
return unless @online
|
# return unless @online
|
||||||
|
#
|
||||||
begin
|
# begin
|
||||||
res = GitHub.open_api("#{GitHub::API_URL}/repos/#{user}/#{repo}/license")
|
# res = GitHub.open_api("#{GitHub::API_URL}/repos/#{user}/#{repo}/license")
|
||||||
return unless res.key?("license")
|
# return unless res.key?("license")
|
||||||
|
#
|
||||||
res["license"]["spdx_id"] || nil
|
# res["license"]["spdx_id"] || nil
|
||||||
rescue GitHub::HTTPNotFoundError
|
# rescue GitHub::HTTPNotFoundError
|
||||||
nil
|
# nil
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
|
||||||
def audit_deps
|
def audit_deps
|
||||||
@specs.each do |spec|
|
@specs.each do |spec|
|
||||||
|
|||||||
@ -106,8 +106,21 @@ module Homebrew
|
|||||||
let(:custom_spdx_id) { "zzz" }
|
let(:custom_spdx_id) { "zzz" }
|
||||||
let(:standard_mismatch_spdx_id) { "0BSD" }
|
let(:standard_mismatch_spdx_id) { "0BSD" }
|
||||||
|
|
||||||
|
it "does not check if the formula is not a new formula" do
|
||||||
|
fa = formula_auditor "foo", <<~RUBY, spdx_ids: spdx_ids, new_formula: false
|
||||||
|
class Foo < Formula
|
||||||
|
url "https://brew.sh/foo-1.0.tgz"
|
||||||
|
license ""
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
fa.audit_license
|
||||||
|
p fa.problems
|
||||||
|
expect(fa.problems).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
it "detects no license info" do
|
it "detects no license info" do
|
||||||
fa = formula_auditor "foo", <<~RUBY, spdx_ids: spdx_ids
|
fa = formula_auditor "foo", <<~RUBY, spdx_ids: spdx_ids, new_formula: true
|
||||||
class Foo < Formula
|
class Foo < Formula
|
||||||
url "https://brew.sh/foo-1.0.tgz"
|
url "https://brew.sh/foo-1.0.tgz"
|
||||||
license ""
|
license ""
|
||||||
@ -120,7 +133,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "detects if license is not a standard spdx-id" do
|
it "detects if license is not a standard spdx-id" do
|
||||||
fa = formula_auditor "foo", <<~RUBY, spdx_ids: spdx_ids
|
fa = formula_auditor "foo", <<~RUBY, spdx_ids: spdx_ids, new_formula: true
|
||||||
class Foo < Formula
|
class Foo < Formula
|
||||||
url "https://brew.sh/foo-1.0.tgz"
|
url "https://brew.sh/foo-1.0.tgz"
|
||||||
license "#{custom_spdx_id}"
|
license "#{custom_spdx_id}"
|
||||||
@ -132,7 +145,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "verifies that a license info is a standard spdx id" do
|
it "verifies that a license info is a standard spdx id" do
|
||||||
fa = formula_auditor "foo", <<~RUBY, spdx_ids: spdx_ids
|
fa = formula_auditor "foo", <<~RUBY, spdx_ids: spdx_ids, new_formula: true
|
||||||
class Foo < Formula
|
class Foo < Formula
|
||||||
url "https://brew.sh/foo-1.0.tgz"
|
url "https://brew.sh/foo-1.0.tgz"
|
||||||
license "0BSD"
|
license "0BSD"
|
||||||
@ -145,7 +158,7 @@ module Homebrew
|
|||||||
|
|
||||||
it "checks online and verifies that a standard license id is the same "\
|
it "checks online and verifies that a standard license id is the same "\
|
||||||
"as what is indicated on its Github repo" do
|
"as what is indicated on its Github repo" do
|
||||||
fa = formula_auditor "cask", <<~RUBY, spdx_ids: spdx_ids, online: true, core_tap: true
|
fa = formula_auditor "cask", <<~RUBY, spdx_ids: spdx_ids, online: true, core_tap: true, new_formula: true
|
||||||
class Cask < Formula
|
class Cask < Formula
|
||||||
url "https://github.com/cask/cask/archive/v0.8.4.tar.gz"
|
url "https://github.com/cask/cask/archive/v0.8.4.tar.gz"
|
||||||
head "https://github.com/cask/cask.git"
|
head "https://github.com/cask/cask.git"
|
||||||
@ -159,7 +172,7 @@ module Homebrew
|
|||||||
|
|
||||||
it "checks online and detects that a formula-specified license is not "\
|
it "checks online and detects that a formula-specified license is not "\
|
||||||
"the same as what is indicated on its Github repository" do
|
"the same as what is indicated on its Github repository" do
|
||||||
fa = formula_auditor "cask", <<~RUBY, online: true, spdx_ids: spdx_ids, core_tap: true
|
fa = formula_auditor "cask", <<~RUBY, online: true, spdx_ids: spdx_ids, core_tap: true, new_formula: true
|
||||||
class Cask < Formula
|
class Cask < Formula
|
||||||
url "https://github.com/cask/cask/archive/v0.8.4.tar.gz"
|
url "https://github.com/cask/cask/archive/v0.8.4.tar.gz"
|
||||||
head "https://github.com/cask/cask.git"
|
head "https://github.com/cask/cask.git"
|
||||||
|
|||||||
@ -476,6 +476,15 @@ module GitHub
|
|||||||
open_api(url, scopes: ["admin:org", "user"], data: data, request_method: "POST")
|
open_api(url, scopes: ["admin:org", "user"], data: data, request_method: "POST")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_repo_license(user, repo)
|
||||||
|
res = GitHub.open_api("#{GitHub::API_URL}/repos/#{user}/#{repo}/license")
|
||||||
|
return unless res.key?("license")
|
||||||
|
|
||||||
|
res["license"]["spdx_id"] || nil
|
||||||
|
rescue GitHub::HTTPNotFoundError
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
def api_errors
|
def api_errors
|
||||||
[GitHub::AuthenticationFailedError, GitHub::HTTPNotFoundError,
|
[GitHub::AuthenticationFailedError, GitHub::HTTPNotFoundError,
|
||||||
GitHub::RateLimitExceededError, GitHub::Error, JSON::ParserError].freeze
|
GitHub::RateLimitExceededError, GitHub::Error, JSON::ParserError].freeze
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user