utils: add SPDX module
This commit is contained in:
parent
c5d3a4a0ed
commit
753b8621df
@ -4,6 +4,7 @@ require "formula"
|
||||
require "formula_versions"
|
||||
require "utils/curl"
|
||||
require "utils/notability"
|
||||
require "utils/spdx"
|
||||
require "extend/ENV"
|
||||
require "formula_cellar_checks"
|
||||
require "cmd/search"
|
||||
@ -118,8 +119,7 @@ module Homebrew
|
||||
# Check style in a single batch run up front for performance
|
||||
style_results = Style.check_style_json(style_files, options) if style_files
|
||||
# load licenses
|
||||
spdx = HOMEBREW_LIBRARY_PATH/"data/spdx.json"
|
||||
spdx_data = JSON.parse(spdx.read)
|
||||
spdx_data = SPDX.spdx_data
|
||||
new_formula_problem_lines = []
|
||||
audit_formulae.sort.each do |f|
|
||||
only = only_cops ? ["style"] : args.only
|
||||
|
||||
@ -1,14 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cli/parser"
|
||||
require "utils/github"
|
||||
require "utils/spdx"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
SPDX_PATH = (HOMEBREW_LIBRARY_PATH/"data/spdx.json").freeze
|
||||
SPDX_API_URL = "https://api.github.com/repos/spdx/license-list-data/releases/latest"
|
||||
|
||||
def update_license_data_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
usage_banner <<~EOS
|
||||
@ -29,16 +26,14 @@ module Homebrew
|
||||
args = update_license_data_args.parse
|
||||
ohai "Updating SPDX license data..."
|
||||
|
||||
latest_tag = GitHub.open_api(SPDX_API_URL)["tag_name"]
|
||||
data_url = "https://raw.githubusercontent.com/spdx/license-list-data/#{latest_tag}/json/licenses.json"
|
||||
curl_download(data_url, to: SPDX_PATH, partial: false)
|
||||
SPDX.download_latest_license_data!
|
||||
|
||||
Homebrew.failed = system("git", "diff", "--stat", "--exit-code", SPDX_PATH) if args.fail_if_not_changed?
|
||||
Homebrew.failed = system("git", "diff", "--stat", "--exit-code", SPDX::JSON_PATH) if args.fail_if_not_changed?
|
||||
|
||||
return unless args.commit?
|
||||
|
||||
ohai "git add"
|
||||
safe_system "git", "add", SPDX_PATH
|
||||
safe_system "git", "add", SPDX::JSON_PATH
|
||||
ohai "git commit"
|
||||
system "git", "commit", "--message", "data/spdx.json: update to #{latest_tag}"
|
||||
end
|
||||
|
||||
20
Library/Homebrew/utils/spdx.rb
Normal file
20
Library/Homebrew/utils/spdx.rb
Normal file
@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "utils/github"
|
||||
|
||||
module SPDX
|
||||
module_function
|
||||
|
||||
JSON_PATH = (HOMEBREW_LIBRARY_PATH/"data/spdx.json").freeze
|
||||
API_URL = "https://api.github.com/repos/spdx/license-list-data/releases/latest"
|
||||
|
||||
def spdx_data
|
||||
@spdx_data ||= JSON.parse(JSON_PATH.read)
|
||||
end
|
||||
|
||||
def download_latest_license_data!
|
||||
latest_tag = GitHub.open_api(API_URL)["tag_name"]
|
||||
data_url = "https://raw.githubusercontent.com/spdx/license-list-data/#{latest_tag}/json/licenses.json"
|
||||
curl_download(data_url, to: JSON_PATH, partial: false)
|
||||
end
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user