| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											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" | 
					
						
							| 
									
										
										
										
											2020-07-27 10:39:09 -04:00
										 |  |  | require "utils/pypi" | 
					
						
							| 
									
										
										
										
											2020-09-04 14:13:43 -07:00
										 |  |  | require "utils/tar" | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   sig { returns(CLI::Parser) } | 
					
						
							| 
									
										
										
										
											2018-07-30 18:25:38 +05:30
										 |  |  |   def bump_formula_pr_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							| 
									
										
										
										
											2021-01-15 15:04:02 -05:00
										 |  |  |       description <<~EOS | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2020-07-15 08:16:33 -07:00
										 |  |  |         should also be specified. A best effort to determine the <revision> will be made | 
					
						
							|  |  |  |         if the value is not supplied by the user. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         If a <version> is specified, a best effort to determine the <URL> and <SHA-256> or | 
					
						
							|  |  |  |         the <tag> and <revision> will be made if both values are not supplied by the user. | 
					
						
							| 
									
										
										
										
											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 "-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", | 
					
						
							| 
									
										
										
										
											2020-09-04 07:17:21 -07:00
										 |  |  |              description: "Make the expected file modifications without taking any Git actions." | 
					
						
							|  |  |  |       switch "--commit", | 
					
						
							|  |  |  |              depends_on:  "--write", | 
					
						
							|  |  |  |              description: "When passed with `--write`, generate a new commit after writing changes "\ | 
					
						
							|  |  |  |                           "to the formula file." | 
					
						
							| 
									
										
										
										
											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." | 
					
						
							| 
									
										
										
										
											2020-09-15 18:58:38 -07:00
										 |  |  |       switch "--online", | 
					
						
							|  |  |  |              description: "Run `brew audit --online` 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=", | 
					
						
							| 
									
										
										
										
											2020-12-08 21:54:03 -05:00
										 |  |  |              description: "Specify the new commit <revision> corresponding to the specified git <tag> "\ | 
					
						
							|  |  |  |                           "or specified <version>." | 
					
						
							| 
									
										
										
										
											2020-07-27 03:59:52 +02:00
										 |  |  |       switch "-f", "--force", | 
					
						
							| 
									
										
										
										
											2020-11-12 10:40:41 -05:00
										 |  |  |              description: "Ignore duplicate open PRs. Remove all mirrors if `--mirror` was not specified." | 
					
						
							| 
									
										
										
										
											2020-07-30 18:40:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 07:17:21 -07:00
										 |  |  |       conflicts "--dry-run", "--write" | 
					
						
							| 
									
										
										
										
											2019-01-29 19:39:41 +00:00
										 |  |  |       conflicts "--no-audit", "--strict" | 
					
						
							| 
									
										
										
										
											2020-09-15 18:58:38 -07:00
										 |  |  |       conflicts "--no-audit", "--online" | 
					
						
							| 
									
										
										
										
											2018-04-14 16:17:14 +05:30
										 |  |  |       conflicts "--url", "--tag" | 
					
						
							| 
									
										
										
										
											2021-01-10 14:26:40 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |       named_args :formula, max: 1
 | 
					
						
							| 
									
										
										
										
											2017-02-12 09:22:26 -08:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-07-30 18:25:38 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-31 19:33:18 +02:00
										 |  |  |   def use_correct_linux_tap(formula, args:) | 
					
						
							| 
									
										
										
										
											2021-01-08 11:42:37 -08:00
										 |  |  |     default_origin_branch = formula.tap.path.git_origin_branch | 
					
						
							| 
									
										
										
										
											2020-11-27 18:45:13 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 12:35:45 -04:00
										 |  |  |     return formula.tap.remote_repo, "origin", default_origin_branch, "-" if !OS.linux? || !formula.tap.core_tap? | 
					
						
							| 
									
										
										
										
											2020-11-27 18:45:13 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 12:35:45 -04:00
										 |  |  |     tap_remote_repo = formula.tap.full_name.gsub("linuxbrew", "homebrew") | 
					
						
							|  |  |  |     homebrew_core_url = "https://github.com/#{tap_remote_repo}" | 
					
						
							| 
									
										
										
										
											2020-11-27 18:45:13 +11:00
										 |  |  |     homebrew_core_remote = "homebrew" | 
					
						
							|  |  |  |     previous_branch = formula.tap.path.git_branch || "master" | 
					
						
							|  |  |  |     formula_path = formula.path.relative_path_from(formula.tap.path) | 
					
						
							|  |  |  |     full_origin_branch = "#{homebrew_core_remote}/#{default_origin_branch}" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if args.dry_run? || args.write? | 
					
						
							|  |  |  |       ohai "git remote add #{homebrew_core_remote} #{homebrew_core_url}" | 
					
						
							|  |  |  |       ohai "git fetch #{homebrew_core_remote} HEAD #{default_origin_branch}" | 
					
						
							|  |  |  |       ohai "git cat-file -e #{full_origin_branch}:#{formula_path}" | 
					
						
							|  |  |  |       ohai "git checkout #{full_origin_branch}" | 
					
						
							| 
									
										
										
										
											2021-03-21 12:35:45 -04:00
										 |  |  |       return tap_remote_repo, homebrew_core_remote, default_origin_branch, previous_branch | 
					
						
							| 
									
										
										
										
											2019-11-06 21:20:49 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-11-27 18:45:13 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |     formula.tap.path.cd do | 
					
						
							| 
									
										
										
										
											2021-03-17 15:34:20 +00:00
										 |  |  |       unless Utils.popen_read("git", "remote", "-v").match?(%r{^homebrew.*Homebrew/homebrew-core.*$}) | 
					
						
							| 
									
										
										
										
											2020-11-27 18:45:13 +11:00
										 |  |  |         ohai "Adding #{homebrew_core_remote} remote" | 
					
						
							|  |  |  |         safe_system "git", "remote", "add", homebrew_core_remote, homebrew_core_url | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       ohai "Fetching remote #{homebrew_core_remote}" | 
					
						
							|  |  |  |       safe_system "git", "fetch", homebrew_core_remote, "HEAD", default_origin_branch | 
					
						
							|  |  |  |       if quiet_system "git", "cat-file", "-e", "#{full_origin_branch}:#{formula_path}" | 
					
						
							| 
									
										
										
										
											2021-01-26 15:21:24 -05:00
										 |  |  |         ohai "#{formula.full_name} exists in #{full_origin_branch}." | 
					
						
							| 
									
										
										
										
											2020-11-27 18:45:13 +11:00
										 |  |  |         safe_system "git", "checkout", full_origin_branch | 
					
						
							| 
									
										
										
										
											2021-03-21 12:35:45 -04:00
										 |  |  |         return tap_remote_repo, homebrew_core_remote, default_origin_branch, previous_branch | 
					
						
							| 
									
										
										
										
											2020-11-27 18:45:13 +11:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-08-14 11:42:50 -07:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2019-11-06 21:20:49 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-30 18:25:38 +05:30
										 |  |  |   def bump_formula_pr | 
					
						
							| 
									
										
										
										
											2020-07-30 18:40:10 +02:00
										 |  |  |     args = bump_formula_pr_args.parse | 
					
						
							| 
									
										
										
										
											2017-02-12 09:22:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-08 21:54:03 -05:00
										 |  |  |     if args.revision.present? && args.tag.nil? && args.version.nil? | 
					
						
							|  |  |  |       raise UsageError, "`--revision` must be passed with either `--tag` or `--version`!" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-08-19 10:34:48 -04:00
										 |  |  |     formula = args.named.to_formulae.first | 
					
						
							| 
									
										
										
										
											2017-02-12 09:22:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |     new_url = args.url | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |     formula ||= determine_formula_from_url(new_url) if new_url.present? | 
					
						
							|  |  |  |     raise FormulaUnspecifiedError if formula.blank? | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-15 12:29:11 -07:00
										 |  |  |     odie "This formula is disabled!" if formula.disabled? | 
					
						
							| 
									
										
										
										
											2021-01-24 09:34:53 -08:00
										 |  |  |     odie "This formula is deprecated and does not build!" if formula.deprecation_reason == :does_not_build | 
					
						
							| 
									
										
										
										
											2021-01-08 11:42:37 -08:00
										 |  |  |     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? | 
					
						
							| 
									
										
										
										
											2020-09-15 12:29:11 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-10 09:47:20 -08:00
										 |  |  |     formula_spec = formula.stable | 
					
						
							|  |  |  |     odie "#{formula}: no stable specification found!" if formula_spec.blank? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 12:35:45 -04:00
										 |  |  |     tap_remote_repo, remote, remote_branch, previous_branch = use_correct_linux_tap(formula, args: args) | 
					
						
							|  |  |  |     check_open_pull_requests(formula, tap_remote_repo, args: args) | 
					
						
							| 
									
										
										
										
											2020-07-16 20:35:09 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     new_version = args.version | 
					
						
							| 
									
										
										
										
											2021-03-21 12:35:45 -04:00
										 |  |  |     check_new_version(formula, tap_remote_repo, version: new_version, args: args) if new_version.present? | 
					
						
							| 
									
										
										
										
											2017-02-12 09:22:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 16:05:50 -07:00
										 |  |  |     opoo "This formula has patches that may be resolved upstream." if formula.patchlist.present? | 
					
						
							| 
									
										
										
										
											2020-10-06 23:22:07 -04:00
										 |  |  |     if formula.resources.any? { |resource| !resource.name.start_with?("homebrew-") } | 
					
						
							| 
									
										
										
										
											2020-10-01 14:40:36 -04:00
										 |  |  |       opoo "This formula has resources that may need to be updated." | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-08-13 16:05:50 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-07 10:22:08 -07:00
										 |  |  |     old_mirrors = formula_spec.mirrors | 
					
						
							| 
									
										
										
										
											2020-09-04 12:53:37 -07:00
										 |  |  |     new_mirrors ||= args.mirror | 
					
						
							|  |  |  |     new_mirror ||= determine_mirror(new_url) | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |     new_mirrors ||= [new_mirror] if new_mirror.present? | 
					
						
							| 
									
										
										
										
											2020-09-04 12:53:37 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |     check_for_mirrors(formula, old_mirrors, new_mirrors, args: args) if new_url.present? | 
					
						
							| 
									
										
										
										
											2020-09-04 12:53:37 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-07 08:33:57 +01:00
										 |  |  |     old_hash = formula_spec.checksum&.hexdigest | 
					
						
							|  |  |  |     new_hash = args.sha256 | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |     new_tag = args.tag | 
					
						
							|  |  |  |     new_revision = args.revision | 
					
						
							| 
									
										
										
										
											2020-07-15 08:16:33 -07:00
										 |  |  |     old_url = formula_spec.url | 
					
						
							|  |  |  |     old_tag = formula_spec.specs[:tag] | 
					
						
							| 
									
										
										
										
											2021-01-10 09:47:20 -08:00
										 |  |  |     old_formula_version = formula_version(formula) | 
					
						
							| 
									
										
										
										
											2020-07-15 08:16:33 -07:00
										 |  |  |     old_version = old_formula_version.to_s | 
					
						
							| 
									
										
										
										
											2020-07-16 20:35:09 -07:00
										 |  |  |     forced_version = new_version.present? | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |     new_url_hash = if new_url.present? && new_hash.present? | 
					
						
							| 
									
										
										
										
											2021-03-21 12:35:45 -04:00
										 |  |  |       check_new_version(formula, tap_remote_repo, url: new_url, args: args) if new_version.blank? | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |       true | 
					
						
							| 
									
										
										
										
											2021-01-10 09:47:20 -08:00
										 |  |  |     elsif new_tag.present? && new_revision.present? | 
					
						
							| 
									
										
										
										
											2021-03-21 12:35:45 -04:00
										 |  |  |       check_new_version(formula, tap_remote_repo, url: old_url, tag: new_tag, args: args) if new_version.blank? | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |       false | 
					
						
							| 
									
										
										
										
											2021-01-07 08:33:57 +01:00
										 |  |  |     elsif old_hash.blank? | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |       if new_tag.blank? && new_version.blank? && new_revision.blank? | 
					
						
							| 
									
										
										
										
											2020-12-08 21:54:03 -05:00
										 |  |  |         raise UsageError, "#{formula}: no --tag= or --version= argument specified!" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |       if old_tag.present? | 
					
						
							| 
									
										
										
										
											2020-12-08 21:54:03 -05:00
										 |  |  |         new_tag ||= old_tag.gsub(old_version, new_version) | 
					
						
							|  |  |  |         if new_tag == old_tag | 
					
						
							|  |  |  |           odie <<~EOS | 
					
						
							|  |  |  |             You need to bump this formula manually since the new tag | 
					
						
							|  |  |  |             and old tag are both #{new_tag}. | 
					
						
							|  |  |  |           EOS | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2021-03-21 12:35:45 -04:00
										 |  |  |         check_new_version(formula, tap_remote_repo, url: old_url, tag: new_tag, args: args) if new_version.blank? | 
					
						
							| 
									
										
										
										
											2020-12-08 21:54:03 -05:00
										 |  |  |         resource_path, forced_version = fetch_resource(formula, new_version, old_url, tag: new_tag) | 
					
						
							| 
									
										
										
										
											2021-03-17 15:34:20 +00:00
										 |  |  |         new_revision = Utils.popen_read("git", "-C", resource_path.to_s, "rev-parse", "-q", "--verify", "HEAD") | 
					
						
							| 
									
										
										
										
											2020-12-08 21:54:03 -05:00
										 |  |  |         new_revision = new_revision.strip | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |       elsif new_revision.blank? | 
					
						
							| 
									
										
										
										
											2021-01-24 21:40:41 -05:00
										 |  |  |         odie "#{formula}: the current URL requires specifying a `--revision=` argument." | 
					
						
							| 
									
										
										
										
											2020-07-15 08:16:33 -07:00
										 |  |  |       end | 
					
						
							|  |  |  |       false | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |     elsif new_url.blank? && new_version.blank? | 
					
						
							| 
									
										
										
										
											2020-12-08 21:54:03 -05:00
										 |  |  |       raise UsageError, "#{formula}: no --url= or --version= argument specified!" | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2020-07-31 10:10:07 -04:00
										 |  |  |       new_url ||= PyPI.update_pypi_url(old_url, new_version) | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |       if new_url.blank? | 
					
						
							| 
									
										
										
										
											2020-09-07 10:22:08 -07:00
										 |  |  |         new_url = old_url.gsub(old_version, new_version) | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |         if new_mirrors.blank? && old_mirrors.present? | 
					
						
							| 
									
										
										
										
											2020-09-07 10:22:08 -07:00
										 |  |  |           new_mirrors = old_mirrors.map do |old_mirror| | 
					
						
							|  |  |  |             old_mirror.gsub(old_version, new_version) | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-07-15 08:16:33 -07:00
										 |  |  |       if new_url == old_url | 
					
						
							|  |  |  |         odie <<~EOS | 
					
						
							| 
									
										
										
										
											2020-07-20 07:44:42 -07:00
										 |  |  |           You need to bump this formula manually since the new URL | 
					
						
							| 
									
										
										
										
											2020-07-15 08:16:33 -07:00
										 |  |  |           and old URL are both: | 
					
						
							|  |  |  |             #{new_url} | 
					
						
							|  |  |  |         EOS | 
					
						
							| 
									
										
										
										
											2020-03-13 17:09:58 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2021-03-21 12:35:45 -04:00
										 |  |  |       check_new_version(formula, tap_remote_repo, url: new_url, args: args) if new_version.blank? | 
					
						
							| 
									
										
										
										
											2020-07-15 08:16:33 -07:00
										 |  |  |       resource_path, forced_version = fetch_resource(formula, new_version, new_url) | 
					
						
							| 
									
										
										
										
											2020-09-04 14:13:43 -07:00
										 |  |  |       Utils::Tar.validate_file(resource_path) | 
					
						
							|  |  |  |       new_hash = resource_path.sha256 | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-17 08:17:56 -07:00
										 |  |  |     replacement_pairs = [] | 
					
						
							| 
									
										
										
										
											2021-01-10 09:47:20 -08:00
										 |  |  |     if 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
										 |  |  |       [ | 
					
						
							| 
									
										
										
										
											2020-06-02 09:49:23 +01:00
										 |  |  |         / +mirror "#{Regexp.escape(mirror)}"\n/m, | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |         "", | 
					
						
							|  |  |  |       ] | 
					
						
							| 
									
										
										
										
											2016-12-22 00:54:08 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-09-04 11:28:02 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |     replacement_pairs += if new_url_hash.present? | 
					
						
							| 
									
										
										
										
											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
										 |  |  |       ] | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |     elsif new_tag.present? | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |       [ | 
					
						
							| 
									
										
										
										
											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
										 |  |  |       ] | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |     elsif new_url.present? | 
					
						
							| 
									
										
										
										
											2020-12-08 21:54:03 -05:00
										 |  |  |       [ | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |           /#{Regexp.escape(formula_spec.url)}/, | 
					
						
							|  |  |  |           new_url, | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |           formula_spec.specs[:revision], | 
					
						
							|  |  |  |           new_revision, | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       ] | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       [ | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |           formula_spec.specs[:revision], | 
					
						
							|  |  |  |           new_revision, | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       ] | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-10 09:47:20 -08:00
										 |  |  |     old_contents = formula.path.read | 
					
						
							| 
									
										
										
										
											2016-06-17 10:10:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |     if new_mirrors.present? | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |       replacement_pairs << [ | 
					
						
							| 
									
										
										
										
											2020-06-02 09:49:23 +01:00
										 |  |  |         /^( +)(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. | 
					
						
							| 
									
										
										
										
											2021-01-10 09:47:20 -08:00
										 |  |  |     if old_contents.include?("depends_on :linux") && old_contents.include?("=> :x86_64_linux") | 
					
						
							| 
									
										
										
										
											2020-01-18 00:08:22 +01:00
										 |  |  |       replacement_pairs << [ | 
					
						
							|  |  |  |         /^    sha256 ".+" => :x86_64_linux\n/m, | 
					
						
							|  |  |  |         "\\2", | 
					
						
							|  |  |  |       ] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-15 08:16:33 -07:00
										 |  |  |     if forced_version && new_version != "0" | 
					
						
							| 
									
										
										
										
											2021-01-10 09:47:20 -08:00
										 |  |  |       replacement_pairs << if old_contents.include?("version \"#{old_formula_version}\"") | 
					
						
							| 
									
										
										
										
											2020-07-20 07:44:42 -07:00
										 |  |  |         [ | 
					
						
							|  |  |  |           old_formula_version.to_s, | 
					
						
							|  |  |  |           new_version, | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |         ] | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |       elsif new_mirrors.present? | 
					
						
							| 
									
										
										
										
											2020-07-20 07:44:42 -07:00
										 |  |  |         [ | 
					
						
							|  |  |  |           /^( +)(mirror "#{Regexp.escape(new_mirrors.last)}"\n)/m, | 
					
						
							|  |  |  |           "\\1\\2\\1version \"#{new_version}\"\n", | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |         ] | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |       elsif new_url.present? | 
					
						
							| 
									
										
										
										
											2020-07-20 07:44:42 -07:00
										 |  |  |         [ | 
					
						
							|  |  |  |           /^( +)(url "#{Regexp.escape(new_url)}"\n)/m, | 
					
						
							|  |  |  |           "\\1\\2\\1version \"#{new_version}\"\n", | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |         ] | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |       elsif new_revision.present? | 
					
						
							| 
									
										
										
										
											2020-07-25 11:20:32 +02:00
										 |  |  |         [ | 
					
						
							|  |  |  |           /^( {2})( +)(:revision => "#{new_revision}"\n)/m, | 
					
						
							|  |  |  |           "\\1\\2\\3\\1version \"#{new_version}\"\n", | 
					
						
							|  |  |  |         ] | 
					
						
							| 
									
										
										
										
											2016-09-27 02:50:46 -07:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-07-20 07:44:42 -07:00
										 |  |  |     elsif forced_version && new_version == "0" | 
					
						
							|  |  |  |       replacement_pairs << [ | 
					
						
							|  |  |  |         /^  version "[\w.\-+]+"\n/m, | 
					
						
							|  |  |  |         "", | 
					
						
							|  |  |  |       ] | 
					
						
							| 
									
										
										
										
											2016-07-06 05:00:45 -07:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-08-16 10:28:26 -07:00
										 |  |  |     new_contents = Utils::Inreplace.inreplace_pairs(formula.path, | 
					
						
							|  |  |  |                                                     replacement_pairs.uniq.compact, | 
					
						
							| 
									
										
										
										
											2020-09-04 07:17:21 -07:00
										 |  |  |                                                     read_only_run: args.dry_run?, | 
					
						
							| 
									
										
										
										
											2020-08-16 10:28:26 -07:00
										 |  |  |                                                     silent:        args.quiet?) | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-10 09:47:20 -08:00
										 |  |  |     new_formula_version = formula_version(formula, new_contents) | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if new_formula_version < old_formula_version | 
					
						
							| 
									
										
										
										
											2020-09-04 07:17:21 -07:00
										 |  |  |       formula.path.atomic_write(old_contents) unless args.dry_run? | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |       odie <<~EOS | 
					
						
							| 
									
										
										
										
											2020-12-08 21:54:03 -05:00
										 |  |  |         You need to bump this formula manually since changing the version | 
					
						
							|  |  |  |         from #{old_formula_version} to #{new_formula_version} would be a downgrade. | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |       EOS | 
					
						
							|  |  |  |     elsif new_formula_version == old_formula_version | 
					
						
							| 
									
										
										
										
											2020-09-04 07:17:21 -07:00
										 |  |  |       formula.path.atomic_write(old_contents) unless args.dry_run? | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |       odie <<~EOS | 
					
						
							| 
									
										
										
										
											2020-07-20 07:44:42 -07:00
										 |  |  |         You need to bump this formula manually since the new version | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |         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? | 
					
						
							| 
									
										
										
										
											2020-07-29 17:31:11 -04:00
										 |  |  |       ohai "Renaming alias #{alias_rename.first} to #{alias_rename.last}" | 
					
						
							| 
									
										
										
										
											2019-07-14 02:02:31 +02:00
										 |  |  |       alias_rename.map! { |a| formula.tap.alias_dir/a } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 07:17:21 -07:00
										 |  |  |     unless args.dry_run? | 
					
						
							| 
									
										
										
										
											2020-11-20 09:27:42 -05:00
										 |  |  |       resources_checked = PyPI.update_python_resources! formula, version: new_formula_version, | 
					
						
							| 
									
										
										
										
											2020-09-17 21:35:01 -04:00
										 |  |  |                                                         silent: args.quiet?, ignore_non_pypi_packages: true | 
					
						
							| 
									
										
										
										
											2020-07-27 10:39:09 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-31 19:33:18 +02:00
										 |  |  |     run_audit(formula, alias_rename, old_contents, args: args) | 
					
						
							| 
									
										
										
										
											2016-06-17 10:10:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 21:35:01 -04:00
										 |  |  |     pr_message = "Created with `brew bump-formula-pr`." | 
					
						
							| 
									
										
										
										
											2020-10-06 23:22:07 -04:00
										 |  |  |     if resources_checked.nil? && formula.resources.any? { |resource| !resource.name.start_with?("homebrew-") } | 
					
						
							| 
									
										
										
										
											2020-09-17 21:35:01 -04:00
										 |  |  |       pr_message += <<~EOS | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         `resource` blocks may require updates. | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 06:18:34 -07:00
										 |  |  |     pr_info = { | 
					
						
							|  |  |  |       sourcefile_path:  formula.path, | 
					
						
							|  |  |  |       old_contents:     old_contents, | 
					
						
							|  |  |  |       additional_files: alias_rename, | 
					
						
							| 
									
										
										
										
											2020-11-27 18:45:13 +11:00
										 |  |  |       remote:           remote, | 
					
						
							|  |  |  |       remote_branch:    remote_branch, | 
					
						
							| 
									
										
										
										
											2020-09-04 06:18:34 -07:00
										 |  |  |       branch_name:      "bump-#{formula.name}-#{new_formula_version}", | 
					
						
							|  |  |  |       commit_message:   "#{formula.name} #{new_formula_version}", | 
					
						
							|  |  |  |       previous_branch:  previous_branch, | 
					
						
							|  |  |  |       tap:              formula.tap, | 
					
						
							| 
									
										
										
										
											2021-03-21 12:35:45 -04:00
										 |  |  |       tap_remote_repo:  tap_remote_repo, | 
					
						
							| 
									
										
										
										
											2020-09-17 21:35:01 -04:00
										 |  |  |       pr_message:       pr_message, | 
					
						
							| 
									
										
										
										
											2020-09-04 06:18:34 -07:00
										 |  |  |     } | 
					
						
							|  |  |  |     GitHub.create_bump_pr(pr_info, args: args) | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-03-25 23:49:54 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-20 07:44:42 -07:00
										 |  |  |   def determine_formula_from_url(url) | 
					
						
							| 
									
										
										
										
											2020-07-15 08:16:33 -07: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. | 
					
						
							|  |  |  |     url_split = url.split("/") | 
					
						
							|  |  |  |     maximum_url_components_to_match = 5
 | 
					
						
							|  |  |  |     components_to_match = [url_split.count - 1, maximum_url_components_to_match].min | 
					
						
							|  |  |  |     base_url = url_split.first(components_to_match).join("/") | 
					
						
							|  |  |  |     base_url = /#{Regexp.escape(base_url)}/ | 
					
						
							|  |  |  |     guesses = [] | 
					
						
							|  |  |  |     Formula.each do |f| | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |       guesses << f if f.stable&.url&.match(base_url) | 
					
						
							| 
									
										
										
										
											2020-07-15 08:16:33 -07:00
										 |  |  |     end | 
					
						
							|  |  |  |     return guesses.shift if guesses.count == 1
 | 
					
						
							| 
									
										
										
										
											2020-07-20 07:44:42 -07:00
										 |  |  |     return if guesses.count <= 1
 | 
					
						
							| 
									
										
										
										
											2020-07-15 08:16:33 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     odie "Couldn't guess formula for sure; could be one of these:\n#{guesses.map(&:name).join(", ")}" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 16:05:09 -07:00
										 |  |  |   def determine_mirror(url) | 
					
						
							|  |  |  |     case url | 
					
						
							|  |  |  |     when %r{.*ftp.gnu.org/gnu.*} | 
					
						
							|  |  |  |       url.sub "ftp.gnu.org/gnu", "ftpmirror.gnu.org" | 
					
						
							|  |  |  |     when %r{.*download.savannah.gnu.org/*} | 
					
						
							|  |  |  |       url.sub "download.savannah.gnu.org", "download-mirror.savannah.gnu.org" | 
					
						
							|  |  |  |     when %r{.*www.apache.org/dyn/closer.lua\?path=.*} | 
					
						
							|  |  |  |       url.sub "www.apache.org/dyn/closer.lua?path=", "archive.apache.org/dist/" | 
					
						
							|  |  |  |     when %r{.*mirrors.ocf.berkeley.edu/debian.*} | 
					
						
							|  |  |  |       url.sub "mirrors.ocf.berkeley.edu/debian", "mirrorservice.org/sites/ftp.debian.org/debian" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-07 10:22:08 -07:00
										 |  |  |   def check_for_mirrors(formula, old_mirrors, new_mirrors, args:) | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |     return if new_mirrors.present? || old_mirrors.empty? | 
					
						
							| 
									
										
										
										
											2020-09-07 10:22:08 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if args.force? | 
					
						
							| 
									
										
										
										
											2021-01-24 21:40:41 -05:00
										 |  |  |       opoo "#{formula}: Removing all mirrors because a `--mirror=` argument was not specified." | 
					
						
							| 
									
										
										
										
											2020-09-07 10:22:08 -07:00
										 |  |  |     else | 
					
						
							|  |  |  |       odie <<~EOS | 
					
						
							| 
									
										
										
										
											2021-01-24 21:40:41 -05:00
										 |  |  |         #{formula}: a `--mirror=` argument for updating the mirror URL(s) was not specified. | 
					
						
							|  |  |  |         Use `--force` to remove all mirrors. | 
					
						
							| 
									
										
										
										
											2020-09-07 10:22:08 -07:00
										 |  |  |       EOS | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-15 08:16:33 -07:00
										 |  |  |   def fetch_resource(formula, new_version, url, **specs) | 
					
						
							|  |  |  |     resource = Resource.new | 
					
						
							|  |  |  |     resource.url(url, specs) | 
					
						
							|  |  |  |     resource.owner = Resource.new(formula.name) | 
					
						
							|  |  |  |     forced_version = new_version && new_version != resource.version | 
					
						
							|  |  |  |     resource.version = new_version if forced_version | 
					
						
							| 
									
										
										
										
											2021-01-24 21:40:41 -05:00
										 |  |  |     odie "No `--version=` argument specified!" if resource.version.blank? | 
					
						
							| 
									
										
										
										
											2020-07-15 08:16:33 -07:00
										 |  |  |     [resource.fetch, forced_version] | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-10 09:47:20 -08:00
										 |  |  |   def formula_version(formula, contents = nil) | 
					
						
							|  |  |  |     spec = :stable | 
					
						
							| 
									
										
										
										
											2018-03-25 23:49:54 +05:30
										 |  |  |     name = formula.name | 
					
						
							|  |  |  |     path = formula.path | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |     if contents.present? | 
					
						
							| 
									
										
										
										
											2018-03-25 23:49:54 +05:30
										 |  |  |       Formulary.from_contents(name, path, contents, spec).version | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       Formulary::FormulaLoader.new(name, path).get_formula(spec).version | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 12:35:45 -04:00
										 |  |  |   def check_open_pull_requests(formula, tap_remote_repo, args:) | 
					
						
							|  |  |  |     GitHub.check_for_duplicate_pull_requests(formula.name, tap_remote_repo, | 
					
						
							| 
									
										
										
										
											2021-01-07 09:15:18 -08:00
										 |  |  |                                              state: "open", | 
					
						
							|  |  |  |                                              file:  formula.path.relative_path_from(formula.tap.path).to_s, | 
					
						
							|  |  |  |                                              args:  args) | 
					
						
							| 
									
										
										
										
											2020-07-16 20:35:09 -07:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-06-14 20:49:52 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 12:35:45 -04:00
										 |  |  |   def check_new_version(formula, tap_remote_repo, args:, version: nil, url: nil, tag: nil) | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |     if version.nil? | 
					
						
							| 
									
										
										
										
											2020-07-20 07:44:42 -07:00
										 |  |  |       specs = {} | 
					
						
							| 
									
										
										
										
											2021-01-04 15:29:01 -08:00
										 |  |  |       specs[:tag] = tag if tag.present? | 
					
						
							| 
									
										
										
										
											2020-08-09 02:59:18 +02:00
										 |  |  |       version = Version.detect(url, **specs) | 
					
						
							| 
									
										
										
										
											2020-07-20 07:44:42 -07:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2021-01-24 09:34:53 -08:00
										 |  |  |     check_throttle(formula, version) | 
					
						
							| 
									
										
										
										
											2021-03-21 12:35:45 -04:00
										 |  |  |     check_closed_pull_requests(formula, tap_remote_repo, args: args, version: version) | 
					
						
							| 
									
										
										
										
											2021-01-24 09:34:53 -08:00
										 |  |  |   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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 12:35:45 -04:00
										 |  |  |   def check_closed_pull_requests(formula, tap_remote_repo, args:, version:) | 
					
						
							| 
									
										
										
										
											2020-08-05 12:50:56 -07:00
										 |  |  |     # if we haven't already found open requests, try for an exact match across closed requests | 
					
						
							| 
									
										
										
										
											2021-03-21 12:35:45 -04:00
										 |  |  |     GitHub.check_for_duplicate_pull_requests(formula.name, tap_remote_repo, | 
					
						
							| 
									
										
										
										
											2021-01-24 09:34:53 -08:00
										 |  |  |                                              version: version, | 
					
						
							|  |  |  |                                              state:   "closed", | 
					
						
							|  |  |  |                                              file:    formula.path.relative_path_from(formula.tap.path).to_s, | 
					
						
							|  |  |  |                                              args:    args) | 
					
						
							| 
									
										
										
										
											2018-03-25 23:49:54 +05:30
										 |  |  |   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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-31 19:33:18 +02:00
										 |  |  |   def run_audit(formula, alias_rename, old_contents, args:) | 
					
						
							| 
									
										
										
										
											2021-01-30 19:12:40 -05:00
										 |  |  |     audit_args = ["--formula"] | 
					
						
							| 
									
										
										
										
											2020-09-15 18:58:38 -07:00
										 |  |  |     audit_args << "--strict" if args.strict? | 
					
						
							|  |  |  |     audit_args << "--online" if args.online? | 
					
						
							| 
									
										
										
										
											2019-07-16 23:05:36 +02:00
										 |  |  |     if args.dry_run? | 
					
						
							|  |  |  |       if args.no_audit? | 
					
						
							|  |  |  |         ohai "Skipping `brew audit`" | 
					
						
							| 
									
										
										
										
											2020-09-15 18:58:38 -07:00
										 |  |  |       elsif audit_args.present? | 
					
						
							|  |  |  |         ohai "brew audit #{audit_args.join(" ")} #{formula.path.basename}" | 
					
						
							| 
									
										
										
										
											2019-07-16 23:05:36 +02:00
										 |  |  |       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`" | 
					
						
							| 
									
										
										
										
											2020-09-15 18:58:38 -07:00
										 |  |  |     elsif audit_args.present? | 
					
						
							|  |  |  |       system HOMEBREW_BREW_FILE, "audit", *audit_args, formula.path | 
					
						
							| 
									
										
										
										
											2019-07-16 23:05:36 +02:00
										 |  |  |       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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-16 20:35:09 -07:00
										 |  |  |     formula.path.atomic_write(old_contents) | 
					
						
							| 
									
										
										
										
											2019-07-16 23:05:36 +02:00
										 |  |  |     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 |