audit: fixed with PR comments. Refactored get_repo_license api call and audit_license only new_formula

This commit is contained in:
Lionell 2020-06-18 00:44:33 +08:00
parent f1cd404839
commit 610dfe0fc2
2 changed files with 24 additions and 13 deletions

View File

@ -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|

View File

@ -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