Code review changes

This commit is contained in:
Douglas Eichelberger 2023-03-25 17:39:39 -07:00
parent 7720485f40
commit 1c411f6086
2 changed files with 8 additions and 6 deletions

View File

@ -745,7 +745,7 @@ on_request: installed_on_request?, options: options)
fi.finish fi.finish
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
ignore_interrupts do ignore_interrupts do
tmp_keg.rename(installed_keg.to_s) if tmp_keg && !installed_keg.directory? tmp_keg.rename(installed_keg.to_path) if tmp_keg && !installed_keg.directory?
linked_keg.link(verbose: verbose?) if keg_was_linked linked_keg.link(verbose: verbose?) if keg_was_linked
end end
raise unless e.is_a? FormulaInstallationAlreadyAttemptedError raise unless e.is_a? FormulaInstallationAlreadyAttemptedError

View File

@ -130,10 +130,10 @@ module Formulary
end end
def self.load_formula_from_api(name, flags:) def self.load_formula_from_api(name, flags:)
namespace = "FormulaNamespaceAPI#{Digest::MD5.hexdigest(name)}" namespace = :"FormulaNamespaceAPI#{Digest::MD5.hexdigest(name)}"
mod = Module.new mod = Module.new
remove_const(namespace.to_sym) if const_defined?(namespace) remove_const(namespace) if const_defined?(namespace)
const_set(namespace, mod) const_set(namespace, mod)
mod.const_set(:BUILD_FLAGS, flags) mod.const_set(:BUILD_FLAGS, flags)
@ -491,14 +491,16 @@ module Formulary
def initialize(url, from: nil) def initialize(url, from: nil)
@url = url @url = url
@from = from @from = from
uri_path = T.must(URI(url).path) uri_path = URI(url).path
raise ArgumentError, "URL has no path component" unless uri_path
formula = File.basename(uri_path, ".rb") formula = File.basename(uri_path, ".rb")
super formula, HOMEBREW_CACHE_FORMULA/File.basename(uri_path) super formula, HOMEBREW_CACHE_FORMULA/File.basename(uri_path)
end end
def load_file(flags:, ignore_errors:) def load_file(flags:, ignore_errors:)
if @from != :formula_installer if @from != :formula_installer
if (md = %r{githubusercontent.com/[\w-]+/[\w-]+/[a-f0-9]{40}(?:/Formula)?/(?<name>[\w+-.@]+).rb}.match(url)) if (md = url.match(%r{githubusercontent.com/[\w-]+/[\w-]+/[a-f0-9]{40}(?:/Formula)?/(?<name>[\w+-.@]+).rb}))
raise UnsupportedInstallationMethod, raise UnsupportedInstallationMethod,
"Installation of #{md[:name]} from a GitHub commit URL is unsupported! " \ "Installation of #{md[:name]} from a GitHub commit URL is unsupported! " \
"`brew extract #{md[:name]}` to a stable tap on GitHub instead." "`brew extract #{md[:name]}` to a stable tap on GitHub instead."
@ -514,7 +516,7 @@ module Formulary
curl_download url, to: path curl_download url, to: path
super super
rescue MethodDeprecatedError => e rescue MethodDeprecatedError => e
if (match_data = %r{github.com/(?<user>[\w-]+)/(?<repo>[\w-]+)/}.match(url)) if (match_data = url.match(%r{github.com/(?<user>[\w-]+)/(?<repo>[\w-]+)/}))
e.issues_url = "https://github.com/#{match_data[:user]}/#{match_data[:repo]}/issues/new" e.issues_url = "https://github.com/#{match_data[:user]}/#{match_data[:repo]}/issues/new"
end end
raise raise