Port Homebrew::DevCmd::BumpFormulaPr
This commit is contained in:
parent
ebc458a7fe
commit
d873881c47
@ -119,7 +119,9 @@ module Homebrew
|
||||
]
|
||||
end
|
||||
|
||||
sig { params(cmd: T.nilable(T.class_of(Homebrew::AbstractCommand)), block: T.nilable(T.proc.bind(Parser).void)).void }
|
||||
sig {
|
||||
params(cmd: T.nilable(T.class_of(Homebrew::AbstractCommand)), block: T.nilable(T.proc.bind(Parser).void)).void
|
||||
}
|
||||
def initialize(cmd = nil, &block)
|
||||
@parser = OptionParser.new
|
||||
|
||||
|
||||
@ -1,17 +1,16 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "formula"
|
||||
require "cli/parser"
|
||||
require "utils/pypi"
|
||||
require "utils/tar"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def bump_formula_pr_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
module DevCmd
|
||||
class BumpFormulaPr < AbstractCommand
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Create a pull request to update <formula> with a new URL or a new tag.
|
||||
|
||||
@ -89,11 +88,9 @@ module Homebrew
|
||||
|
||||
named_args :formula, max: 1, without_api: true
|
||||
end
|
||||
end
|
||||
|
||||
def bump_formula_pr
|
||||
args = bump_formula_pr_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
if args.revision.present? && args.tag.nil? && args.version.nil?
|
||||
raise UsageError, "`--revision` must be passed with either `--tag` or `--version`!"
|
||||
end
|
||||
@ -134,10 +131,10 @@ module Homebrew
|
||||
remote_branch = formula.tap.git_repo.origin_branch_name
|
||||
previous_branch = "-"
|
||||
|
||||
check_open_pull_requests(formula, tap_remote_repo, args:)
|
||||
check_open_pull_requests(formula, tap_remote_repo)
|
||||
|
||||
new_version = args.version
|
||||
check_new_version(formula, tap_remote_repo, version: new_version, args:) if new_version.present?
|
||||
check_new_version(formula, tap_remote_repo, version: new_version) if new_version.present?
|
||||
|
||||
opoo "This formula has patches that may be resolved upstream." if formula.patchlist.present?
|
||||
if formula.resources.any? { |resource| !resource.name.start_with?("homebrew-") }
|
||||
@ -149,7 +146,7 @@ module Homebrew
|
||||
new_mirror ||= determine_mirror(new_url)
|
||||
new_mirrors ||= [new_mirror] if new_mirror.present?
|
||||
|
||||
check_for_mirrors(formula, old_mirrors, new_mirrors, args:) if new_url.present?
|
||||
check_for_mirrors(formula, old_mirrors, new_mirrors) if new_url.present?
|
||||
|
||||
old_hash = formula_spec.checksum&.hexdigest
|
||||
new_hash = args.sha256
|
||||
@ -161,10 +158,10 @@ module Homebrew
|
||||
old_version = old_formula_version.to_s
|
||||
forced_version = new_version.present?
|
||||
new_url_hash = if new_url.present? && new_hash.present?
|
||||
check_new_version(formula, tap_remote_repo, url: new_url, args:) if new_version.blank?
|
||||
check_new_version(formula, tap_remote_repo, url: new_url) if new_version.blank?
|
||||
true
|
||||
elsif new_tag.present? && new_revision.present?
|
||||
check_new_version(formula, tap_remote_repo, url: old_url, tag: new_tag, args:) if new_version.blank?
|
||||
check_new_version(formula, tap_remote_repo, url: old_url, tag: new_tag) if new_version.blank?
|
||||
false
|
||||
elsif old_hash.blank?
|
||||
if new_tag.blank? && new_version.blank? && new_revision.blank?
|
||||
@ -179,8 +176,9 @@ module Homebrew
|
||||
and old tag are both #{new_tag}.
|
||||
EOS
|
||||
end
|
||||
check_new_version(formula, tap_remote_repo, url: old_url, tag: new_tag, args:) if new_version.blank?
|
||||
resource_path, forced_version = fetch_resource_and_forced_version(formula, new_version, old_url, tag: new_tag)
|
||||
check_new_version(formula, tap_remote_repo, url: old_url, tag: new_tag) if new_version.blank?
|
||||
resource_path, forced_version = fetch_resource_and_forced_version(formula, new_version, old_url,
|
||||
tag: new_tag)
|
||||
new_revision = Utils.popen_read("git", "-C", resource_path.to_s, "rev-parse", "-q", "--verify", "HEAD")
|
||||
new_revision = new_revision.strip
|
||||
elsif new_revision.blank?
|
||||
@ -190,12 +188,12 @@ module Homebrew
|
||||
elsif new_url.blank? && new_version.blank?
|
||||
raise UsageError, "#{formula}: no `--url` or `--version` argument specified!"
|
||||
else
|
||||
new_url ||= PyPI.update_pypi_url(old_url, new_version)
|
||||
new_url ||= PyPI.update_pypi_url(old_url, T.must(new_version))
|
||||
if new_url.blank?
|
||||
new_url = update_url(old_url, old_version, new_version)
|
||||
new_url = update_url(old_url, old_version, T.must(new_version))
|
||||
if new_mirrors.blank? && old_mirrors.present?
|
||||
new_mirrors = old_mirrors.map do |old_mirror|
|
||||
update_url(old_mirror, old_version, new_version)
|
||||
update_url(old_mirror, old_version, T.must(new_version))
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -206,7 +204,7 @@ module Homebrew
|
||||
#{new_url}
|
||||
EOS
|
||||
end
|
||||
check_new_version(formula, tap_remote_repo, url: new_url, args:) if new_version.blank?
|
||||
check_new_version(formula, tap_remote_repo, url: new_url) if new_version.blank?
|
||||
resource_path, forced_version = fetch_resource_and_forced_version(formula, new_version, new_url)
|
||||
Utils::Tar.validate_file(resource_path)
|
||||
new_hash = resource_path.sha256
|
||||
@ -273,7 +271,7 @@ module Homebrew
|
||||
|
||||
if new_mirrors.present?
|
||||
replacement_pairs << [
|
||||
/^( +)(url "#{Regexp.escape(new_url)}"[^\n]*?\n)/m,
|
||||
/^( +)(url "#{Regexp.escape(T.must(new_url))}"[^\n]*?\n)/m,
|
||||
"\\1\\2\\1mirror \"#{new_mirrors.join("\"\n\\1mirror \"")}\"\n",
|
||||
]
|
||||
end
|
||||
@ -344,7 +342,7 @@ module Homebrew
|
||||
ignore_non_pypi_packages: true
|
||||
end
|
||||
|
||||
run_audit(formula, alias_rename, old_contents, args:)
|
||||
run_audit(formula, alias_rename, old_contents)
|
||||
|
||||
pr_message = "Created with `brew bump-formula-pr`."
|
||||
if resources_checked.nil? && formula.resources.any? { |resource| !resource.name.start_with?("homebrew-") }
|
||||
@ -393,6 +391,8 @@ module Homebrew
|
||||
GitHub.create_bump_pr(pr_info, args:)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def determine_mirror(url)
|
||||
case url
|
||||
when %r{.*ftp\.gnu\.org/gnu.*}
|
||||
@ -406,7 +406,7 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
def check_for_mirrors(formula, old_mirrors, new_mirrors, args:)
|
||||
def check_for_mirrors(formula, old_mirrors, new_mirrors)
|
||||
return if new_mirrors.present? || old_mirrors.empty?
|
||||
|
||||
if args.force?
|
||||
@ -451,14 +451,14 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
def check_open_pull_requests(formula, tap_remote_repo, args:)
|
||||
def check_open_pull_requests(formula, tap_remote_repo)
|
||||
GitHub.check_for_duplicate_pull_requests(formula.name, tap_remote_repo,
|
||||
state: "open",
|
||||
file: formula.path.relative_path_from(formula.tap.path).to_s,
|
||||
quiet: args.quiet?)
|
||||
end
|
||||
|
||||
def check_new_version(formula, tap_remote_repo, args:, version: nil, url: nil, tag: nil)
|
||||
def check_new_version(formula, tap_remote_repo, version: nil, url: nil, tag: nil)
|
||||
if version.nil?
|
||||
specs = {}
|
||||
specs[:tag] = tag if tag.present?
|
||||
@ -467,7 +467,7 @@ module Homebrew
|
||||
end
|
||||
|
||||
check_throttle(formula, version)
|
||||
check_closed_pull_requests(formula, tap_remote_repo, args:, version:)
|
||||
check_closed_pull_requests(formula, tap_remote_repo, version:)
|
||||
end
|
||||
|
||||
def check_throttle(formula, new_version)
|
||||
@ -480,7 +480,7 @@ module Homebrew
|
||||
odie "#{formula} should only be updated every #{throttled_rate} releases on multiples of #{throttled_rate}"
|
||||
end
|
||||
|
||||
def check_closed_pull_requests(formula, tap_remote_repo, args:, version:)
|
||||
def check_closed_pull_requests(formula, tap_remote_repo, version:)
|
||||
# if we haven't already found open requests, try for an exact match across closed requests
|
||||
GitHub.check_for_duplicate_pull_requests(formula.name, tap_remote_repo,
|
||||
version:,
|
||||
@ -501,7 +501,7 @@ module Homebrew
|
||||
[versioned_alias, "#{name}@#{new_alias_version}"]
|
||||
end
|
||||
|
||||
def run_audit(formula, alias_rename, old_contents, args:)
|
||||
def run_audit(formula, alias_rename, old_contents)
|
||||
audit_args = ["--formula"]
|
||||
audit_args << "--strict" if args.strict?
|
||||
audit_args << "--online" if args.online?
|
||||
@ -533,3 +533,5 @@ module Homebrew
|
||||
odie "`brew audit` failed!"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/bump-formula-pr"
|
||||
|
||||
RSpec.describe "brew bump-formula-pr" do
|
||||
RSpec.describe Homebrew::DevCmd::BumpFormulaPr do
|
||||
it_behaves_like "parseable arguments"
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user