Update deprecations

Add more deprecations, disable deprecations and remove disabled code.
This commit is contained in:
Mike McQuaid 2020-05-18 13:50:43 +01:00
parent ca5eac845d
commit 4f75a77b08
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
35 changed files with 75 additions and 420 deletions

View File

@ -84,7 +84,7 @@ module CleanupRefinement
return true return true
end end
return true if scrub && !formula.installed? return true if scrub && !formula.latest_version_installed?
return true if Utils::Bottles.file_outdated?(formula, self) return true if Utils::Bottles.file_outdated?(formula, self)

View File

@ -84,11 +84,7 @@ module Homebrew
require "formula" require "formula"
@formulae ||= (downcased_unique_named - casks).map do |name| @formulae ||= (downcased_unique_named - casks).map do |name|
if name.include?("/") || File.exist?(name) Formulary.factory(name, spec)
Formulary.factory(name, spec)
else
Formulary.find_with_priority(name, spec)
end
end.uniq(&:name).freeze end.uniq(&:name).freeze
end end

View File

@ -359,11 +359,7 @@ module Homebrew
named_args.map do |arg| named_args.map do |arg|
next if arg.match?(HOMEBREW_CASK_TAP_CASK_REGEX) next if arg.match?(HOMEBREW_CASK_TAP_CASK_REGEX)
if arg.include?("/") || arg.end_with?(".tar.gz") || File.exist?(arg) Formulary.factory(arg, spec)
Formulary.factory(arg, spec)
else
Formulary.find_with_priority(arg.downcase, spec)
end
end.compact.uniq(&:name) end.compact.uniq(&:name)
end end
end end

View File

@ -36,7 +36,6 @@ module Homebrew
shell = if args.plain? shell = if args.plain?
nil nil
elsif args.shell.nil? elsif args.shell.nil?
# legacy behavior
:bash unless $stdout.tty? :bash unless $stdout.tty?
elsif args.shell == "auto" elsif args.shell == "auto"
Utils::Shell.parent || Utils::Shell.preferred Utils::Shell.parent || Utils::Shell.preferred

View File

@ -105,11 +105,7 @@ module Homebrew
args.named.each_with_index do |f, i| args.named.each_with_index do |f, i|
puts unless i.zero? puts unless i.zero?
begin begin
formula = if f.include?("/") || File.exist?(f) Formulary.factory(f)
Formulary.factory(f)
else
Formulary.find_with_priority(f)
end
if args.analytics? if args.analytics?
Utils::Analytics.formula_output(formula) Utils::Analytics.formula_output(formula)
else else

View File

@ -1,18 +0,0 @@
# frozen_string_literal: true
require "cli/parser"
module Homebrew
module_function
def tap_pin_args
Homebrew::CLI::Parser.new do
hide_from_man_page!
end
end
def tap_pin
odisabled "the brew tap-pin command",
"fully-scoped user/tap/formula naming when installing and in dependency references"
end
end

View File

@ -1,18 +0,0 @@
# frozen_string_literal: true
require "cli/parser"
module Homebrew
module_function
def tap_unpin_args
Homebrew::CLI::Parser.new do
hide_from_man_page!
end
end
def tap_unpin
odisabled "the brew tap-unpin command",
"fully-scoped user/tap/formula naming when installing and in dependency references"
end
end

View File

@ -216,7 +216,7 @@ module Homebrew
ensure ensure
# restore previous installation state if build failed # restore previous installation state if build failed
begin begin
linked_kegs.each(&:link) unless f.installed? linked_kegs.each(&:link) unless f.latest_version_installed?
rescue rescue
nil nil
end end

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
require "compat/cask/dsl/version" require "compat/extend/nil"
require "compat/language/python" require "compat/extend/string"
require "compat/requirements/macos_requirement"
require "compat/formula" require "compat/formula"
require "compat/language/python"
require "compat/os/mac" if OS.mac? require "compat/os/mac" if OS.mac?

View File

@ -1,23 +0,0 @@
# frozen_string_literal: true
module Cask
class DSL
class Version < ::String
module Compat
def dots_to_slashes
odisabled "#dots_to_slashes"
end
def hyphens_to_slashes
odisabled "#hyphens_to_slashes"
end
def underscores_to_slashes
odisabled "#underscores_to_slashes"
end
end
prepend Compat
end
end
end

View File

@ -0,0 +1,11 @@
# frozen_string_literal: true
class NilClass
module Compat
def chuzzle
odeprecated "chuzzle", "chomp.presence"
end
end
prepend Compat
end

View File

@ -0,0 +1,15 @@
# frozen_string_literal: true
class String
module Compat
# String.chomp, but if result is empty: returns nil instead.
# Allows `chuzzle || foo` short-circuits.
def chuzzle
odeprecated "chuzzle", "chomp.presence"
s = chomp
s unless s.empty?
end
end
prepend Compat
end

View File

@ -3,10 +3,19 @@
class Formula class Formula
module Compat module Compat
def installed? def installed?
# odeprecated "Formula#installed?", odeprecated "Formula#installed?",
# "Formula#latest_version_installed? (or Formula#any_version_installed? )" "Formula#latest_version_installed? (or Formula#any_version_installed? )"
latest_version_installed? latest_version_installed?
end end
def prepare_patches
if respond_to?(:patches)
active_spec.add_legacy_patches(patches)
odeprecated "patches", "patch do"
end
super
end
end end
prepend Compat prepend Compat

View File

@ -5,7 +5,7 @@ module Language
module Cabal module Cabal
module Compat module Compat
def cabal_sandbox(options = {}) def cabal_sandbox(options = {})
# odeprecated "Language::Haskell::Cabal.cabal_sandbox" odeprecated "Language::Haskell::Cabal.cabal_sandbox"
pwd = Pathname.pwd pwd = Pathname.pwd
home = options[:home] || pwd home = options[:home] || pwd
@ -41,14 +41,14 @@ module Language
end end
def cabal_sandbox_add_source(*args) def cabal_sandbox_add_source(*args)
# odeprecated "Language::Haskell::Cabal.cabal_sandbox_add_source" odeprecated "Language::Haskell::Cabal.cabal_sandbox_add_source"
system "cabal", "v1-sandbox", "add-source", *args system "cabal", "v1-sandbox", "add-source", *args
end end
def cabal_install(*args) def cabal_install(*args)
# odeprecated "Language::Haskell::Cabal.cabal_install", odeprecated "Language::Haskell::Cabal.cabal_install",
# "cabal v2-install directly with std_cabal_v2_args" "cabal v2-install directly with std_cabal_v2_args"
# cabal hardcodes 64 as the maximum number of parallel jobs # cabal hardcodes 64 as the maximum number of parallel jobs
# https://github.com/Homebrew/legacy-homebrew/issues/49509 # https://github.com/Homebrew/legacy-homebrew/issues/49509
@ -64,13 +64,13 @@ module Language
end end
def cabal_configure(flags) def cabal_configure(flags)
# odeprecated "Language::Haskell::Cabal.cabal_configure" odeprecated "Language::Haskell::Cabal.cabal_configure"
system "cabal", "v1-configure", flags system "cabal", "v1-configure", flags
end end
def cabal_install_tools(*tools) def cabal_install_tools(*tools)
# odeprecated "Language::Haskell::Cabal.cabal_install_tools" odeprecated "Language::Haskell::Cabal.cabal_install_tools"
# install tools sequentially, as some tools can depend on other tools # install tools sequentially, as some tools can depend on other tools
tools.each { |tool| cabal_install tool } tools.each { |tool| cabal_install tool }
@ -81,8 +81,8 @@ module Language
end end
def install_cabal_package(*args, **options) def install_cabal_package(*args, **options)
# odeprecated "Language::Haskell::Cabal.install_cabal_package", odeprecated "Language::Haskell::Cabal.install_cabal_package",
# "cabal v2-update directly followed by v2-install with std_cabal_v2_args" "cabal v2-update directly followed by v2-install with std_cabal_v2_args"
cabal_sandbox do cabal_sandbox do
cabal_install_tools(*options[:using]) if options[:using] cabal_install_tools(*options[:using]) if options[:using]

View File

@ -5,6 +5,8 @@ module Language
class << self class << self
module Compat module Compat
def rewrite_python_shebang(python_path) def rewrite_python_shebang(python_path)
odeprecated "Language::Python.rewrite_python_shebang",
"Utils::Shebang.rewrite_shebang and Shebang.python_shebang_rewrite_info(python_path)"
Pathname.pwd.find do |f| Pathname.pwd.find do |f|
Utils::Shebang.rewrite_shebang(Shebang.python_shebang_rewrite_info(python_path), f) Utils::Shebang.rewrite_shebang(Shebang.python_shebang_rewrite_info(python_path), f)
end end

View File

@ -5,7 +5,7 @@ module OS
class << self class << self
module Compat module Compat
def preferred_arch def preferred_arch
# odeprecated "MacOS.preferred_arch", "Hardware::CPU.arch (or ideally let the compiler handle it)" odeprecated "MacOS.preferred_arch", "Hardware::CPU.arch (or ideally let the compiler handle it)"
if Hardware::CPU.is_64_bit? if Hardware::CPU.is_64_bit?
Hardware::CPU.arch_64_bit Hardware::CPU.arch_64_bit
else else
@ -14,12 +14,12 @@ module OS
end end
def tcc_db def tcc_db
# odeprecated "MacOS.tcc_db" odeprecated "MacOS.tcc_db"
@tcc_db ||= Pathname.new("/Library/Application Support/com.apple.TCC/TCC.db") @tcc_db ||= Pathname.new("/Library/Application Support/com.apple.TCC/TCC.db")
end end
def pre_mavericks_accessibility_dotfile def pre_mavericks_accessibility_dotfile
# odeprecated "MacOS.pre_mavericks_accessibility_dotfile" odeprecated "MacOS.pre_mavericks_accessibility_dotfile"
@pre_mavericks_accessibility_dotfile ||= Pathname.new("/private/var/db/.AccessibilityAPIEnabled") @pre_mavericks_accessibility_dotfile ||= Pathname.new("/private/var/db/.AccessibilityAPIEnabled")
end end
end end

View File

@ -1,35 +0,0 @@
# frozen_string_literal: true
class MacOSRequirement < Requirement
module Compat
def initialize(tags = [], comparator: ">=")
if tags.first.respond_to?(:map)
versions, *rest = tags
versions = versions.map do |v|
next v if v.is_a?(Symbol)
sym = MacOS::Version.new(v).to_sym
odisabled "depends_on macos: #{v.inspect}",
"depends_on macos: #{sym.inspect}"
sym
end
tags = [versions, *rest]
elsif !tags.empty? && !tags.first.is_a?(Symbol)
v, *rest = tags
sym = MacOS::Version.new(v).to_sym
odisabled "depends_on macos: #{v.inspect}",
"depends_on macos: #{sym.inspect}"
tags = [sym, *rest]
end
super(tags, comparator: comparator)
end
end
prepend Compat
end

View File

@ -134,19 +134,8 @@ module Homebrew
end end
end end
created_pr_comment = false new_formula_problem_count += new_formula_problem_lines.size
if new_formula && !new_formula_problem_lines.empty? puts new_formula_problem_lines.map { |s| " #{s}" }
begin
created_pr_comment = true if GitHub.create_issue_comment(new_formula_problem_lines.join("\n"))
rescue *GitHub.api_errors => e
opoo "Unable to create issue comment: #{e.message}"
end
end
unless created_pr_comment
new_formula_problem_count += new_formula_problem_lines.size
puts new_formula_problem_lines.map { |s| " #{s}" }
end
total_problems_count = problem_count + new_formula_problem_count total_problems_count = problem_count + new_formula_problem_count
problem_plural = "#{total_problems_count} #{"problem".pluralize(total_problems_count)}" problem_plural = "#{total_problems_count} #{"problem".pluralize(total_problems_count)}"

View File

@ -38,7 +38,7 @@ module Homebrew
if args.examples? if args.examples?
puts "'v8'.f # => instance of the v8 formula" puts "'v8'.f # => instance of the v8 formula"
puts ":hub.f.installed?" puts ":hub.f.latest_version_installed?"
puts ":lua.f.methods - 1.methods" puts ":lua.f.methods - 1.methods"
puts ":mpd.f.recursive_dependencies.reject(&:installed?)" puts ":mpd.f.recursive_dependencies.reject(&:installed?)"
return return

View File

@ -60,7 +60,7 @@ module Homebrew
rescue FormulaUnavailableError rescue FormulaUnavailableError
nil nil
else else
if gnupg.installed? if gnupg.any_version_installed?
path = PATH.new(ENV.fetch("PATH")) path = PATH.new(ENV.fetch("PATH"))
path.prepend(gnupg.installed_prefix/"bin") path.prepend(gnupg.installed_prefix/"bin")
ENV["PATH"] = path ENV["PATH"] = path

View File

@ -56,7 +56,7 @@ module Homebrew
gnupg = Formula["gnupg"] gnupg = Formula["gnupg"]
rescue FormulaUnavailableError # rubocop:disable Lint/SuppressedException rescue FormulaUnavailableError # rubocop:disable Lint/SuppressedException
else else
if gnupg.installed? if gnupg.any_version_installed?
path = PATH.new(ENV.fetch("PATH")) path = PATH.new(ENV.fetch("PATH"))
path.prepend(gnupg.installed_prefix/"bin") path.prepend(gnupg.installed_prefix/"bin")
ENV["PATH"] = path ENV["PATH"] = path

View File

@ -398,15 +398,6 @@ class Pathname
basename.to_s == ".DS_Store" basename.to_s == ".DS_Store"
end end
# https://bugs.ruby-lang.org/issues/9915
if RUBY_VERSION == "2.0.0"
prepend Module.new {
def inspect
super.force_encoding(@path.encoding)
end
}
end
def binary_executable? def binary_executable?
false false
end end

View File

@ -2,21 +2,6 @@
require "active_support/core_ext/object/blank" require "active_support/core_ext/object/blank"
class String
# String.chomp, but if result is empty: returns nil instead.
# Allows `chuzzle || foo` short-circuits.
# TODO: Deprecate.
def chuzzle
s = chomp
s unless s.empty?
end
end
class NilClass
# TODO: Deprecate.
def chuzzle; end
end
# Used by the inreplace function (in `utils.rb`). # Used by the inreplace function (in `utils.rb`).
module StringInreplaceExtension module StringInreplaceExtension
attr_accessor :errors attr_accessor :errors

View File

@ -2090,7 +2090,6 @@ class Formula
private private
def prepare_patches def prepare_patches
active_spec.add_legacy_patches(patches) if respond_to?(:patches)
patchlist.grep(DATAPatch) { |p| p.path = path } patchlist.grep(DATAPatch) { |p| p.path = path }
end end
@ -2171,7 +2170,10 @@ class Formula
raise "You cannot override Formula#brew in class #{name}" raise "You cannot override Formula#brew in class #{name}"
when :test when :test
define_method(:test_defined?) { true } define_method(:test_defined?) { true }
when :patches
odeprecated "a Formula#patches definition", "'patch do' block calls"
when :options when :options
odeprecated "a Formula#options definition", "'option do' block calls"
instance = allocate instance = allocate
specs.each do |spec| specs.each do |spec|

View File

@ -589,7 +589,7 @@ class FormulaInstaller
linked_keg.unlink linked_keg.unlink
end end
if df.installed? if df.latest_version_installed?
installed_keg = Keg.new(df.prefix) installed_keg = Keg.new(df.prefix)
tmp_keg = Pathname.new("#{installed_keg}.tmp") tmp_keg = Pathname.new("#{installed_keg}.tmp")
installed_keg.rename(tmp_keg) installed_keg.rename(tmp_keg)

View File

@ -205,21 +205,16 @@ module Formulary
def load_file def load_file
if url =~ %r{githubusercontent.com/[\w-]+/[\w-]+/[a-f0-9]{40}(/Formula)?/([\w+-.@]+).rb} if url =~ %r{githubusercontent.com/[\w-]+/[\w-]+/[a-f0-9]{40}(/Formula)?/([\w+-.@]+).rb}
formula_name = Regexp.last_match(2) formula_name = Regexp.last_match(2)
opoo <<~EOS odeprecated "Installation of #{formula_name} from a commit URL",
Unsupported installation from a commit URL! "Use 'brew extract #{formula_name}' to stable tap."
Consider using `brew extract #{formula_name} ...` instead!"
This will extract your desired #{formula_name} version to a stable tap instead of
installing from a commit URL that cannnot receive updates or fixes!
EOS
end end
HOMEBREW_CACHE_FORMULA.mkpath HOMEBREW_CACHE_FORMULA.mkpath
FileUtils.rm_f(path) FileUtils.rm_f(path)
curl_download url, to: path curl_download url, to: path
super super
rescue MethodDeprecatedError => e rescue MethodDeprecatedError => e
if url =~ %r{github.com/([\w-]+)/homebrew-([\w-]+)/} if url =~ %r{github.com/([\w-]+)/([\w-]+)/}
e.issues_url = "https://github.com/#{Regexp.last_match(1)}/homebrew-#{Regexp.last_match(2)}/issues/new" e.issues_url = "https://github.com/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}/issues/new"
end end
raise raise
end end
@ -483,20 +478,4 @@ module Formulary
]).find(&:file?) ]).find(&:file?)
end.compact end.compact
end end
def self.find_with_priority(ref, spec = :stable)
possible_pinned_tap_formulae = tap_paths(ref, Dir["#{HOMEBREW_LIBRARY}/PinnedTaps/*/*/"]).map(&:realpath)
raise TapFormulaAmbiguityError.new(ref, possible_pinned_tap_formulae) if possible_pinned_tap_formulae.size > 1
if possible_pinned_tap_formulae.size == 1
selected_formula = factory(possible_pinned_tap_formulae.first, spec)
if core_path(ref).file?
odisabled "the brew tap-pin command",
"fully-scoped user/tap/formula naming when installing and in dependency references"
end
selected_formula
else
factory(ref, spec)
end
end
end end

View File

@ -33,7 +33,7 @@ module Language
next if build.without? python_formula.to_s next if build.without? python_formula.to_s
version = major_minor_version python version = major_minor_version python
ENV["PYTHONPATH"] = if python_formula.installed? ENV["PYTHONPATH"] = if python_formula.latest_version_installed?
nil nil
else else
homebrew_site_packages(python) homebrew_site_packages(python)

View File

@ -169,6 +169,7 @@ end
# Legacy patches have no checksum and are not cached. # Legacy patches have no checksum and are not cached.
class LegacyPatch < ExternalPatch class LegacyPatch < ExternalPatch
def initialize(strip, url) def initialize(strip, url)
odeprecated "legacy patches", "'patch do' blocks"
super(strip) super(strip)
resource.url(url) resource.url(url)
resource.download_strategy = CurlDownloadStrategy resource.download_strategy = CurlDownloadStrategy

View File

@ -111,7 +111,7 @@ class JavaRequirement < Requirement
rescue FormulaUnavailableError rescue FormulaUnavailableError
nil nil
end end
javas << jdk.bin/"java" if jdk&.installed? javas << jdk.bin/"java" if jdk&.latest_version_installed?
javas << which("java") javas << which("java")
javas javas
end end

View File

@ -221,6 +221,7 @@ class SoftwareSpec
end end
end end
# TODO
def add_legacy_patches(list) def add_legacy_patches(list)
list = Patch.normalize_legacy_patches(list) list = Patch.normalize_legacy_patches(list)
list.each { |p| p.owner = self } list.each { |p| p.owner = self }

View File

@ -644,25 +644,6 @@ describe Formula do
expect(f.head.version).to eq(Version.create("HEAD-5658946")) expect(f.head.version).to eq(Version.create("HEAD-5658946"))
end end
specify "legacy options" do
f = formula do
url "foo-1.0"
def options
[
["--foo", "desc"],
["--bar", "desc"],
]
end
option("baz")
end
expect(f).to have_option_defined("foo")
expect(f).to have_option_defined("bar")
expect(f).to have_option_defined("baz")
end
specify "#desc" do specify "#desc" do
f = formula do f = formula do
desc "a formula" desc "a formula"
@ -673,23 +654,6 @@ describe Formula do
expect(f.desc).to eq("a formula") expect(f.desc).to eq("a formula")
end end
specify "#test_defined?" do
f1 = formula do
url "foo-1.0"
def test
# do nothing
end
end
f2 = formula do
url "foo-1.0"
end
expect(f1).to have_test_defined
expect(f2).not_to have_test_defined
end
specify "test fixtures" do specify "test fixtures" do
f1 = formula do f1 = formula do
url "foo-1.0" url "foo-1.0"

View File

@ -234,22 +234,6 @@ describe Formulary do
end end
end end
describe "::find_with_priority" do
let(:core_path) { CoreTap.new.formula_dir/"#{formula_name}.rb" }
let(:tap) { Tap.new("homebrew", "foo") }
let(:tap_path) { tap.path/"#{formula_name}.rb" }
before do
core_path.write formula_content
tap_path.write formula_content
end
it "prioritizes core Formulae" do
formula = described_class.find_with_priority(formula_name)
expect(formula.path).to eq(core_path)
end
end
describe "::core_path" do describe "::core_path" do
it "returns the path to a Formula in the core tap" do it "returns the path to a Formula in the core tap" do
name = "foo-bar" name = "foo-bar"

View File

@ -74,74 +74,6 @@ describe Patch do
expect(subject.patch_files.count).to eq(7) expect(subject.patch_files.count).to eq(7)
end end
end end
describe "#normalize_legacy_patches" do
it "can create a patch from a single string" do
patches = described_class.normalize_legacy_patches("https://brew.sh/patch.diff")
expect(patches.length).to eq(1)
expect(patches.first.strip).to eq(:p1)
end
it "can create patches from an array" do
patches = described_class.normalize_legacy_patches(
%w[https://brew.sh/patch1.diff https://brew.sh/patch2.diff],
)
expect(patches.length).to eq(2)
expect(patches.first.strip).to eq(:p1)
expect(patches.second.strip).to eq(:p1)
end
it "can create patches from a :p0 hash" do
patches = described_class.normalize_legacy_patches(
p0: "https://brew.sh/patch.diff",
)
expect(patches.length).to eq(1)
expect(patches.first.strip).to eq(:p0)
end
it "can create patches from a :p1 hash" do
patches = described_class.normalize_legacy_patches(
p1: "https://brew.sh/patch.diff",
)
expect(patches.length).to eq(1)
expect(patches.first.strip).to eq(:p1)
end
it "can create patches from a mixed hash" do
patches = described_class.normalize_legacy_patches(
p1: "https://brew.sh/patch1.diff",
p0: "https://brew.sh/patch0.diff",
)
expect(patches.length).to eq(2)
expect(patches.count { |p| p.strip == :p0 }).to eq(1)
expect(patches.count { |p| p.strip == :p1 }).to eq(1)
end
it "can create patches from a mixed hash with array" do
patches = described_class.normalize_legacy_patches(
p1: [
"https://brew.sh/patch10.diff",
"https://brew.sh/patch11.diff",
],
p0: [
"https://brew.sh/patch00.diff",
"https://brew.sh/patch01.diff",
],
)
expect(patches.length).to eq(4)
expect(patches.count { |p| p.strip == :p0 }).to eq(2)
expect(patches.count { |p| p.strip == :p1 }).to eq(2)
end
it "returns an empty array if given nil" do
expect(described_class.normalize_legacy_patches(nil)).to be_empty
end
end
end end
describe EmbeddedPatch do describe EmbeddedPatch do

View File

@ -65,16 +65,6 @@ describe "patching" do
end end
end end
specify "single_patch" do
expect(
formula do
def patches
PATCH_URL_A
end
end,
).to be_patched
end
specify "single_patch_dsl" do specify "single_patch_dsl" do
expect( expect(
formula do formula do
@ -199,46 +189,6 @@ describe "patching" do
).to be_patched ).to be_patched
end end
specify "patch_p0" do
expect(
formula do
def patches
{ p0: PATCH_URL_B }
end
end,
).to be_patched
end
specify "patch_array" do
expect(
formula do
def patches
[PATCH_URL_A]
end
end,
).to be_patched
end
specify "patch_hash" do
expect(
formula do
def patches
{ p1: PATCH_URL_A }
end
end,
).to be_patched
end
specify "patch_hash_array" do
expect(
formula do
def patches
{ p1: [PATCH_URL_A] }
end
end,
).to be_patched
end
specify "patch_string" do specify "patch_string" do
expect(formula { patch PATCH_A_CONTENTS }).to be_patched expect(formula { patch PATCH_A_CONTENTS }).to be_patched
end end
@ -247,26 +197,6 @@ describe "patching" do
expect(formula { patch :p0, PATCH_B_CONTENTS }).to be_patched expect(formula { patch :p0, PATCH_B_CONTENTS }).to be_patched
end end
specify "patch_data_constant" do
expect(
formula("test", path: Pathname.new(__FILE__).expand_path) do
def patches
:DATA
end
end,
).to be_patched
end
specify "single_patch_missing_apply_fail" do
expect(
formula do
def patches
TESTBALL_PATCHES_URL
end
end,
).to miss_apply
end
specify "single_patch_dsl_missing_apply_fail" do specify "single_patch_dsl_missing_apply_fail" do
expect( expect(
formula do formula do

View File

@ -14,8 +14,6 @@ module GitHub
ALL_SCOPES_URL = Formatter.url( ALL_SCOPES_URL = Formatter.url(
"https://github.com/settings/tokens/new?scopes=#{ALL_SCOPES.join(",")}&description=Homebrew", "https://github.com/settings/tokens/new?scopes=#{ALL_SCOPES.join(",")}&description=Homebrew",
).freeze ).freeze
PR_ENV_KEY = "HOMEBREW_NEW_FORMULA_PULL_REQUEST_URL"
PR_ENV = ENV[PR_ENV_KEY]
class Error < RuntimeError class Error < RuntimeError
attr_reader :github_message attr_reader :github_message
@ -396,37 +394,6 @@ module GitHub
open_api(uri) { |json| json.fetch("items", []) } open_api(uri) { |json| json.fetch("items", []) }
end end
def create_issue_comment(body)
return false unless PR_ENV
_, user, repo, pr = *PR_ENV.match(HOMEBREW_PULL_OR_COMMIT_URL_REGEX)
if !user || !repo || !pr
opoo <<-EOS.undent
#{PR_ENV_KEY} set but regex matched:
user: #{user.inspect}, repo: #{repo.inspect}, pr: #{pr.inspect}
EOS
return false
end
url = "#{API_URL}/repos/#{user}/#{repo}/issues/#{pr}/comments"
data = { "body" => body }
if issue_comment_exists?(user, repo, pr, body)
ohai "Skipping: identical comment exists on #{PR_ENV}"
return true
end
scopes = CREATE_ISSUE_FORK_OR_PR_SCOPES
open_api(url, data: data, scopes: scopes)
end
def issue_comment_exists?(user, repo, pr, body)
url = "#{API_URL}/repos/#{user}/#{repo}/issues/#{pr}/comments"
comments = open_api(url)
return unless comments
comments.any? { |comment| comment["body"].eql?(body) }
end
def dispatch_event(user, repo, event, **payload) def dispatch_event(user, repo, event, **payload)
url = "#{API_URL}/repos/#{user}/#{repo}/dispatches" url = "#{API_URL}/repos/#{user}/#{repo}/dispatches"
open_api(url, data: { event_type: event, client_payload: payload }, open_api(url, data: { event_type: event, client_payload: payload },