formula_audit: Check the license(s) of the specific release

- Some repositories occasionally change their licenses. For example they
  release a version of the software with one license and then decide to change
  the license later.
- Now that `?ref=` is a parameter to the GitHub Repositories License API,
  we can use that in the license audit to check if the license of the specific
  release matches the one declared in the formula.
This commit is contained in:
Issy Long 2024-02-27 16:53:54 +00:00
parent 18571e8991
commit c2507fdc6d
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4
2 changed files with 6 additions and 3 deletions

View File

@ -255,7 +255,8 @@ module Homebrew
user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*}) user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*})
return if user.blank? return if user.blank?
github_license = GitHub.get_repo_license(user, repo) tag = SharedAudits.github_tag_from_url(formula.stable.url)
github_license = GitHub.get_repo_license(user, repo, ref: tag)
return unless github_license return unless github_license
return if (licenses + ["NOASSERTION"]).include?(github_license) return if (licenses + ["NOASSERTION"]).include?(github_license)
return if PERMITTED_LICENSE_MISMATCHES[github_license]&.any? { |license| licenses.include? license } return if PERMITTED_LICENSE_MISMATCHES[github_license]&.any? { |license| licenses.include? license }

View File

@ -497,8 +497,10 @@ module GitHub
end end
end end
def self.get_repo_license(user, repo) def self.get_repo_license(user, repo, ref: nil)
response = API.open_rest("#{API_URL}/repos/#{user}/#{repo}/license") url = "#{API_URL}/repos/#{user}/#{repo}/license"
url += "?ref=#{ref}" if ref.present?
response = API.open_rest(url)
return unless response.key?("license") return unless response.key?("license")
response["license"]["spdx_id"] response["license"]["spdx_id"]