| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  | # typed: strict | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-25 06:38:00 -04:00
										 |  |  | require "bump_version_parser" | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  | require "cask" | 
					
						
							| 
									
										
										
										
											2021-08-24 18:15:04 -07:00
										 |  |  | require "cask/download" | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  | require "cli/parser" | 
					
						
							|  |  |  | require "utils/tar" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module Homebrew | 
					
						
							|  |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   sig { returns(CLI::Parser) } | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |   def bump_cask_pr_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							| 
									
										
										
										
											2021-01-15 15:04:02 -05:00
										 |  |  |       description <<~EOS | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |         Create a pull request to update <cask> with a new version. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         A best effort to determine the <SHA-256> will be made if the value is not | 
					
						
							|  |  |  |         supplied by the user. | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |       switch "-n", "--dry-run", | 
					
						
							|  |  |  |              description: "Print what would be done rather than doing it." | 
					
						
							| 
									
										
										
										
											2021-10-20 22:36:07 +11:00
										 |  |  |       switch "--write-only", | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |              description: "Make the expected file modifications without taking any Git actions." | 
					
						
							|  |  |  |       switch "--commit", | 
					
						
							| 
									
										
										
										
											2021-11-19 12:14:47 -08:00
										 |  |  |              depends_on:  "--write-only", | 
					
						
							| 
									
										
										
										
											2022-06-28 10:09:59 +01:00
										 |  |  |              description: "When passed with `--write-only`, generate a new commit after writing changes " \ | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |                           "to the cask file." | 
					
						
							|  |  |  |       switch "--no-audit", | 
					
						
							| 
									
										
										
										
											2020-11-18 08:10:21 +01:00
										 |  |  |              description: "Don't run `brew audit` before opening the PR." | 
					
						
							| 
									
										
										
										
											2020-09-16 10:56:54 -07:00
										 |  |  |       switch "--online", | 
					
						
							| 
									
										
										
										
											2023-09-08 12:58:07 -04:00
										 |  |  |              hidden:      true | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |       switch "--no-style", | 
					
						
							| 
									
										
										
										
											2020-11-18 08:10:21 +01:00
										 |  |  |              description: "Don't run `brew style --fix` before opening the PR." | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |       switch "--no-browse", | 
					
						
							|  |  |  |              description: "Print the pull request URL instead of opening in a browser." | 
					
						
							|  |  |  |       switch "--no-fork", | 
					
						
							|  |  |  |              description: "Don't try to fork the repository." | 
					
						
							|  |  |  |       flag   "--version=", | 
					
						
							|  |  |  |              description: "Specify the new <version> for the cask." | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |       flag   "--version-arm=", | 
					
						
							|  |  |  |              description: "Specify the new cask <version> for the ARM architecture." | 
					
						
							|  |  |  |       flag   "--version-intel=", | 
					
						
							|  |  |  |              description: "Specify the new cask <version> for the Intel architecture." | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |       flag   "--message=", | 
					
						
							| 
									
										
										
										
											2022-11-19 23:03:23 +00:00
										 |  |  |              description: "Prepend <message> to the default pull request message." | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |       flag   "--url=", | 
					
						
							|  |  |  |              description: "Specify the <URL> for the new download." | 
					
						
							|  |  |  |       flag   "--sha256=", | 
					
						
							|  |  |  |              description: "Specify the <SHA-256> checksum of the new download." | 
					
						
							| 
									
										
										
										
											2021-04-18 20:53:01 +02:00
										 |  |  |       flag   "--fork-org=", | 
					
						
							|  |  |  |              description: "Use the specified GitHub organization for forking." | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |       switch "-f", "--force", | 
					
						
							|  |  |  |              description: "Ignore duplicate open PRs." | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       conflicts "--dry-run", "--write" | 
					
						
							| 
									
										
										
										
											2020-09-16 10:56:54 -07:00
										 |  |  |       conflicts "--no-audit", "--online" | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |       conflicts "--version=", "--version-arm=" | 
					
						
							|  |  |  |       conflicts "--version=", "--version-intel=" | 
					
						
							| 
									
										
										
										
											2021-01-10 14:26:40 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-22 16:53:46 +01:00
										 |  |  |       named_args :cask, number: 1, without_api: true | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |   sig { void } | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |   def bump_cask_pr | 
					
						
							|  |  |  |     args = bump_cask_pr_args.parse | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-08 12:58:07 -04:00
										 |  |  |     # odeprecated "brew bump-cask-pr --online" if args.online? | 
					
						
							| 
									
										
										
										
											2023-07-18 10:48:11 +01:00
										 |  |  |     # This will be run by `brew audit` or `brew style` later so run it first to | 
					
						
							|  |  |  |     # not start spamming during normal output. | 
					
						
							| 
									
										
										
										
											2023-10-27 19:44:02 +01:00
										 |  |  |     gem_groups = [] | 
					
						
							|  |  |  |     gem_groups << "style" if !args.no_audit? || !args.no_style? | 
					
						
							|  |  |  |     gem_groups << "audit" unless args.no_audit? | 
					
						
							|  |  |  |     Homebrew.install_bundler_gems!(groups: gem_groups) unless gem_groups.empty? | 
					
						
							| 
									
										
										
										
											2021-04-30 12:00:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |     # As this command is simplifying user-run commands then let's just use a | 
					
						
							|  |  |  |     # user path, too. | 
					
						
							| 
									
										
										
										
											2022-06-15 05:40:43 +01:00
										 |  |  |     ENV["PATH"] = PATH.new(ORIGINAL_PATHS).to_s | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Use the user's browser, too. | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |     ENV["BROWSER"] = EnvConfig.browser | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     cask = args.named.to_casks.first | 
					
						
							| 
									
										
										
										
											2021-01-08 11:42:37 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     odie "This cask is not in a tap!" if cask.tap.blank? | 
					
						
							|  |  |  |     odie "This cask's tap is not a Git repository!" unless cask.tap.git? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-25 06:38:00 -04:00
										 |  |  |     new_version = BumpVersionParser.new( | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |       general: args.version, | 
					
						
							|  |  |  |       intel:   args.version_intel, | 
					
						
							|  |  |  |       arm:     args.version_arm, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2023-03-30 04:11:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-01 01:07:21 +08:00
										 |  |  |     new_hash = unless (new_hash = args.sha256).nil? | 
					
						
							| 
									
										
										
										
											2023-03-30 04:11:23 +02:00
										 |  |  |       raise UsageError, "`--sha256` must not be empty." if new_hash.blank? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       ["no_check", ":no_check"].include?(new_hash) ? :no_check : new_hash | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     new_base_url = unless (new_base_url = args.url).nil? | 
					
						
							|  |  |  |       raise UsageError, "`--url` must not be empty." if new_base_url.blank? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       begin | 
					
						
							|  |  |  |         URI(new_base_url) | 
					
						
							|  |  |  |       rescue URI::InvalidURIError | 
					
						
							|  |  |  |         raise UsageError, "`--url` is not valid." | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-12-08 12:42:02 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |     if new_version.blank? && new_base_url.nil? && new_hash.nil? | 
					
						
							| 
									
										
										
										
											2023-02-10 23:15:40 -05:00
										 |  |  |       raise UsageError, "No `--version`, `--url` or `--sha256` argument specified!" | 
					
						
							| 
									
										
										
										
											2020-12-08 12:42:02 -08:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |     check_pull_requests(cask, args: args, new_version: new_version) | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |     replacement_pairs ||= [] | 
					
						
							| 
									
										
										
										
											2023-03-30 04:11:23 +02:00
										 |  |  |     branch_name = "bump-#{cask.token}" | 
					
						
							|  |  |  |     commit_message = nil | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |     old_contents = File.read(cask.sourcefile_path) | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-30 04:11:23 +02:00
										 |  |  |     if new_base_url | 
					
						
							|  |  |  |       commit_message ||= "#{cask.token}: update URL" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |       m = /^ +url "(.+?)"\n/m.match(old_contents) | 
					
						
							|  |  |  |       odie "Could not find old URL in cask!" if m.nil? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-13 18:31:26 -07:00
										 |  |  |       old_base_url = m.captures.fetch(0) | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       replacement_pairs << [ | 
					
						
							|  |  |  |         /#{Regexp.escape(old_base_url)}/, | 
					
						
							| 
									
										
										
										
											2023-04-25 14:38:59 -04:00
										 |  |  |         new_base_url.to_s, | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |       ] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 19:17:35 -07:00
										 |  |  |     if new_version.present? | 
					
						
							|  |  |  |       # For simplicity, our naming defers to the arm version if we multiple architectures are specified | 
					
						
							|  |  |  |       branch_version = new_version.arm || new_version.general | 
					
						
							|  |  |  |       if branch_version.is_a?(Cask::DSL::Version) | 
					
						
							| 
									
										
										
										
											2023-11-30 02:49:07 +00:00
										 |  |  |         commit_version = shortened_version(branch_version, cask: cask) | 
					
						
							| 
									
										
										
										
											2023-10-23 19:17:35 -07:00
										 |  |  |         branch_name = "bump-#{cask.token}-#{branch_version.tr(",:", "-")}" | 
					
						
							|  |  |  |         commit_message ||= "#{cask.token} #{commit_version}" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       replacement_pairs = replace_version_and_checksum(cask, new_hash, new_version, replacement_pairs) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     # Now that we have all replacement pairs, we will replace them further down | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-30 04:11:23 +02:00
										 |  |  |     commit_message ||= "#{cask.token}: update checksum" if new_hash | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |     # Remove nested arrays where elements are identical | 
					
						
							|  |  |  |     replacement_pairs = replacement_pairs.reject { |pair| pair[0] == pair[1] }.uniq.compact | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |     Utils::Inreplace.inreplace_pairs(cask.sourcefile_path, | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |                                      replacement_pairs, | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |                                      read_only_run: args.dry_run?, | 
					
						
							|  |  |  |                                      silent:        args.quiet?) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     run_cask_audit(cask, old_contents, args: args) | 
					
						
							|  |  |  |     run_cask_style(cask, old_contents, args: args) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     pr_info = { | 
					
						
							| 
									
										
										
										
											2020-12-08 12:42:02 -08:00
										 |  |  |       branch_name:     branch_name, | 
					
						
							|  |  |  |       commit_message:  commit_message, | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |       old_contents:    old_contents, | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |       pr_message:      "Created with `brew bump-cask-pr`.", | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |       sourcefile_path: cask.sourcefile_path, | 
					
						
							|  |  |  |       tap:             cask.tap, | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |     } | 
					
						
							|  |  |  |     GitHub.create_bump_pr(pr_info, args: args) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-30 02:49:07 +00:00
										 |  |  |   sig { params(version: Cask::DSL::Version, cask: Cask::Cask).returns(Cask::DSL::Version) } | 
					
						
							|  |  |  |   def shortened_version(version, cask:) | 
					
						
							|  |  |  |     if version.before_comma == cask.version.before_comma | 
					
						
							|  |  |  |       version | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       version.before_comma | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |   sig { | 
					
						
							|  |  |  |     params( | 
					
						
							|  |  |  |       cask:              Cask::Cask, | 
					
						
							| 
									
										
										
										
											2023-11-05 08:55:58 -08:00
										 |  |  |       new_hash:          T.any(NilClass, String, Symbol), | 
					
						
							| 
									
										
										
										
											2023-07-25 06:38:00 -04:00
										 |  |  |       new_version:       BumpVersionParser, | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |       replacement_pairs: T::Array[[T.any(Regexp, String), T.any(Regexp, String)]], | 
					
						
							|  |  |  |     ).returns(T::Array[[T.any(Regexp, String), T.any(Regexp, String)]]) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   def replace_version_and_checksum(cask, new_hash, new_version, replacement_pairs) | 
					
						
							|  |  |  |     # When blocks are absent, arch is not relevant. For consistency, we simulate the arm architecture. | 
					
						
							|  |  |  |     arch_options = cask.on_system_blocks_exist? ? OnSystem::ARCH_OPTIONS : [:arm] | 
					
						
							|  |  |  |     arch_options.each do |arch| | 
					
						
							|  |  |  |       SimulateSystem.with arch: arch do | 
					
						
							|  |  |  |         old_cask     = Cask::CaskLoader.load(cask.sourcefile_path) | 
					
						
							|  |  |  |         old_version  = old_cask.version | 
					
						
							|  |  |  |         bump_version = new_version.send(arch) || new_version.general | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         old_version_regex = old_version.latest? ? ":latest" : %Q(["']#{Regexp.escape(old_version.to_s)}["']) | 
					
						
							|  |  |  |         replacement_pairs << [/version\s+#{old_version_regex}/m, | 
					
						
							|  |  |  |                               "version #{bump_version.latest? ? ":latest" : %Q("#{bump_version}")}"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # We are replacing our version here so we can get the new hash | 
					
						
							|  |  |  |         tmp_contents = Utils::Inreplace.inreplace_pairs(cask.sourcefile_path, | 
					
						
							|  |  |  |                                                         replacement_pairs.uniq.compact, | 
					
						
							|  |  |  |                                                         read_only_run: true, | 
					
						
							|  |  |  |                                                         silent:        true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         tmp_cask = Cask::CaskLoader.load(tmp_contents) | 
					
						
							|  |  |  |         old_hash = tmp_cask.sha256 | 
					
						
							|  |  |  |         if tmp_cask.version.latest? || new_hash == :no_check | 
					
						
							|  |  |  |           opoo "Ignoring specified `--sha256=` argument." if new_hash.is_a?(String) | 
					
						
							|  |  |  |           replacement_pairs << [/"#{old_hash}"/, ":no_check"] if old_hash != :no_check | 
					
						
							|  |  |  |         elsif old_hash == :no_check && new_hash != :no_check | 
					
						
							|  |  |  |           replacement_pairs << [":no_check", "\"#{new_hash}\""] if new_hash.is_a?(String) | 
					
						
							| 
									
										
										
										
											2023-11-30 02:45:00 +00:00
										 |  |  |         elsif new_hash && !cask.on_system_blocks_exist? && cask.languages.empty? | 
					
						
							|  |  |  |           replacement_pairs << [old_hash.to_s, new_hash.to_s] | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |         elsif old_hash != :no_check | 
					
						
							| 
									
										
										
										
											2023-11-30 02:45:00 +00:00
										 |  |  |           opoo "Multiple checksum replacements required; ignoring specified `--sha256` argument." if new_hash | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |           languages = if cask.languages.empty? | 
					
						
							|  |  |  |             [nil] | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             cask.languages | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |           languages.each do |language| | 
					
						
							|  |  |  |             new_cask        = Cask::CaskLoader.load(tmp_contents) | 
					
						
							|  |  |  |             new_cask.config = if language.blank? | 
					
						
							|  |  |  |               tmp_cask.config | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |               tmp_cask.config.merge(Cask::Config.new(explicit: { languages: [language] })) | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |             download = Cask::Download.new(new_cask, quarantine: true).fetch(verify_download_integrity: false) | 
					
						
							|  |  |  |             Utils::Tar.validate_file(download) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if new_cask.sha256.to_s != download.sha256 | 
					
						
							|  |  |  |               replacement_pairs << [new_cask.sha256.to_s, | 
					
						
							|  |  |  |                                     download.sha256] | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     replacement_pairs | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-25 06:38:00 -04:00
										 |  |  |   sig { params(cask: Cask::Cask, args: CLI::Args, new_version: BumpVersionParser).void } | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |   def check_pull_requests(cask, args:, new_version:) | 
					
						
							| 
									
										
										
										
											2023-03-29 20:05:16 +08:00
										 |  |  |     tap_remote_repo = cask.tap.full_name || cask.tap.remote_repo | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 12:35:45 -04:00
										 |  |  |     GitHub.check_for_duplicate_pull_requests(cask.token, tap_remote_repo, | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |                                              state:   "open", | 
					
						
							|  |  |  |                                              version: nil, | 
					
						
							| 
									
										
										
										
											2023-01-19 17:06:42 -08:00
										 |  |  |                                              file:    cask.sourcefile_path.relative_path_from(cask.tap.path).to_s, | 
					
						
							|  |  |  |                                              args:    args) | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # if we haven't already found open requests, try for an exact match across closed requests | 
					
						
							|  |  |  |     new_version.instance_variables.each do |version_type| | 
					
						
							|  |  |  |       version = new_version.instance_variable_get(version_type) | 
					
						
							|  |  |  |       next if version.blank? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       GitHub.check_for_duplicate_pull_requests( | 
					
						
							|  |  |  |         cask.token, | 
					
						
							|  |  |  |         tap_remote_repo, | 
					
						
							|  |  |  |         state:   "closed", | 
					
						
							| 
									
										
										
										
											2023-11-30 02:49:07 +00:00
										 |  |  |         version: shortened_version(version, cask: cask), | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |         file:    cask.sourcefile_path.relative_path_from(cask.tap.path).to_s, | 
					
						
							|  |  |  |         args:    args, | 
					
						
							|  |  |  |       ) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |   sig { params(cask: Cask::Cask, old_contents: String, args: T.untyped).void } | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |   def run_cask_audit(cask, old_contents, args:) | 
					
						
							|  |  |  |     if args.dry_run? | 
					
						
							|  |  |  |       if args.no_audit? | 
					
						
							| 
									
										
										
										
											2020-11-18 08:10:21 +01:00
										 |  |  |         ohai "Skipping `brew audit`" | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2023-09-08 12:58:07 -04:00
										 |  |  |         ohai "brew audit --cask --online #{cask.full_name}" | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |       end | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     failed_audit = false | 
					
						
							|  |  |  |     if args.no_audit? | 
					
						
							| 
									
										
										
										
											2020-11-18 08:10:21 +01:00
										 |  |  |       ohai "Skipping `brew audit`" | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2023-09-08 12:58:07 -04:00
										 |  |  |       system HOMEBREW_BREW_FILE, "audit", "--cask", "--online", cask.full_name | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |       failed_audit = !$CHILD_STATUS.success? | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     return unless failed_audit | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cask.sourcefile_path.atomic_write(old_contents) | 
					
						
							| 
									
										
										
										
											2020-11-18 08:10:21 +01:00
										 |  |  |     odie "`brew audit` failed!" | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-21 11:45:34 -04:00
										 |  |  |   sig { params(cask: Cask::Cask, old_contents: String, args: T.untyped).void } | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |   def run_cask_style(cask, old_contents, args:) | 
					
						
							|  |  |  |     if args.dry_run? | 
					
						
							|  |  |  |       if args.no_style? | 
					
						
							| 
									
										
										
										
											2020-11-18 08:10:21 +01:00
										 |  |  |         ohai "Skipping `brew style --fix`" | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2020-11-18 08:10:21 +01:00
										 |  |  |         ohai "brew style --fix #{cask.sourcefile_path.basename}" | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |       end | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     failed_style = false | 
					
						
							|  |  |  |     if args.no_style? | 
					
						
							| 
									
										
										
										
											2020-11-18 08:10:21 +01:00
										 |  |  |       ohai "Skipping `brew style --fix`" | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2020-11-18 08:10:21 +01:00
										 |  |  |       system HOMEBREW_BREW_FILE, "style", "--fix", cask.sourcefile_path | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |       failed_style = !$CHILD_STATUS.success? | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     return unless failed_style | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cask.sourcefile_path.atomic_write(old_contents) | 
					
						
							| 
									
										
										
										
											2020-11-18 08:10:21 +01:00
										 |  |  |     odie "`brew style --fix` failed!" | 
					
						
							| 
									
										
										
										
											2020-09-04 16:58:31 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | end |