| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  | require "formula" | 
					
						
							| 
									
										
										
										
											2019-04-17 18:25:08 +09:00
										 |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-30 18:25:38 +05:30
										 |  |  |   def bump_formula_pr_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  |       usage_banner <<~EOS | 
					
						
							| 
									
										
										
										
											2018-10-15 15:06:33 -04:00
										 |  |  |         `bump-formula-pr` [<options>] [<formula>] | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-06 14:20:27 -04:00
										 |  |  |         Create a pull request to update <formula> with a new URL or a new tag. | 
					
						
							| 
									
										
										
										
											2018-10-02 19:54:22 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-08 22:49:03 -04:00
										 |  |  |         If a <URL> is specified, the <SHA-256> checksum of the new download should also | 
					
						
							|  |  |  |         be specified. A best effort to determine the <SHA-256> and <formula> name will | 
					
						
							|  |  |  |         be made if either or both values are not supplied by the user. | 
					
						
							| 
									
										
										
										
											2018-10-02 19:54:22 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-08 22:49:03 -04:00
										 |  |  |         If a <tag> is specified, the Git commit <revision> corresponding to that tag | 
					
						
							|  |  |  |         must also be specified. | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-08 22:49:03 -04:00
										 |  |  |         *Note:* this command cannot be used to transition a formula from a | 
					
						
							|  |  |  |         URL-and-SHA-256 style specification into a tag-and-revision style specification, | 
					
						
							| 
									
										
										
										
											2019-08-20 00:04:14 -04:00
										 |  |  |         nor vice versa. It must use whichever style specification the formula already uses. | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2018-10-02 19:54:22 +05:30
										 |  |  |       switch "--devel", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              description: "Bump the development rather than stable version. The development spec must already exist." | 
					
						
							| 
									
										
										
										
											2018-10-02 19:54:22 +05:30
										 |  |  |       switch "-n", "--dry-run", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              description: "Print what would be done rather than doing it." | 
					
						
							| 
									
										
										
										
											2018-10-02 19:54:22 +05:30
										 |  |  |       switch "--write", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              depends_on:  "--dry-run", | 
					
						
							|  |  |  |              description: "When passed along with `--dry-run`, perform a not-so-dry run by making the expected "\ | 
					
						
							|  |  |  |                           "file modifications but not taking any Git actions." | 
					
						
							| 
									
										
										
										
											2018-10-28 01:13:50 +10:00
										 |  |  |       switch "--no-audit", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              description: "Don't run `brew audit` before opening the PR." | 
					
						
							| 
									
										
										
										
											2018-10-02 19:54:22 +05:30
										 |  |  |       switch "--strict", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              description: "Run `brew audit --strict` before opening the PR." | 
					
						
							| 
									
										
										
										
											2018-10-02 19:54:22 +05:30
										 |  |  |       switch "--no-browse", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              description: "Print the pull request URL instead of opening in a browser." | 
					
						
							| 
									
										
										
										
											2019-11-11 19:12:55 +00:00
										 |  |  |       switch "--no-fork", | 
					
						
							|  |  |  |              description: "Don't try to fork the repository." | 
					
						
							| 
									
										
										
										
											2020-03-23 10:59:27 +01:00
										 |  |  |       comma_array "--mirror", | 
					
						
							| 
									
										
										
										
											2020-02-19 16:27:34 -05:00
										 |  |  |                   description: "Use the specified <URL> as a mirror URL. If <URL> is a comma-separated list "\ | 
					
						
							|  |  |  |                                "of URLs, multiple mirrors will be added." | 
					
						
							| 
									
										
										
										
											2018-10-08 22:49:03 -04:00
										 |  |  |       flag   "--version=", | 
					
						
							| 
									
										
										
										
											2019-08-20 00:04:14 -04:00
										 |  |  |              description: "Use the specified <version> to override the value parsed from the URL or tag. Note "\ | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |                           "that `--version=0` can be used to delete an existing version override from a "\ | 
					
						
							|  |  |  |                           "formula if it has become redundant." | 
					
						
							| 
									
										
										
										
											2018-10-08 22:49:03 -04:00
										 |  |  |       flag   "--message=", | 
					
						
							| 
									
										
										
										
											2019-08-20 00:04:14 -04:00
										 |  |  |              description: "Append <message> to the default pull request message." | 
					
						
							| 
									
										
										
										
											2018-10-08 22:49:03 -04:00
										 |  |  |       flag   "--url=", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              description: "Specify the <URL> for the new download. If a <URL> is specified, the <SHA-256> "\ | 
					
						
							|  |  |  |                           "checksum of the new download should also be specified." | 
					
						
							| 
									
										
										
										
											2018-10-08 22:49:03 -04:00
										 |  |  |       flag   "--sha256=", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              depends_on:  "--url=", | 
					
						
							|  |  |  |              description: "Specify the <SHA-256> checksum of the new download." | 
					
						
							| 
									
										
										
										
											2018-10-08 22:49:03 -04:00
										 |  |  |       flag   "--tag=", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              description: "Specify the new git commit <tag> for the formula." | 
					
						
							| 
									
										
										
										
											2018-10-08 22:49:03 -04:00
										 |  |  |       flag   "--revision=", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              required_for: "--tag=", | 
					
						
							| 
									
										
										
										
											2019-08-20 00:04:14 -04:00
										 |  |  |              description:  "Specify the new git commit <revision> corresponding to the specified <tag>." | 
					
						
							| 
									
										
										
										
											2018-10-02 19:54:22 +05:30
										 |  |  |       switch :force | 
					
						
							| 
									
										
										
										
											2018-10-08 22:49:03 -04:00
										 |  |  |       switch :quiet | 
					
						
							| 
									
										
										
										
											2018-10-02 19:54:22 +05:30
										 |  |  |       switch :verbose | 
					
						
							|  |  |  |       switch :debug | 
					
						
							| 
									
										
										
										
											2019-01-29 19:39:41 +00:00
										 |  |  |       conflicts "--no-audit", "--strict" | 
					
						
							| 
									
										
										
										
											2018-04-14 16:17:14 +05:30
										 |  |  |       conflicts "--url", "--tag" | 
					
						
							| 
									
										
										
										
											2019-12-13 16:50:54 -05:00
										 |  |  |       max_named 1
 | 
					
						
							| 
									
										
										
										
											2017-02-12 09:22:26 -08:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-07-30 18:25:38 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 21:20:49 +01:00
										 |  |  |   def use_correct_linux_tap(formula) | 
					
						
							|  |  |  |     if OS.linux? && formula.tap.core_tap? | 
					
						
							|  |  |  |       tap_full_name = formula.tap.full_name.gsub("linuxbrew", "homebrew") | 
					
						
							|  |  |  |       homebrew_core_url = "https://github.com/#{tap_full_name}" | 
					
						
							|  |  |  |       homebrew_core_remote = "homebrew" | 
					
						
							|  |  |  |       homebrew_core_branch = "master" | 
					
						
							|  |  |  |       origin_branch = "#{homebrew_core_remote}/#{homebrew_core_branch}" | 
					
						
							|  |  |  |       previous_branch = Utils.popen_read("git -C \"#{formula.tap.path}\" symbolic-ref -q --short HEAD").chomp | 
					
						
							|  |  |  |       previous_branch = "master" if previous_branch.empty? | 
					
						
							|  |  |  |       formula_path = formula.path.to_s[%r{(Formula\/.*)}, 1] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if args.dry_run? | 
					
						
							|  |  |  |         ohai "git remote add #{homebrew_core_remote} #{homebrew_core_url}" | 
					
						
							|  |  |  |         ohai "git fetch #{homebrew_core_remote} #{homebrew_core_branch}" | 
					
						
							|  |  |  |         ohai "git cat-file -e #{origin_branch}:#{formula_path}" | 
					
						
							|  |  |  |         ohai "git checkout #{origin_branch}" | 
					
						
							|  |  |  |         return tap_full_name, origin_branch, previous_branch | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         formula.path.parent.cd do | 
					
						
							|  |  |  |           unless Utils.popen_read("git remote -v").match?(%r{^homebrew.*Homebrew\/homebrew-core.*$}) | 
					
						
							|  |  |  |             ohai "Adding #{homebrew_core_remote} remote" | 
					
						
							|  |  |  |             safe_system "git", "remote", "add", homebrew_core_remote, homebrew_core_url | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |           ohai "Fetching #{origin_branch}" | 
					
						
							|  |  |  |           safe_system "git", "fetch", homebrew_core_remote, homebrew_core_branch | 
					
						
							|  |  |  |           if quiet_system "git", "cat-file", "-e", "#{origin_branch}:#{formula_path}" | 
					
						
							|  |  |  |             ohai "#{formula.full_name} exists in #{origin_branch}" | 
					
						
							|  |  |  |             safe_system "git", "checkout", origin_branch | 
					
						
							|  |  |  |             return tap_full_name, origin_branch, previous_branch | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2019-12-07 11:27:27 +00:00
										 |  |  |     [formula.tap&.full_name, "origin/master", "-"] | 
					
						
							| 
									
										
										
										
											2019-11-06 21:20:49 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-30 18:25:38 +05:30
										 |  |  |   def bump_formula_pr | 
					
						
							|  |  |  |     bump_formula_pr_args.parse | 
					
						
							| 
									
										
										
										
											2017-02-12 09:22:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-18 12:13:43 -04:00
										 |  |  |     # As this command is simplifying user-run commands then let's just use a | 
					
						
							| 
									
										
										
										
											2017-10-28 21:46:11 +01:00
										 |  |  |     # user path, too. | 
					
						
							|  |  |  |     ENV["PATH"] = ENV["HOMEBREW_PATH"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 07:48:00 +00:00
										 |  |  |     # Use the user's browser, too. | 
					
						
							| 
									
										
										
										
											2020-04-05 15:44:50 +01:00
										 |  |  |     ENV["BROWSER"] = Homebrew::EnvConfig.browser | 
					
						
							| 
									
										
										
										
											2017-11-07 07:48:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 17:28:24 +00:00
										 |  |  |     formula = args.formulae.first | 
					
						
							| 
									
										
										
										
											2017-02-12 09:22:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |     new_url = args.url | 
					
						
							| 
									
										
										
										
											2016-09-04 11:20:03 -07:00
										 |  |  |     if new_url && !formula | 
					
						
							| 
									
										
										
										
											2018-01-24 06:37:27 -08:00
										 |  |  |       # 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 | 
					
						
							|  |  |  |       # first five components since sometimes the last component isn't the only | 
					
						
							|  |  |  |       # one to change. | 
					
						
							|  |  |  |       new_url_split = new_url.split("/") | 
					
						
							|  |  |  |       maximum_url_components_to_match = 5
 | 
					
						
							|  |  |  |       components_to_match = [new_url_split.count - 1, maximum_url_components_to_match].min | 
					
						
							|  |  |  |       base_url = new_url_split.first(components_to_match).join("/") | 
					
						
							| 
									
										
										
										
											2016-09-04 11:20:03 -07:00
										 |  |  |       base_url = /#{Regexp.escape(base_url)}/ | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |       is_devel = args.devel? | 
					
						
							| 
									
										
										
										
											2016-09-04 11:20:03 -07:00
										 |  |  |       guesses = [] | 
					
						
							|  |  |  |       Formula.each do |f| | 
					
						
							|  |  |  |         if is_devel && f.devel && f.devel.url && f.devel.url.match(base_url) | 
					
						
							|  |  |  |           guesses << f | 
					
						
							| 
									
										
										
										
											2017-09-24 19:24:46 +01:00
										 |  |  |         elsif f.stable&.url && f.stable.url.match(base_url) | 
					
						
							| 
									
										
										
										
											2016-09-04 11:20:03 -07:00
										 |  |  |           guesses << f | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       if guesses.count == 1
 | 
					
						
							|  |  |  |         formula = guesses.shift | 
					
						
							|  |  |  |       elsif guesses.count > 1
 | 
					
						
							| 
									
										
										
										
											2020-02-19 14:55:13 -05:00
										 |  |  |         odie "Couldn't guess formula for sure; could be one of these:\n#{guesses.map(&:name).join(", ")}" | 
					
						
							| 
									
										
										
										
											2016-09-04 11:20:03 -07:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2019-03-20 11:33:11 +00:00
										 |  |  |     raise FormulaUnspecifiedError unless formula | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-23 14:15:29 +08:00
										 |  |  |     tap_full_name, origin_branch, previous_branch = use_correct_linux_tap(formula) | 
					
						
							|  |  |  |     check_for_duplicate_pull_requests(formula, tap_full_name) | 
					
						
							| 
									
										
										
										
											2017-02-12 09:22:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |     requested_spec, formula_spec = if args.devel? | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |       devel_message = " (devel)" | 
					
						
							|  |  |  |       [:devel, formula.devel] | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       [:stable, formula.stable] | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-03-28 00:29:48 +02:00
										 |  |  |     odie "#{formula}: no #{requested_spec} specification found!" unless formula_spec | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     hash_type, old_hash = if (checksum = formula_spec.checksum) | 
					
						
							| 
									
										
										
										
											2018-03-25 23:49:54 +05:30
										 |  |  |       [checksum.hash_type, checksum.hexdigest] | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |     new_hash = args[hash_type] if hash_type | 
					
						
							|  |  |  |     new_tag = args.tag | 
					
						
							|  |  |  |     new_revision = args.revision | 
					
						
							| 
									
										
										
										
											2020-02-19 16:27:34 -05:00
										 |  |  |     new_mirrors ||= args.mirror | 
					
						
							| 
									
										
										
										
											2020-02-18 18:09:53 -05:00
										 |  |  |     new_mirror ||= case new_url | 
					
						
							|  |  |  |     when requested_spec != :devel && %r{.*ftp.gnu.org/gnu.*} | 
					
						
							|  |  |  |       new_url.sub "ftp.gnu.org/gnu", "ftpmirror.gnu.org" | 
					
						
							| 
									
										
										
										
											2020-02-18 18:41:02 -05:00
										 |  |  |     when %r{.*download.savannah.gnu.org/*} | 
					
						
							|  |  |  |       new_url.sub "download.savannah.gnu.org", "download-mirror.savannah.gnu.org" | 
					
						
							|  |  |  |     when %r{.*www.apache.org/dyn/closer.lua\?path=.*} | 
					
						
							|  |  |  |       new_url.sub "www.apache.org/dyn/closer.lua?path=", "archive.apache.org/dist/" | 
					
						
							| 
									
										
										
										
											2020-02-18 18:09:53 -05:00
										 |  |  |     when %r{.*mirrors.ocf.berkeley.edu/debian.*} | 
					
						
							|  |  |  |       new_url.sub "mirrors.ocf.berkeley.edu/debian", "mirrorservice.org/sites/ftp.debian.org/debian" | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-02-19 16:27:34 -05:00
										 |  |  |     new_mirrors ||= [new_mirror] unless new_mirror.nil? | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |     forced_version = args.version | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |     new_url_hash = if new_url && new_hash | 
					
						
							|  |  |  |       true | 
					
						
							|  |  |  |     elsif new_tag && new_revision | 
					
						
							|  |  |  |       false | 
					
						
							|  |  |  |     elsif !hash_type | 
					
						
							| 
									
										
										
										
											2017-12-11 09:02:41 +00:00
										 |  |  |       odie "#{formula}: no --tag=/--revision= arguments specified!" | 
					
						
							| 
									
										
										
										
											2017-01-09 12:16:55 +00:00
										 |  |  |     elsif !new_url | 
					
						
							| 
									
										
										
										
											2017-12-11 09:02:41 +00:00
										 |  |  |       odie "#{formula}: no --url= argument specified!" | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2018-01-24 06:49:31 -08:00
										 |  |  |       resource = Resource.new { @url = new_url } | 
					
						
							| 
									
										
										
										
											2018-01-24 06:55:55 -08:00
										 |  |  |       resource.download_strategy = DownloadStrategyDetector.detect_from_url(new_url) | 
					
						
							| 
									
										
										
										
											2018-01-24 03:51:23 -08:00
										 |  |  |       resource.owner = Resource.new(formula.name) | 
					
						
							| 
									
										
										
										
											2020-03-13 17:09:58 +01:00
										 |  |  |       if forced_version | 
					
						
							|  |  |  |         if forced_version == resource.version | 
					
						
							|  |  |  |           forced_version = nil | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           resource.version = forced_version | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2018-01-24 03:51:23 -08:00
										 |  |  |       odie "No --version= argument specified!" unless resource.version | 
					
						
							|  |  |  |       resource_path = resource.fetch | 
					
						
							| 
									
										
										
										
											2018-01-24 04:22:11 -08:00
										 |  |  |       tar_file_extensions = %w[.tar .tb2 .tbz .tbz2 .tgz .tlz .txz .tZ] | 
					
						
							|  |  |  |       if tar_file_extensions.any? { |extension| new_url.include? extension } | 
					
						
							|  |  |  |         gnu_tar_gtar_path = HOMEBREW_PREFIX/"opt/gnu-tar/bin/gtar" | 
					
						
							|  |  |  |         gnu_tar_gtar = gnu_tar_gtar_path if gnu_tar_gtar_path.executable? | 
					
						
							|  |  |  |         tar = which("gtar") || gnu_tar_gtar || which("tar") | 
					
						
							| 
									
										
										
										
											2019-10-13 19:26:39 +01:00
										 |  |  |         if Utils.popen_read(tar, "-tf", resource_path).match?(%r{/.*\.}) | 
					
						
							| 
									
										
										
										
											2018-01-24 04:22:11 -08:00
										 |  |  |           new_hash = resource_path.sha256 | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           odie "#{resource_path} is not a valid tar file!" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       else | 
					
						
							| 
									
										
										
										
											2018-01-24 03:51:23 -08:00
										 |  |  |         new_hash = resource_path.sha256 | 
					
						
							| 
									
										
										
										
											2016-09-04 11:28:38 -07:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |     old_formula_version = formula_version(formula, requested_spec) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-17 08:17:56 -07:00
										 |  |  |     replacement_pairs = [] | 
					
						
							| 
									
										
										
										
											2016-09-11 17:41:51 +01:00
										 |  |  |     if requested_spec == :stable && formula.revision.nonzero? | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |       replacement_pairs << [ | 
					
						
							|  |  |  |         /^  revision \d+\n(\n(  head "))?/m, | 
					
						
							|  |  |  |         "\\2", | 
					
						
							|  |  |  |       ] | 
					
						
							| 
									
										
										
										
											2016-06-17 08:17:56 -07:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-22 00:54:08 -05:00
										 |  |  |     replacement_pairs += formula_spec.mirrors.map do |mirror| | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |       [ | 
					
						
							|  |  |  |         / +mirror \"#{Regexp.escape(mirror)}\"\n/m, | 
					
						
							|  |  |  |         "", | 
					
						
							|  |  |  |       ] | 
					
						
							| 
									
										
										
										
											2016-12-22 00:54:08 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-09-04 11:28:02 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-17 08:17:56 -07:00
										 |  |  |     replacement_pairs += if new_url_hash | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |       [ | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |         [ | 
					
						
							|  |  |  |           /#{Regexp.escape(formula_spec.url)}/, | 
					
						
							|  |  |  |           new_url, | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |           old_hash, | 
					
						
							|  |  |  |           new_hash, | 
					
						
							|  |  |  |         ], | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |       ] | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       [ | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |         [ | 
					
						
							|  |  |  |           formula_spec.specs[:tag], | 
					
						
							|  |  |  |           new_tag, | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |           formula_spec.specs[:revision], | 
					
						
							|  |  |  |           new_revision, | 
					
						
							|  |  |  |         ], | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |       ] | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |     backup_file = File.read(formula.path) unless args.dry_run? | 
					
						
							| 
									
										
										
										
											2016-06-17 10:10:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-19 16:27:34 -05:00
										 |  |  |     if new_mirrors | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |       replacement_pairs << [ | 
					
						
							|  |  |  |         /^( +)(url \"#{Regexp.escape(new_url)}\"\n)/m, | 
					
						
							| 
									
										
										
										
											2020-02-19 16:27:34 -05:00
										 |  |  |         "\\1\\2\\1mirror \"#{new_mirrors.join("\"\n\\1mirror \"")}\"\n", | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |       ] | 
					
						
							| 
									
										
										
										
											2016-09-04 11:28:02 -07:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-14 22:38:05 +00:00
										 |  |  |     # When bumping a linux-only formula, one needs to also delete the | 
					
						
							|  |  |  |     # sha256 linux bottle line if it exists. That's because of running | 
					
						
							|  |  |  |     # test-bot with --keep-old option in linuxbrew-core. | 
					
						
							|  |  |  |     formula_contents = formula.path.read | 
					
						
							|  |  |  |     if formula_contents.include?("depends_on :linux") && formula_contents.include?("=> :x86_64_linux") | 
					
						
							| 
									
										
										
										
											2020-01-18 00:08:22 +01:00
										 |  |  |       replacement_pairs << [ | 
					
						
							|  |  |  |         /^    sha256 ".+" => :x86_64_linux\n/m, | 
					
						
							|  |  |  |         "\\2", | 
					
						
							|  |  |  |       ] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-06 05:00:45 -07:00
										 |  |  |     if forced_version && forced_version != "0" | 
					
						
							| 
									
										
										
										
											2016-09-27 02:50:46 -07:00
										 |  |  |       if requested_spec == :stable | 
					
						
							| 
									
										
										
										
											2020-03-13 21:15:06 +00:00
										 |  |  |         replacement_pairs << if File.read(formula.path).include?("version \"#{old_formula_version}\"") | 
					
						
							|  |  |  |           [ | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |             old_formula_version.to_s, | 
					
						
							|  |  |  |             forced_version, | 
					
						
							|  |  |  |           ] | 
					
						
							| 
									
										
										
										
											2020-02-19 16:27:34 -05:00
										 |  |  |         elsif new_mirrors | 
					
						
							| 
									
										
										
										
											2020-03-13 21:15:06 +00:00
										 |  |  |           [ | 
					
						
							| 
									
										
										
										
											2020-02-28 13:02:55 -05:00
										 |  |  |             /^( +)(mirror \"#{Regexp.escape(new_mirrors.last)}\"\n)/m, | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |             "\\1\\2\\1version \"#{forced_version}\"\n", | 
					
						
							|  |  |  |           ] | 
					
						
							| 
									
										
										
										
											2016-09-04 11:21:08 -07:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2020-03-13 21:15:06 +00:00
										 |  |  |           [ | 
					
						
							| 
									
										
										
										
											2020-02-28 13:02:55 -05:00
										 |  |  |             /^( +)(url \"#{Regexp.escape(new_url)}\"\n)/m, | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |             "\\1\\2\\1version \"#{forced_version}\"\n", | 
					
						
							|  |  |  |           ] | 
					
						
							| 
									
										
										
										
											2016-09-04 11:21:08 -07:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-09-27 02:50:46 -07:00
										 |  |  |       elsif requested_spec == :devel | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |         replacement_pairs << [ | 
					
						
							|  |  |  |           /(  devel do.+?version \")#{old_formula_version}(\"\n.+?end\n)/m, | 
					
						
							|  |  |  |           "\\1#{forced_version}\\2", | 
					
						
							|  |  |  |         ] | 
					
						
							| 
									
										
										
										
											2016-09-04 11:21:08 -07:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-07-06 05:00:45 -07:00
										 |  |  |     elsif forced_version && forced_version == "0" | 
					
						
							| 
									
										
										
										
											2016-09-27 02:50:46 -07:00
										 |  |  |       if requested_spec == :stable | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |         replacement_pairs << [ | 
					
						
							|  |  |  |           /^  version \"[\w\.\-\+]+\"\n/m, | 
					
						
							|  |  |  |           "", | 
					
						
							|  |  |  |         ] | 
					
						
							| 
									
										
										
										
											2016-09-27 02:50:46 -07:00
										 |  |  |       elsif requested_spec == :devel | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |         replacement_pairs << [ | 
					
						
							|  |  |  |           /(  devel do.+?)^ +version \"[^\n]+\"\n(.+?end\n)/m, | 
					
						
							|  |  |  |           "\\1\\2", | 
					
						
							|  |  |  |         ] | 
					
						
							| 
									
										
										
										
											2016-09-27 02:50:46 -07:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-07-06 05:00:45 -07:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |     new_contents = inreplace_pairs(formula.path, replacement_pairs) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     new_formula_version = formula_version(formula, requested_spec, new_contents) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-19 16:27:34 -05:00
										 |  |  |     if !new_mirrors && !formula_spec.mirrors.empty? | 
					
						
							| 
									
										
										
										
											2020-03-04 17:28:24 +00:00
										 |  |  |       if args.force? | 
					
						
							| 
									
										
										
										
											2020-02-18 18:12:00 -05:00
										 |  |  |         opoo "#{formula}: Removing all mirrors because a --mirror= argument was not specified." | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         odie <<~EOS | 
					
						
							|  |  |  |           #{formula}: a --mirror= argument for updating the mirror URL was not specified. | 
					
						
							|  |  |  |           Use --force to remove all mirrors. | 
					
						
							|  |  |  |         EOS | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |     if new_formula_version < old_formula_version | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |       formula.path.atomic_write(backup_file) unless args.dry_run? | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |       odie <<~EOS | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |         You probably need to bump this formula manually since changing the | 
					
						
							|  |  |  |         version from #{old_formula_version} to #{new_formula_version} would be a downgrade. | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |     elsif new_formula_version == old_formula_version | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |       formula.path.atomic_write(backup_file) unless args.dry_run? | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |       odie <<~EOS | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |         You probably need to bump this formula manually since the new version | 
					
						
							|  |  |  |         and old version are both #{new_formula_version}. | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-14 02:02:31 +02:00
										 |  |  |     alias_rename = alias_update_pair(formula, new_formula_version) | 
					
						
							|  |  |  |     if alias_rename.present? | 
					
						
							|  |  |  |       ohai "renaming alias #{alias_rename.first} to #{alias_rename.last}" | 
					
						
							|  |  |  |       alias_rename.map! { |a| formula.tap.alias_dir/a } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-16 23:05:36 +02:00
										 |  |  |     run_audit(formula, alias_rename, backup_file) | 
					
						
							| 
									
										
										
										
											2016-06-17 10:10:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |     formula.path.parent.cd do | 
					
						
							|  |  |  |       branch = "#{formula.name}-#{new_formula_version}" | 
					
						
							| 
									
										
										
										
											2017-06-29 13:28:55 +02:00
										 |  |  |       git_dir = Utils.popen_read("git rev-parse --git-dir").chomp | 
					
						
							| 
									
										
										
										
											2017-06-27 23:45:57 +02:00
										 |  |  |       shallow = !git_dir.empty? && File.exist?("#{git_dir}/shallow") | 
					
						
							| 
									
										
										
										
											2019-07-14 02:02:31 +02:00
										 |  |  |       changed_files = [formula.path] | 
					
						
							|  |  |  |       changed_files += alias_rename if alias_rename.present? | 
					
						
							| 
									
										
										
										
											2017-06-27 23:45:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |       if args.dry_run? | 
					
						
							| 
									
										
										
										
											2019-11-11 19:12:55 +00:00
										 |  |  |         ohai "try to fork repository with GitHub API" unless args.no_fork? | 
					
						
							| 
									
										
										
										
											2017-06-27 23:45:57 +02:00
										 |  |  |         ohai "git fetch --unshallow origin" if shallow | 
					
						
							| 
									
										
										
										
											2019-07-14 02:02:31 +02:00
										 |  |  |         ohai "git add #{alias_rename.first} #{alias_rename.last}" if alias_rename.present? | 
					
						
							| 
									
										
										
										
											2019-11-06 21:20:49 +01:00
										 |  |  |         ohai "git checkout --no-track -b #{branch} #{origin_branch}" | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |         ohai "git commit --no-edit --verbose --message='#{formula.name} " \ | 
					
						
							| 
									
										
										
										
											2019-07-14 02:02:31 +02:00
										 |  |  |              "#{new_formula_version}#{devel_message}' -- #{changed_files.join(" ")}" | 
					
						
							| 
									
										
										
										
											2016-08-19 10:32:54 -04:00
										 |  |  |         ohai "git push --set-upstream $HUB_REMOTE #{branch}:#{branch}" | 
					
						
							| 
									
										
										
										
											2019-11-06 21:20:49 +01:00
										 |  |  |         ohai "git checkout --quiet #{previous_branch}" | 
					
						
							| 
									
										
										
										
											2019-04-08 12:47:15 -04:00
										 |  |  |         ohai "create pull request with GitHub API" | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2017-11-21 08:16:12 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-11 19:12:55 +00:00
										 |  |  |         if args.no_fork? | 
					
						
							| 
									
										
										
										
											2018-10-11 16:05:41 +01:00
										 |  |  |           remote_url = Utils.popen_read("git remote get-url --push origin").chomp | 
					
						
							|  |  |  |           username = formula.tap.user | 
					
						
							| 
									
										
										
										
											2019-11-11 19:12:55 +00:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2019-11-26 12:14:21 -06:00
										 |  |  |           remote_url, username = forked_repo_info(formula, tap_full_name, backup_file) | 
					
						
							| 
									
										
										
										
											2018-09-07 11:08:35 -07:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-11-21 08:16:12 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-27 23:45:57 +02:00
										 |  |  |         safe_system "git", "fetch", "--unshallow", "origin" if shallow | 
					
						
							| 
									
										
										
										
											2019-07-14 02:02:31 +02:00
										 |  |  |         safe_system "git", "add", *alias_rename if alias_rename.present? | 
					
						
							| 
									
										
										
										
											2019-11-06 21:20:49 +01:00
										 |  |  |         safe_system "git", "checkout", "--no-track", "-b", branch, origin_branch | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |         safe_system "git", "commit", "--no-edit", "--verbose", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |                     "--message=#{formula.name} #{new_formula_version}#{devel_message}", | 
					
						
							| 
									
										
										
										
											2019-07-14 02:02:31 +02:00
										 |  |  |                     "--", *changed_files | 
					
						
							| 
									
										
										
										
											2018-03-04 00:12:59 +05:30
										 |  |  |         safe_system "git", "push", "--set-upstream", remote_url, "#{branch}:#{branch}" | 
					
						
							| 
									
										
										
										
											2019-11-06 21:20:49 +01:00
										 |  |  |         safe_system "git", "checkout", "--quiet", previous_branch | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |         pr_message = <<~EOS | 
					
						
							| 
									
										
										
										
											2016-11-15 11:37:49 -05:00
										 |  |  |           Created with `brew bump-formula-pr`. | 
					
						
							|  |  |  |         EOS | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |         user_message = args.message | 
					
						
							| 
									
										
										
										
											2016-11-15 11:37:49 -05:00
										 |  |  |         if user_message | 
					
						
							| 
									
										
										
										
											2017-10-31 14:16:09 -04:00
										 |  |  |           pr_message += "\n" + <<~EOS | 
					
						
							| 
									
										
										
										
											2016-11-15 11:37:49 -05:00
										 |  |  |             --- | 
					
						
							| 
									
										
										
										
											2017-10-31 14:16:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-15 11:37:49 -05:00
										 |  |  |             #{user_message} | 
					
						
							|  |  |  |           EOS | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2018-03-04 00:12:59 +05:30
										 |  |  |         pr_title = "#{formula.name} #{new_formula_version}#{devel_message}" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         begin | 
					
						
							| 
									
										
										
										
											2019-11-06 21:20:49 +01:00
										 |  |  |           url = GitHub.create_pull_request(tap_full_name, pr_title, | 
					
						
							| 
									
										
										
										
											2018-03-04 00:12:59 +05:30
										 |  |  |                                            "#{username}:#{branch}", "master", pr_message)["html_url"] | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |           if args.no_browse? | 
					
						
							| 
									
										
										
										
											2018-03-04 00:12:59 +05:30
										 |  |  |             puts url | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             exec_browser url | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2018-04-30 01:22:04 +05:30
										 |  |  |         rescue *GitHub.api_errors => e | 
					
						
							| 
									
										
										
										
											2018-03-04 00:12:59 +05:30
										 |  |  |           odie "Unable to open pull request: #{e.message}!" | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-03-25 23:49:54 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-26 12:14:21 -06:00
										 |  |  |   def forked_repo_info(formula, tap_full_name, backup_file) | 
					
						
							| 
									
										
										
										
											2019-11-26 12:10:14 -06:00
										 |  |  |     response = GitHub.create_fork(tap_full_name) | 
					
						
							|  |  |  |   rescue GitHub::AuthenticationFailedError, *GitHub.api_errors => e | 
					
						
							|  |  |  |     formula.path.atomic_write(backup_file) | 
					
						
							|  |  |  |     odie "Unable to fork: #{e.message}!" | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     # GitHub API responds immediately but fork takes a few seconds to be ready. | 
					
						
							|  |  |  |     sleep 1 until GitHub.check_fork_exists(tap_full_name) | 
					
						
							| 
									
										
										
										
											2019-11-26 12:14:21 -06:00
										 |  |  |     remote_url = if system("git", "config", "--local", "--get-regexp", "remote\..*\.url", "git@github.com:.*") | 
					
						
							| 
									
										
										
										
											2019-11-20 09:43:45 -06:00
										 |  |  |       response.fetch("ssh_url") | 
					
						
							| 
									
										
										
										
											2019-11-19 13:08:28 -06:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2020-02-29 01:19:16 +01:00
										 |  |  |       url = response.fetch("clone_url") | 
					
						
							| 
									
										
										
										
											2020-04-07 09:56:46 -04:00
										 |  |  |       if (api_token = Homebrew::EnvConfig.github_api_token) | 
					
						
							|  |  |  |         url.gsub!(%r{^https://github\.com/}, "https://#{api_token}@github.com/") | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-02-29 01:19:16 +01:00
										 |  |  |       url | 
					
						
							| 
									
										
										
										
											2019-11-19 13:08:28 -06:00
										 |  |  |     end | 
					
						
							|  |  |  |     username = response.fetch("owner").fetch("login") | 
					
						
							|  |  |  |     [remote_url, username] | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 23:49:54 +05:30
										 |  |  |   def inreplace_pairs(path, replacement_pairs) | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |     if args.dry_run? | 
					
						
							| 
									
										
										
										
											2018-03-25 23:49:54 +05:30
										 |  |  |       contents = path.open("r") { |f| Formulary.ensure_utf8_encoding(f).read } | 
					
						
							|  |  |  |       contents.extend(StringInreplaceExtension) | 
					
						
							|  |  |  |       replacement_pairs.each do |old, new| | 
					
						
							| 
									
										
										
										
											2020-03-04 17:28:24 +00:00
										 |  |  |         ohai "replace #{old.inspect} with #{new.inspect}" unless args.quiet? | 
					
						
							| 
									
										
										
										
											2019-02-19 13:11:32 +00:00
										 |  |  |         raise "No old value for new value #{new}! Did you pass the wrong arguments?" unless old | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 23:49:54 +05:30
										 |  |  |         contents.gsub!(old, new) | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2019-02-19 13:11:32 +00:00
										 |  |  |       raise Utils::InreplaceError, path => contents.errors unless contents.errors.empty? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |       path.atomic_write(contents) if args.write? | 
					
						
							| 
									
										
										
										
											2018-03-25 23:49:54 +05:30
										 |  |  |       contents | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       Utils::Inreplace.inreplace(path) do |s| | 
					
						
							|  |  |  |         replacement_pairs.each do |old, new| | 
					
						
							| 
									
										
										
										
											2020-03-04 17:28:24 +00:00
										 |  |  |           ohai "replace #{old.inspect} with #{new.inspect}" unless args.quiet? | 
					
						
							| 
									
										
										
										
											2019-02-19 13:11:32 +00:00
										 |  |  |           raise "No old value for new value #{new}! Did you pass the wrong arguments?" unless old | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 23:49:54 +05:30
										 |  |  |           s.gsub!(old, new) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       path.open("r") { |f| Formulary.ensure_utf8_encoding(f).read } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def formula_version(formula, spec, contents = nil) | 
					
						
							|  |  |  |     name = formula.name | 
					
						
							|  |  |  |     path = formula.path | 
					
						
							|  |  |  |     if contents | 
					
						
							|  |  |  |       Formulary.from_contents(name, path, contents, spec).version | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       Formulary::FormulaLoader.new(name, path).get_formula(spec).version | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 21:20:49 +01:00
										 |  |  |   def fetch_pull_requests(formula, tap_full_name) | 
					
						
							|  |  |  |     GitHub.issues_for_formula(formula.name, tap_full_name: tap_full_name).select do |pr| | 
					
						
							| 
									
										
										
										
											2018-03-25 23:49:54 +05:30
										 |  |  |       pr["html_url"].include?("/pull/") && | 
					
						
							|  |  |  |         /(^|\s)#{Regexp.quote(formula.name)}(:|\s|$)/i =~ pr["title"] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   rescue GitHub::RateLimitExceededError => e | 
					
						
							|  |  |  |     opoo e.message | 
					
						
							|  |  |  |     [] | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 21:20:49 +01:00
										 |  |  |   def check_for_duplicate_pull_requests(formula, tap_full_name) | 
					
						
							|  |  |  |     pull_requests = fetch_pull_requests(formula, tap_full_name) | 
					
						
							| 
									
										
										
										
											2018-03-25 23:49:54 +05:30
										 |  |  |     return unless pull_requests | 
					
						
							|  |  |  |     return if pull_requests.empty? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 23:49:54 +05:30
										 |  |  |     duplicates_message = <<~EOS | 
					
						
							|  |  |  |       These open pull requests may be duplicates: | 
					
						
							|  |  |  |       #{pull_requests.map { |pr| "#{pr["title"]} #{pr["html_url"]}" }.join("\n")} | 
					
						
							|  |  |  |     EOS | 
					
						
							|  |  |  |     error_message = "Duplicate PRs should not be opened. Use --force to override this error." | 
					
						
							| 
									
										
										
										
											2020-03-04 17:28:24 +00:00
										 |  |  |     if args.force? && !args.quiet? | 
					
						
							| 
									
										
										
										
											2018-03-25 23:49:54 +05:30
										 |  |  |       opoo duplicates_message | 
					
						
							| 
									
										
										
										
											2020-03-04 17:28:24 +00:00
										 |  |  |     elsif !args.force? && args.quiet? | 
					
						
							| 
									
										
										
										
											2018-03-25 23:49:54 +05:30
										 |  |  |       odie error_message | 
					
						
							| 
									
										
										
										
											2020-03-04 17:28:24 +00:00
										 |  |  |     elsif !args.force? | 
					
						
							| 
									
										
										
										
											2018-03-25 23:49:54 +05:30
										 |  |  |       odie <<~EOS | 
					
						
							|  |  |  |         #{duplicates_message.chomp} | 
					
						
							|  |  |  |         #{error_message} | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2019-07-14 02:02:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def alias_update_pair(formula, new_formula_version) | 
					
						
							|  |  |  |     versioned_alias = formula.aliases.grep(/^.*@\d+(\.\d+)?$/).first | 
					
						
							|  |  |  |     return if versioned_alias.nil? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     name, old_alias_version = versioned_alias.split("@") | 
					
						
							|  |  |  |     new_alias_regex = (old_alias_version.split(".").length == 1) ? /^\d+/ : /^\d+\.\d+/ | 
					
						
							|  |  |  |     new_alias_version, = *new_formula_version.to_s.match(new_alias_regex) | 
					
						
							|  |  |  |     return if Version.create(new_alias_version) <= Version.create(old_alias_version) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     [versioned_alias, "#{name}@#{new_alias_version}"] | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2019-07-16 23:05:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def run_audit(formula, alias_rename, backup_file) | 
					
						
							|  |  |  |     if args.dry_run? | 
					
						
							|  |  |  |       if args.no_audit? | 
					
						
							|  |  |  |         ohai "Skipping `brew audit`" | 
					
						
							|  |  |  |       elsif args.strict? | 
					
						
							|  |  |  |         ohai "brew audit --strict #{formula.path.basename}" | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         ohai "brew audit #{formula.path.basename}" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     FileUtils.mv alias_rename.first, alias_rename.last if alias_rename.present? | 
					
						
							|  |  |  |     failed_audit = false | 
					
						
							|  |  |  |     if args.no_audit? | 
					
						
							|  |  |  |       ohai "Skipping `brew audit`" | 
					
						
							|  |  |  |     elsif args.strict? | 
					
						
							|  |  |  |       system HOMEBREW_BREW_FILE, "audit", "--strict", formula.path | 
					
						
							|  |  |  |       failed_audit = !$CHILD_STATUS.success? | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       system HOMEBREW_BREW_FILE, "audit", formula.path | 
					
						
							|  |  |  |       failed_audit = !$CHILD_STATUS.success? | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2019-07-18 18:13:00 +06:00
										 |  |  |     return unless failed_audit | 
					
						
							| 
									
										
										
										
											2019-07-16 23:05:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     formula.path.atomic_write(backup_file) | 
					
						
							|  |  |  |     FileUtils.mv alias_rename.last, alias_rename.first if alias_rename.present? | 
					
						
							| 
									
										
										
										
											2019-12-13 15:39:55 -05:00
										 |  |  |     odie "`brew audit` failed!" | 
					
						
							| 
									
										
										
										
											2019-07-16 23:05:36 +02:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  | end |