Skip to content
Snippets Groups Projects
Commit e5cc33ae authored by Seeker's avatar Seeker
Browse files

bump-formula-pr: cleanup

parent 84e4e1b4
No related branches found
No related tags found
No related merge requests found
...@@ -28,8 +28,6 @@ module Homebrew ...@@ -28,8 +28,6 @@ module Homebrew
URL-and-SHA-256 style specification into a tag-and-revision style specification, URL-and-SHA-256 style specification into a tag-and-revision style specification,
nor vice versa. It must use whichever style specification the formula already uses. nor vice versa. It must use whichever style specification the formula already uses.
EOS EOS
switch "--devel",
description: "Bump the development rather than stable version. The development spec must already exist."
switch "-n", "--dry-run", switch "-n", "--dry-run",
description: "Print what would be done rather than doing it." description: "Print what would be done rather than doing it."
switch "--write", switch "--write",
...@@ -123,7 +121,7 @@ module Homebrew ...@@ -123,7 +121,7 @@ module Homebrew
formula = args.formulae.first formula = args.formulae.first
new_url = args.url new_url = args.url
formula ||= determine_formula_from_url(new_url, args.devel?) if new_url formula ||= determine_formula_from_url(new_url) if new_url
raise FormulaUnspecifiedError unless formula raise FormulaUnspecifiedError unless formula
tap_full_name, origin_branch, previous_branch = use_correct_linux_tap(formula) tap_full_name, origin_branch, previous_branch = use_correct_linux_tap(formula)
...@@ -132,12 +130,8 @@ module Homebrew ...@@ -132,12 +130,8 @@ module Homebrew
new_version = args.version new_version = args.version
check_all_pull_requests(formula, tap_full_name, version: new_version) if new_version check_all_pull_requests(formula, tap_full_name, version: new_version) if new_version
requested_spec, formula_spec = if args.devel? requested_spec = :stable
devel_message = " (devel)" formula_spec = formula.stable
[:devel, formula.devel]
else
[:stable, formula.stable]
end
odie "#{formula}: no #{requested_spec} specification found!" unless formula_spec odie "#{formula}: no #{requested_spec} specification found!" unless formula_spec
hash_type, old_hash = if (checksum = formula_spec.checksum) hash_type, old_hash = if (checksum = formula_spec.checksum)
...@@ -149,7 +143,7 @@ module Homebrew ...@@ -149,7 +143,7 @@ module Homebrew
new_revision = args.revision new_revision = args.revision
new_mirrors ||= args.mirror new_mirrors ||= args.mirror
new_mirror ||= case new_url new_mirror ||= case new_url
when requested_spec != :devel && %r{.*ftp.gnu.org/gnu.*} when %r{.*ftp.gnu.org/gnu.*}
new_url.sub "ftp.gnu.org/gnu", "ftpmirror.gnu.org" new_url.sub "ftp.gnu.org/gnu", "ftpmirror.gnu.org"
when %r{.*download.savannah.gnu.org/*} when %r{.*download.savannah.gnu.org/*}
new_url.sub "download.savannah.gnu.org", "download-mirror.savannah.gnu.org" new_url.sub "download.savannah.gnu.org", "download-mirror.savannah.gnu.org"
...@@ -175,7 +169,7 @@ module Homebrew ...@@ -175,7 +169,7 @@ module Homebrew
new_tag ||= old_tag.gsub(old_version, new_version) new_tag ||= old_tag.gsub(old_version, new_version)
if new_tag == old_tag if new_tag == old_tag
odie <<~EOS odie <<~EOS
You probably need to bump this formula manually since the new tag You need to bump this formula manually since the new tag
and old tag are both #{new_tag}. and old tag are both #{new_tag}.
EOS EOS
end end
...@@ -190,7 +184,7 @@ module Homebrew ...@@ -190,7 +184,7 @@ module Homebrew
new_url ||= old_url.gsub(old_version, new_version) new_url ||= old_url.gsub(old_version, new_version)
if new_url == old_url if new_url == old_url
odie <<~EOS odie <<~EOS
You probably need to bump this formula manually since the new URL You need to bump this formula manually since the new URL
and old URL are both: and old URL are both:
#{new_url} #{new_url}
EOS EOS
...@@ -272,43 +266,27 @@ module Homebrew ...@@ -272,43 +266,27 @@ module Homebrew
end end
if forced_version && new_version != "0" if forced_version && new_version != "0"
case requested_spec replacement_pairs << if File.read(formula.path).include?("version \"#{old_formula_version}\"")
when :stable [
replacement_pairs << if File.read(formula.path).include?("version \"#{old_formula_version}\"") old_formula_version.to_s,
[ new_version,
old_formula_version.to_s,
new_version,
]
elsif new_mirrors
[
/^( +)(mirror "#{Regexp.escape(new_mirrors.last)}"\n)/m,
"\\1\\2\\1version \"#{new_version}\"\n",
]
else
[
/^( +)(url "#{Regexp.escape(new_url)}"\n)/m,
"\\1\\2\\1version \"#{new_version}\"\n",
]
end
when :devel
replacement_pairs << [
/( devel do.+?version ")#{old_formula_version}("\n.+?end\n)/m,
"\\1#{new_version}\\2",
] ]
end elsif new_mirrors
elsif forced_version && new_version == "0" [
case requested_spec /^( +)(mirror "#{Regexp.escape(new_mirrors.last)}"\n)/m,
when :stable "\\1\\2\\1version \"#{new_version}\"\n",
replacement_pairs << [
/^ version "[\w.\-+]+"\n/m,
"",
] ]
when :devel else
replacement_pairs << [ [
/( devel do.+?)^ +version "[^\n]+"\n(.+?end\n)/m, /^( +)(url "#{Regexp.escape(new_url)}"\n)/m,
"\\1\\2", "\\1\\2\\1version \"#{new_version}\"\n",
] ]
end end
elsif forced_version && new_version == "0"
replacement_pairs << [
/^ version "[\w.\-+]+"\n/m,
"",
]
end end
new_contents = inreplace_pairs(formula.path, replacement_pairs.uniq) new_contents = inreplace_pairs(formula.path, replacement_pairs.uniq)
...@@ -328,13 +306,13 @@ module Homebrew ...@@ -328,13 +306,13 @@ module Homebrew
if new_formula_version < old_formula_version if new_formula_version < old_formula_version
formula.path.atomic_write(old_contents) unless args.dry_run? formula.path.atomic_write(old_contents) unless args.dry_run?
odie <<~EOS odie <<~EOS
You probably need to bump this formula manually since changing the You need to bump this formula manually since changing the
version from #{old_formula_version} to #{new_formula_version} would be a downgrade. version from #{old_formula_version} to #{new_formula_version} would be a downgrade.
EOS EOS
elsif new_formula_version == old_formula_version elsif new_formula_version == old_formula_version
formula.path.atomic_write(old_contents) unless args.dry_run? formula.path.atomic_write(old_contents) unless args.dry_run?
odie <<~EOS odie <<~EOS
You probably need to bump this formula manually since the new version You need to bump this formula manually since the new version
and old version are both #{new_formula_version}. and old version are both #{new_formula_version}.
EOS EOS
end end
...@@ -360,7 +338,7 @@ module Homebrew ...@@ -360,7 +338,7 @@ module Homebrew
ohai "git add #{alias_rename.first} #{alias_rename.last}" if alias_rename.present? ohai "git add #{alias_rename.first} #{alias_rename.last}" if alias_rename.present?
ohai "git checkout --no-track -b #{branch} #{origin_branch}" ohai "git checkout --no-track -b #{branch} #{origin_branch}"
ohai "git commit --no-edit --verbose --message='#{formula.name} " \ ohai "git commit --no-edit --verbose --message='#{formula.name} " \
"#{new_formula_version}#{devel_message}' -- #{changed_files.join(" ")}" "#{new_formula_version}' -- #{changed_files.join(" ")}"
ohai "git push --set-upstream $HUB_REMOTE #{branch}:#{branch}" ohai "git push --set-upstream $HUB_REMOTE #{branch}:#{branch}"
ohai "git checkout --quiet #{previous_branch}" ohai "git checkout --quiet #{previous_branch}"
ohai "create pull request with GitHub API" ohai "create pull request with GitHub API"
...@@ -377,7 +355,7 @@ module Homebrew ...@@ -377,7 +355,7 @@ module Homebrew
safe_system "git", "add", *alias_rename if alias_rename.present? safe_system "git", "add", *alias_rename if alias_rename.present?
safe_system "git", "checkout", "--no-track", "-b", branch, origin_branch safe_system "git", "checkout", "--no-track", "-b", branch, origin_branch
safe_system "git", "commit", "--no-edit", "--verbose", safe_system "git", "commit", "--no-edit", "--verbose",
"--message=#{formula.name} #{new_formula_version}#{devel_message}", "--message=#{formula.name} #{new_formula_version}",
"--", *changed_files "--", *changed_files
safe_system "git", "push", "--set-upstream", remote_url, "#{branch}:#{branch}" safe_system "git", "push", "--set-upstream", remote_url, "#{branch}:#{branch}"
safe_system "git", "checkout", "--quiet", previous_branch safe_system "git", "checkout", "--quiet", previous_branch
...@@ -392,7 +370,7 @@ module Homebrew ...@@ -392,7 +370,7 @@ module Homebrew
#{user_message} #{user_message}
EOS EOS
end end
pr_title = "#{formula.name} #{new_formula_version}#{devel_message}" pr_title = "#{formula.name} #{new_formula_version}"
begin begin
url = GitHub.create_pull_request(tap_full_name, pr_title, url = GitHub.create_pull_request(tap_full_name, pr_title,
...@@ -409,7 +387,7 @@ module Homebrew ...@@ -409,7 +387,7 @@ module Homebrew
end end
end end
def determine_formula_from_url(url, is_devel) def determine_formula_from_url(url)
# Split the new URL on / and find any formulae that have the same URL # Split the new URL on / and find any formulae that have the same URL
# except for the last component, but don't try to match any more than the # except for the last component, but don't try to match any more than the
# first five components since sometimes the last component isn't the only # first five components since sometimes the last component isn't the only
...@@ -421,14 +399,10 @@ module Homebrew ...@@ -421,14 +399,10 @@ module Homebrew
base_url = /#{Regexp.escape(base_url)}/ base_url = /#{Regexp.escape(base_url)}/
guesses = [] guesses = []
Formula.each do |f| Formula.each do |f|
if is_devel && f.devel && f.devel.url && f.devel.url.match(base_url) guesses << f if f.stable&.url && f.stable.url.match(base_url)
guesses << f
elsif f.stable&.url && f.stable.url.match(base_url)
guesses << f
end
end end
return guesses.shift if guesses.count == 1 return guesses.shift if guesses.count == 1
return unless guesses.count > 1 return if guesses.count <= 1
odie "Couldn't guess formula for sure; could be one of these:\n#{guesses.map(&:name).join(", ")}" odie "Couldn't guess formula for sure; could be one of these:\n#{guesses.map(&:name).join(", ")}"
end end
...@@ -518,7 +492,11 @@ module Homebrew ...@@ -518,7 +492,11 @@ module Homebrew
end end
def check_all_pull_requests(formula, tap_full_name, version: nil, url: nil, tag: nil) def check_all_pull_requests(formula, tap_full_name, version: nil, url: nil, tag: nil)
version ||= Version.detect(url, tag ? { tag: tag } : {}) unless version
specs = {}
specs[:tag] = tag if tag
version = Version.detect(url, specs)
end
# if we haven't already found open requests, try for an exact match across all requests # if we haven't already found open requests, try for an exact match across all requests
pull_requests = fetch_pull_requests("#{formula.name} #{version}", tap_full_name) if pull_requests.blank? pull_requests = fetch_pull_requests("#{formula.name} #{version}", tap_full_name) if pull_requests.blank?
check_for_duplicate_pull_requests(pull_requests) check_for_duplicate_pull_requests(pull_requests)
......
...@@ -719,8 +719,6 @@ URL-and-SHA-256 style specification into a tag-and-revision style specification, ...@@ -719,8 +719,6 @@ URL-and-SHA-256 style specification into a tag-and-revision style specification,
nor vice versa. It must use whichever style specification the formula already nor vice versa. It must use whichever style specification the formula already
uses. uses.
* `--devel`:
Bump the development rather than stable version. The development spec must already exist.
* `-n`, `--dry-run`: * `-n`, `--dry-run`:
Print what would be done rather than doing it. Print what would be done rather than doing it.
* `--write`: * `--write`:
......
...@@ -926,10 +926,6 @@ If a \fIversion\fR is specified, a best effort to determine the \fIURL\fR and \f ...@@ -926,10 +926,6 @@ If a \fIversion\fR is specified, a best effort to determine the \fIURL\fR and \f
\fINote:\fR this command cannot be used to transition a formula from a URL\-and\-SHA\-256 style specification into a tag\-and\-revision style specification, nor vice versa\. It must use whichever style specification the formula already uses\. \fINote:\fR this command cannot be used to transition a formula from a URL\-and\-SHA\-256 style specification into a tag\-and\-revision style specification, nor vice versa\. It must use whichever style specification the formula already uses\.
. .
.TP .TP
\fB\-\-devel\fR
Bump the development rather than stable version\. The development spec must already exist\.
.
.TP
\fB\-n\fR, \fB\-\-dry\-run\fR \fB\-n\fR, \fB\-\-dry\-run\fR
Print what would be done rather than doing it\. Print what would be done rather than doing it\.
. .
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment