Merge pull request #10406 from SeekingMeaning/bump-formula-improvements
bump-formula-pr: improvements
This commit is contained in:
commit
e5fca67e0a
@ -138,6 +138,7 @@ module Homebrew
|
|||||||
raise FormulaUnspecifiedError if formula.blank?
|
raise FormulaUnspecifiedError if formula.blank?
|
||||||
|
|
||||||
odie "This formula is disabled!" if formula.disabled?
|
odie "This formula is disabled!" if formula.disabled?
|
||||||
|
odie "This formula is deprecated and does not build!" if formula.deprecation_reason == :does_not_build
|
||||||
odie "This formula is not in a tap!" if formula.tap.blank?
|
odie "This formula is not in a tap!" if formula.tap.blank?
|
||||||
odie "This formula's tap is not a Git repository!" unless formula.tap.git?
|
odie "This formula's tap is not a Git repository!" unless formula.tap.git?
|
||||||
|
|
||||||
@ -148,7 +149,7 @@ module Homebrew
|
|||||||
check_open_pull_requests(formula, tap_full_name, args: args)
|
check_open_pull_requests(formula, tap_full_name, args: args)
|
||||||
|
|
||||||
new_version = args.version
|
new_version = args.version
|
||||||
check_closed_pull_requests(formula, tap_full_name, version: new_version, args: args) if new_version.present?
|
check_new_version(formula, tap_full_name, version: new_version, args: args) if new_version.present?
|
||||||
|
|
||||||
opoo "This formula has patches that may be resolved upstream." if formula.patchlist.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-") }
|
if formula.resources.any? { |resource| !resource.name.start_with?("homebrew-") }
|
||||||
@ -172,10 +173,10 @@ module Homebrew
|
|||||||
old_version = old_formula_version.to_s
|
old_version = old_formula_version.to_s
|
||||||
forced_version = new_version.present?
|
forced_version = new_version.present?
|
||||||
new_url_hash = if new_url.present? && new_hash.present?
|
new_url_hash = if new_url.present? && new_hash.present?
|
||||||
check_closed_pull_requests(formula, tap_full_name, url: new_url, args: args) if new_version.blank?
|
check_new_version(formula, tap_full_name, url: new_url, args: args) if new_version.blank?
|
||||||
true
|
true
|
||||||
elsif new_tag.present? && new_revision.present?
|
elsif new_tag.present? && new_revision.present?
|
||||||
check_closed_pull_requests(formula, tap_full_name, url: old_url, tag: new_tag, args: args) if new_version.blank?
|
check_new_version(formula, tap_full_name, url: old_url, tag: new_tag, args: args) if new_version.blank?
|
||||||
false
|
false
|
||||||
elsif old_hash.blank?
|
elsif old_hash.blank?
|
||||||
if new_tag.blank? && new_version.blank? && new_revision.blank?
|
if new_tag.blank? && new_version.blank? && new_revision.blank?
|
||||||
@ -190,9 +191,7 @@ module Homebrew
|
|||||||
and old tag are both #{new_tag}.
|
and old tag are both #{new_tag}.
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
if new_version.blank?
|
check_new_version(formula, tap_full_name, url: old_url, tag: new_tag, args: args) if new_version.blank?
|
||||||
check_closed_pull_requests(formula, tap_full_name, url: old_url, tag: new_tag, args: args)
|
|
||||||
end
|
|
||||||
resource_path, forced_version = fetch_resource(formula, new_version, old_url, tag: new_tag)
|
resource_path, forced_version = fetch_resource(formula, new_version, old_url, tag: new_tag)
|
||||||
new_revision = Utils.popen_read("git -C \"#{resource_path}\" rev-parse -q --verify HEAD")
|
new_revision = Utils.popen_read("git -C \"#{resource_path}\" rev-parse -q --verify HEAD")
|
||||||
new_revision = new_revision.strip
|
new_revision = new_revision.strip
|
||||||
@ -219,7 +218,7 @@ module Homebrew
|
|||||||
#{new_url}
|
#{new_url}
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
check_closed_pull_requests(formula, tap_full_name, url: new_url, args: args) if new_version.blank?
|
check_new_version(formula, tap_full_name, url: new_url, args: args) if new_version.blank?
|
||||||
resource_path, forced_version = fetch_resource(formula, new_version, new_url)
|
resource_path, forced_version = fetch_resource(formula, new_version, new_url)
|
||||||
Utils::Tar.validate_file(resource_path)
|
Utils::Tar.validate_file(resource_path)
|
||||||
new_hash = resource_path.sha256
|
new_hash = resource_path.sha256
|
||||||
@ -462,14 +461,30 @@ module Homebrew
|
|||||||
args: args)
|
args: args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_closed_pull_requests(formula, tap_full_name, args:, version: nil, url: nil, tag: nil)
|
def check_new_version(formula, tap_full_name, args:, version: nil, url: nil, tag: nil)
|
||||||
if version.nil?
|
if version.nil?
|
||||||
specs = {}
|
specs = {}
|
||||||
specs[:tag] = tag if tag.present?
|
specs[:tag] = tag if tag.present?
|
||||||
version = Version.detect(url, **specs)
|
version = Version.detect(url, **specs)
|
||||||
end
|
end
|
||||||
|
check_throttle(formula, version)
|
||||||
|
check_closed_pull_requests(formula, tap_full_name, args: args, version: version)
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_throttle(formula, new_version)
|
||||||
|
throttled_rate = formula.tap.audit_exceptions.dig(:throttled_formulae, formula.name)
|
||||||
|
return if throttled_rate.blank?
|
||||||
|
|
||||||
|
formula_suffix = Version.new(new_version).patch.to_i
|
||||||
|
return if formula_suffix.modulo(throttled_rate).zero?
|
||||||
|
|
||||||
|
odie "#{formula} should only be updated every #{throttled_rate} releases on multiples of #{throttled_rate}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_closed_pull_requests(formula, tap_full_name, args:, version:)
|
||||||
# if we haven't already found open requests, try for an exact match across closed requests
|
# if we haven't already found open requests, try for an exact match across closed requests
|
||||||
GitHub.check_for_duplicate_pull_requests("#{formula.name} #{version}", tap_full_name,
|
GitHub.check_for_duplicate_pull_requests(formula.name, tap_full_name,
|
||||||
|
version: version,
|
||||||
state: "closed",
|
state: "closed",
|
||||||
file: formula.path.relative_path_from(formula.tap.path).to_s,
|
file: formula.path.relative_path_from(formula.tap.path).to_s,
|
||||||
args: args)
|
args: args)
|
||||||
|
|||||||
@ -626,19 +626,24 @@ module GitHub
|
|||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_pull_requests(query, tap_full_name, state: nil)
|
def fetch_pull_requests(name, tap_full_name, state: nil, version: nil)
|
||||||
|
if version.present?
|
||||||
|
query = "#{name} #{version}"
|
||||||
|
regex = /(^|\s)#{Regexp.quote(name)}(:|,|\s)(.*\s)?#{Regexp.quote(version)}(:|,|\s|$)/i
|
||||||
|
else
|
||||||
|
query = name
|
||||||
|
regex = /(^|\s)#{Regexp.quote(name)}(:|,|\s|$)/i
|
||||||
|
end
|
||||||
issues_for_formula(query, tap_full_name: tap_full_name, state: state).select do |pr|
|
issues_for_formula(query, tap_full_name: tap_full_name, state: state).select do |pr|
|
||||||
pr["html_url"].include?("/pull/") &&
|
pr["html_url"].include?("/pull/") && regex.match?(pr["title"])
|
||||||
/(^|\s)#{Regexp.quote(query)}(:|\s|$)/i =~ pr["title"]
|
|
||||||
end
|
end
|
||||||
rescue RateLimitExceededError => e
|
rescue RateLimitExceededError => e
|
||||||
opoo e.message
|
opoo e.message
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_for_duplicate_pull_requests(query, tap_full_name, state:, file:, args:)
|
def check_for_duplicate_pull_requests(name, tap_full_name, state:, file:, args:, version: nil)
|
||||||
pull_requests = fetch_pull_requests(query, tap_full_name, state: state)
|
pull_requests = fetch_pull_requests(name, tap_full_name, state: state, version: version).select do |pr|
|
||||||
pull_requests.select! do |pr|
|
|
||||||
pr_files = open_api(url_to("repos", tap_full_name, "pulls", pr["number"], "files"))
|
pr_files = open_api(url_to("repos", tap_full_name, "pulls", pr["number"], "files"))
|
||||||
pr_files.any? { |f| f["filename"] == file }
|
pr_files.any? { |f| f["filename"] == file }
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user