Class: Homebrew::DevCmd::BumpFormulaPr Private

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/bump-formula-pr.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/bump_formula_pr.rbi

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Defined Under Namespace

Classes: Args, PreparedBump

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#args ⇒ Homebrew::DevCmd::BumpFormulaPr::Args

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



10
# File 'sorbet/rbi/dsl/homebrew/dev_cmd/bump_formula_pr.rbi', line 10

def args; end

#check_throttle(formula, new_version) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
# File 'dev-cmd/bump-formula-pr.rb', line 647

def check_throttle(formula, new_version)
  tap = formula.tap
  return if tap.nil?

  throttle_rate = formula.livecheck.throttle
  throttle_days = formula.livecheck.throttle_days
  return if throttle_rate.nil? && throttle_days.nil?

  return if Livecheck.throttle_allows_bump?(
    formula,
    new_version,
    throttle_rate: throttle_rate,
    throttle_days: throttle_days,
  )

  throttle_items = []
  throttle_items << "#{throttle_rate} releases on multiples of #{throttle_rate}" if throttle_rate
  throttle_items << "#{throttle_days} #{Utils.pluralize("day", throttle_days)}" if throttle_days

  odie "#{formula} should only be updated every #{throttle_items.join(" or ")}"
end

#github_release_notes(new_url, added_release_info) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Include each upstream release's notes once per pull request.

Parameters:

Returns:



537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
# File 'dev-cmd/bump-formula-pr.rb', line 537

def github_release_notes(new_url, added_release_info)
  if new_url =~ %r{^https://github\.com/([\w-]+)/([\w-]+)/archive/refs/tags/(v?[.0-9]+)\.tar\.}
    owner = Regexp.last_match(1)
    repo = Regexp.last_match(2)
    tag = Regexp.last_match(3)
    release_id = "#{owner}/#{repo}/#{tag}"
    github_release_data = begin
      GitHub::API.open_rest("#{GitHub::API_URL}/repos/#{owner}/#{repo}/releases/tags/#{tag}")
    rescue GitHub::API::HTTPNotFoundError
      # If this is a 404: we can't do anything.
      nil
    end

    if github_release_data.present? && github_release_data["body"].present? &&
       added_release_info.exclude?(release_id)
      pre = "pre" if github_release_data["prerelease"].present?
      # maximum length of PR body is 65,536 characters so let's truncate release notes to half of that.
      body = Formatter.truncate(github_release_data["body"], max: 32_768)

      # Ensure the URL is properly HTML encoded to handle any quotes or other special characters
      html_url = CGI.escapeHTML(github_release_data["html_url"])

      added_release_info << release_id
      return <<~XML
        <details>
          <summary>#{pre}release notes</summary>
          <pre>#{body}</pre>
          <p>View the full release notes at <a href="#{html_url}">#{html_url}</a>.</p>
        </details>
      XML

    end
  end

  ""
end

#patch_source_ambiguous?(formula_ast) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Whether platform or conditional source declarations prevent checking patches against one release.

Parameters:

Returns:

  • (Boolean)


576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
# File 'dev-cmd/bump-formula-pr.rb', line 576

def patch_source_ambiguous?(formula_ast)
  patch_scope_nodes(formula_ast.children).any? do |node|
    if node.is_a?(Utils::AST::SendNode)
      node.method_name == :url && node.each_ancestor(:block).any? do |parent|
        Utils::AST::FormulaAST::PATCH_PLATFORM_BLOCKS.include?(parent.method_name)
      end
    elsif !node.is_a?(Utils::AST::BlockNode) && !node.def_type? && !node.defs_type?
      node.each_descendant(:send).any? do |call|
        call.method_name == :url && call.each_ancestor(:block).all? do |parent|
          [:stable, *Utils::AST::FormulaAST::PATCH_PLATFORM_BLOCKS].include?(parent.method_name)
        end
      end
    end
  end
end

#patches_for_removal(node, &block) ⇒ Array<Utils::AST::BlockNode>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Selects whole patches or independent platform branches containing only supported declarations. The caller must return true only when every URL yielded together is included in the release.

Parameters:

Returns:



598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
# File 'dev-cmd/bump-formula-pr.rb', line 598

def patches_for_removal(node, &block)
  platform_blocks = Utils::AST::FormulaAST::PATCH_PLATFORM_BLOCKS
  # Retain stable-only patches to avoid leaving a redundant `stable` block.
  return [] unless node.each_ancestor.all? do |parent|
    parent.class_type? || parent.begin_type? ||
    (parent.is_a?(Utils::AST::BlockNode) && parent.send_node.receiver.nil? &&
     [:patch, *platform_blocks].include?(parent.method_name))
  end
  return [] unless node.arguments.empty?

  if node.method_name == :patch && (arguments = node.send_node.arguments).present?
    strip = Utils::AST.literal_value(arguments.first)
    return [] if arguments.length != 1 || !strip.is_a?(Symbol) || !strip.to_s.match?(/\Ap\d+\z/)
  end

  children = Utils::AST.body_children(node.body)
  calls = patch_scope_nodes(children)
  unsupported_calls = calls.reject do |call|
    case call
    when Utils::AST::SendNode
      call.receiver.nil? && [:url, :sha256, :directory, :type, :resolves].include?(call.method_name)
    when Utils::AST::BlockNode
      call.send_node.receiver.nil? && call.arguments.empty? && platform_blocks.include?(call.method_name)
    end
  end

  if unsupported_calls.empty?
    urls = calls.grep(Utils::AST::SendNode).select { |call| call.method_name == :url }.map do |call|
      value = call.first_argument
      value.str_content if call.arguments.length == 1 && value&.str_type?
    end
    return [node] if urls.present? && urls.none?(&:nil?) && yield(urls.compact.uniq)
  end

  return [] if children.any? do |child|
    unsupported_calls.include?(child) || (child.is_a?(Utils::AST::SendNode) && child.method_name == :url)
  end

  branches = children.grep(Utils::AST::BlockNode)
  if branches.length > 1
    # Only split disjoint OS or architecture pairs.
    return [] unless branches.all? { |branch| branch.send_node.arguments.empty? }
    return [] unless [[:on_linux, :on_macos], [:on_arm, :on_intel]].include?(branches.map(&:method_name).sort)
  end

  branches.flat_map { |branch| patches_for_removal(branch, &block) }
end

#prepare_formula_bump(formula_name, formula, tap, tap_remote_repo, added_release_info, patch_inclusion) ⇒ PreparedBump

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Prepare one formula's source changes and pull request details.

Parameters:

Returns:

Raises:



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# File 'dev-cmd/bump-formula-pr.rb', line 272

def prepare_formula_bump(formula_name, formula, tap, tap_remote_repo, added_release_info, patch_inclusion)
  commit_formula = Formula[formula_name]
  raise FormulaUnspecifiedError if commit_formula.blank?

  commit_formula_spec = commit_formula.stable
  odie "#{commit_formula}: no stable specification found!" if commit_formula_spec.blank?

  formula_pr_message = ""

  new_url = args.url
  new_version = args.version

  check_new_version(commit_formula, tap_remote_repo, version: new_version) if new_version.present?

  if commit_formula.resources.any? { |resource| !resource.name.start_with?("homebrew-") }
    opoo "This formula has resources that may need to be updated."
  end

  old_mirrors = commit_formula_spec.mirrors
  new_mirrors ||= args.mirror
  if new_url.present? && (new_mirror = determine_mirror(new_url))
    new_mirrors ||= [new_mirror]
    check_for_mirrors(commit_formula.name, old_mirrors, new_mirrors)
  end

  new_hash = args.sha256
  new_tag = args.tag
  new_revision = args.revision
  old_url = commit_formula_spec.url
  odie "#{commit_formula}: no stable URL found!" if old_url.nil?
  old_tag = commit_formula_spec.specs[:tag]
  old_formula_version = formula_version(commit_formula)
  old_version = old_formula_version.to_s
  forced_version = new_version.present?
  new_url_hash = if new_url.present? && new_hash.present?
    check_new_version(commit_formula, tap_remote_repo, url: new_url) if new_version.blank?
    true
  elsif new_tag.present? && new_revision.present?
    check_new_version(commit_formula, tap_remote_repo, url: old_url, tag: new_tag) if new_version.blank?
    false
  elsif commit_formula_spec.checksum&.hexdigest.blank?
    if new_tag.blank? && new_version.blank? && new_revision.blank?
      raise UsageError, "#{formula}: no `--tag` or `--version` argument specified!"
    end

    if old_tag.present?
      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
      check_new_version(commit_formula, tap_remote_repo, url: old_url, tag: new_tag) if new_version.blank?
      resource_path, forced_version = fetch_resource_and_forced_version(commit_formula, new_version, old_url,
                                                                        tag: new_tag)
      new_revision = Utils.popen_read("git", "-C", resource_path.to_s, "rev-parse", "-q", "--verify",
                                      "HEAD").strip
    elsif new_revision.blank?
      odie "#{commit_formula}: the current URL requires specifying a `--revision=` argument."
    end
    false
  elsif new_url.blank? && new_version.blank?
    raise UsageError, "#{commit_formula}: no `--url` or `--version` argument specified!"
  else
    new_url ||= PyPI.update_pypi_url(old_url, new_version) if new_version.present?

    if new_url.blank? && new_version.present?
      new_url = update_url(old_url, old_version, new_version)
      if new_mirrors.blank? && old_mirrors.present?
        new_mirrors = old_mirrors.map do |old_mirror|
          update_url(old_mirror, old_version, new_version)
        end
      end
    end
    if new_url == old_url
      odie <<~EOS
        You need to bump this formula manually since the new URL
        and old URL are both:
          #{new_url}
      EOS
    end
    if new_url.blank?
      odie "There was an issue generating the updated url, you may need to create the PR manually"
    end
    check_new_version(commit_formula, tap_remote_repo, url: new_url) if new_version.blank?
    resource_path, forced_version = fetch_resource_and_forced_version(commit_formula, new_version, new_url)
    Utils::Tar.validate_file(resource_path)
    new_hash = resource_path.sha256
  end

  old_contents = commit_formula.path.read
  formula_ast = Utils::AST::FormulaAST.new(old_contents)

  formula_ast.remove_stanza(:revision) if commit_formula.revision.nonzero?
  formula_ast.remove_stable_stanzas(:mirror) if commit_formula_spec.mirrors.present?

  if new_url_hash.present?
    odie "#{commit_formula}: no new URL found!" if new_url.nil?

    formula_ast.replace_stable_stanza_value(:url, new_url)
    formula_ast.replace_stable_stanza_value(:sha256, new_hash)
  else
    odie "#{commit_formula}: no new revision found!" if new_revision.nil?

    if new_tag.present?
      formula_ast.replace_stable_stanza_hash_value(:url, :tag, new_tag)
    elsif new_url.present?
      formula_ast.replace_stable_stanza_value(:url, new_url)
    end
    formula_ast.replace_stable_stanza_hash_value(:url, :revision, new_revision)
  end

  stanzas_to_add = []
  new_mirrors&.each { |mirror| stanzas_to_add << [:mirror, "mirror #{mirror.inspect}"] } if new_url.present?
  if forced_version && new_version && new_version != "0"
    if formula_ast.stable_stanza?(:version)
      formula_ast.replace_stable_stanza_value(:version, new_version)
    else
      stanzas_to_add << [:version, "version #{new_version.inspect}"]
    end
  elsif forced_version && new_version == "0"
    formula_ast.remove_stable_stanza(:version) if formula_ast.stable_stanza?(:version)
  end
  formula_ast.add_stable_stanzas_after(:url, stanzas_to_add) if stanzas_to_add.present?
  new_contents = formula_ast.process

  new_formula_version = formula_version(commit_formula, new_contents)

  if new_formula_version < old_formula_version
    odie <<~EOS
      You need to bump this formula manually since changing the version
      from #{old_formula_version} to #{new_formula_version} would be a downgrade.
    EOS
  elsif new_formula_version == old_formula_version
    odie <<~EOS
      You need to bump this formula manually since the new version
      and old version are both #{new_formula_version}.
    EOS
  end

  unless patch_source_ambiguous?(formula_ast)
    formula_ast.remove_patches do |patch_node|
      patches_for_removal(patch_node) do |patch_urls|
        reasons = patch_urls.to_h do |patch_url|
          [patch_url, patch_inclusion.removal_reason(patch_url, source_url: new_url || old_url,
                                                              tag: new_tag, revision: new_revision)]
        end
        next false if reasons.value?(nil)

        reasons.each do |patch_url, reason|
          ohai "#{args.dry_run? ? "Would remove" : "Removing"} patch: #{patch_url}"
          puts reason
          formula_pr_message += "\n\n#{reason}"
        end
        true
      end
    end
    new_contents = formula_ast.process
  end
  commit_formula.path.atomic_write(new_contents) unless args.dry_run?

  formula_checkboxes = []

  if Utils::AST::FormulaAST.new(new_contents).contains_call?(:patch)
    opoo "This formula has patches that may be resolved upstream."
    formula_checkboxes << "- [ ] `patch` blocks have been checked."
  end

  alias_rename = alias_update_pair(commit_formula, new_formula_version)
  ohai "Renaming alias #{alias_rename.first} to #{alias_rename.last}" if alias_rename.present?

  formula_checkboxes.concat(resource_checkboxes(commit_formula, new_contents, new_formula_version))

  if formula_checkboxes.present?
    formula_pr_message += <<~EOS


      #{formula_checkboxes.join("\n")}
    EOS
  end

  formula_pr_message += github_release_notes(new_url, added_release_info)

  PreparedBump.new(
    sourcefile_path:    commit_formula.path,
    old_contents:,
    commit_message:     "#{commit_formula.name} #{new_formula_version}",
    additional_files:   alias_rename&.map { |name| tap.alias_dir/name },
    formula_pr_message:,
    formula_name:       commit_formula.full_name,
    new_version:        new_formula_version,
  )
end

#resource_checkboxes(commit_formula, new_contents, new_formula_version) ⇒ Array<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Update resources and identify changes requiring manual review.

Parameters:

Returns:



469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
# File 'dev-cmd/bump-formula-pr.rb', line 469

def resource_checkboxes(commit_formula, new_contents, new_formula_version)
  formula_checkboxes = []
  resource_update_results = {}
  unless args.dry_run?
    resources_checked = PyPI.update_python_resources! reload_formula(commit_formula, new_contents),
                                                      version:                  new_formula_version.to_s,
                                                      package_name:             args.python_package_name,
                                                      extra_packages:           args.python_extra_packages,
                                                      exclude_packages:         args.python_exclude_packages,
                                                      install_dependencies:     args.install_dependencies?,
                                                      quiet:                    args.quiet?,
                                                      ignore_non_pypi_packages: true

    resource_versions = parse_resource_versions_arg
    resource_update_results.merge!(
      update_matching_version_resources!(commit_formula,
                                         version:           new_formula_version.to_s,
                                         resource_versions:),
    )

    if resource_versions.present?
      resource_update_results.merge!(
        update_resources!(commit_formula, resource_versions:),
      )
    end
  end

  checked_statuses = [:success, :up_to_date, :downgraded]
  failed_updates = resource_update_results.reject { |_, v| checked_statuses.include?(v) }
  downgraded_resources = resource_update_results.select { |_, v| v == :downgraded }

  # Check if there are any resources that still need manual update:
  unchecked_resources = commit_formula.resources.select do |resource|
    next false if resource.name.start_with?("homebrew-")
    next false if resource_update_results.key?(resource.name)
    next false if resource.livecheck.formula == :parent

    true
  end

  if failed_updates.any? || (!resources_checked && unchecked_resources.any?)
    formula_checkboxes << "- [ ] `resource` blocks have been checked for updates."

    if failed_updates.any?
      formula_checkboxes << "#{failed_updates.map do |name, status|
        "  - Resource `#{name}` failed to auto-update (#{status})."
      end.join("\n")}\n"
    end
  end

  if downgraded_resources.any?
    resource_names = downgraded_resources.keys.map { |name| "`#{name}`" }.join(", ")
    verb = (downgraded_resources.size == 1) ? "was" : "were"
    formula_checkboxes <<
      "**Warning:** #{resource_names} #{verb} " \
      "downgraded to match the latest upstream version."
  end

  annotation_comments = %w[TODO FIXME]
  if annotation_comments.any? { |s| new_contents.include?("#{s}:") }
    formula_checkboxes << "- [ ] TODO and FIXME comments have been checked."
  end

  formula_checkboxes
end

#run ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'dev-cmd/bump-formula-pr.rb', line 112

def run
  Utils::GemSetup.install_bundler_gems!(groups: ["ast"])
  require "utils/ast"
  require "utils/pypi"

  if args.revision.present? && args.tag.nil? && args.version.nil?
    raise UsageError, "`--revision` must be passed with either `--tag` or `--version`!"
  end

  # As this command is simplifying user-run commands then let's just use a
  # user path, too.
  ENV["PATH"] = PATH.new(ORIGINAL_PATHS).to_s

  # Use the user's browser, too.
  ENV["BROWSER"] = Homebrew::EnvConfig.browser

  @tap_retried = T.let(false, T.nilable(T::Boolean))
  begin
    formula = args.named.to_formulae.first
    raise FormulaUnspecifiedError if formula.blank?

    raise ArgumentError, "This formula is disabled!" if DeprecateDisable.disabled_on_all_platforms?(formula)
    if formula.deprecation_reason == :does_not_build
      raise ArgumentError, "This formula is deprecated and does not build!"
    end

    tap = formula.tap
    raise ArgumentError, "This formula is not in a tap!" if tap.blank?
    raise ArgumentError, "This formula's tap is not a Git repository!" unless tap.git?
  rescue ArgumentError => e
    odie e.message if @tap_retried

    CoreTap.instance.install(force: true)
    @tap_retried = true
    retry
  end

  odie <<~EOS unless tap.allow_bump?(formula.name)
    Whoops, the #{formula.name} formula has its version update
    pull requests automatically opened by BrewTestBot every ~3 hours!
    We'd still love your contributions, though, so try another one
    that is excluded from autobump list (i.e. it has 'no_autobump!'
    method or 'livecheck' block with 'skip'.)
  EOS

  if !args.write_only? && GitHub.too_many_open_prs?(tap)
    odie "You have too many PRs open: close or merge some first!"
  end

  formula_spec = formula.stable
  odie "#{formula}: no stable specification found!" if formula_spec.blank?

  # This will be run by `brew audit` later so run it first to not start
  # spamming during normal output.
  Utils::GemSetup.install_bundler_gems!(groups: ["audit", "style"]) unless args.no_audit?

  tap_remote_repo = tap.remote_repository
  odie "#{tap.name} tap does not have a remote repository!" if tap_remote_repo.nil?

  check_pull_requests(formula, tap_remote_repo, state: "open") unless args.write_only?

  all_formulae = []
  if args.bump_synced.present?
    Array(args.bump_synced).each do |formula_name|
      all_formulae << formula_name
    end
  else
    all_formulae << args.named.first.to_s
  end

  return if all_formulae.empty?

  added_release_info = Set.new
  patch_inclusion = GitHub::PatchInclusion.new

  commits = all_formulae.map do |formula_name|
    prepare_formula_bump(formula_name, formula, tap, tap_remote_repo, added_release_info, patch_inclusion)
  end

  completed_alias_moves = T.let([], T::Array[T::Array[Pathname]])
  commits.each do |commit|
    commit_formula = Formula[commit.formula_name]
    # For each formula, run `brew audit` to check for any issues.
    audit_result = run_audit(commit_formula, commit.additional_files,
                             skip_synced_versions: args.bump_synced.present?)
    if !args.dry_run? && (alias_rename = commit.additional_files)
      completed_alias_moves << alias_rename
    end

    next unless audit_result

    # If `brew audit` fails, revert the changes made to any formula.
    if !args.dry_run? && !args.write_only?
      commits.each { |revert| revert.sourcefile_path.atomic_write(revert.old_contents) }
      completed_alias_moves.reverse_each do |alias_rename|
        if (source = alias_rename.first) && (destination = alias_rename.last)
          FileUtils.mv destination, source
        end
      end
    end

    odie "`brew audit` failed for #{commit.formula_name}!"
  end

  new_formula_version = commits.fetch(0).new_version

  pr_title = if args.bump_synced.nil?
    "#{formula.name} #{new_formula_version}"
  else
    maximum_characters_in_title = 72
    max = maximum_characters_in_title - new_formula_version.to_s.length - 1
    "#{Formatter.truncate(Array(args.bump_synced).join(" "), max:)} #{new_formula_version}"
  end

  pr_message = Homebrew::Bump.pr_message("bump-formula-pr", user_message: args.message)
  commits.each do |commit|
    next if commit.formula_pr_message.empty?

    pr_message += "<h4>#{commit.formula_name}</h4>" if commits.length != 1
    pr_message += "#{commit.formula_pr_message}<hr>"
  end

  return if args.write_only? && !args.commit?

  url = Homebrew::Bump.create_pr(
    Homebrew::Bump::BumpInfo.new(
      package_tap: tap,
      branch_name: "bump-#{formula.name}-#{new_formula_version}",
      pr_title:,
      pr_message:,
      commits:     commits.map do |commit|
        Homebrew::Bump::Commit.new(
          sourcefile_path:  commit.sourcefile_path,
          old_contents:     commit.old_contents,
          commit_message:   commit.commit_message,
          additional_files: commit.additional_files || [],
        )
      end,
    ),
    dry_run:  args.dry_run?,
    no_fork:  args.no_fork? || args.write_only?,
    fork_org: args.fork_org,
    commit:   args.commit?,
  )
  return if url.blank?

  if args.no_browse?
    puts url
  else
    Utils::Browser.open url
  end
end

#update_matching_version_resources!(formula, version:, resource_versions: nil) ⇒ Hash{String => Symbol}

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



676
677
678
679
680
681
# File 'dev-cmd/bump-formula-pr.rb', line 676

def update_matching_version_resources!(formula, version:, resource_versions: nil)
  resource_versions ||= {}
  formula.resources
         .select { |r| r.livecheck.formula == :parent && resource_versions[r.name].blank? }
         .to_h { |resource| [resource.name, update_resource_block!(formula, resource, version)] }
end

#update_resources!(formula, resource_versions:) ⇒ Hash{String => Symbol}

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
# File 'dev-cmd/bump-formula-pr.rb', line 689

def update_resources!(formula, resource_versions:)
  results = {}

  formula.resources.each do |resource|
    version_data = resource_versions[resource.name]
    next if version_data.blank?

    current_version = version_data[:current_version]
    latest_version = version_data[:latest_version]

    if current_version.blank? || latest_version.blank?
      opoo "Could not determine versions for resource \"#{resource.name}\""
      results[resource.name] = :version_unknown
      next
    end

    if current_version == latest_version
      results[resource.name] = :up_to_date
      next
    end

    is_downgraded = Version.new(current_version) > Version.new(latest_version)
    is_downgraded &&= current_version != resource.specs[:revision]

    begin
      result = update_resource_block!(formula, resource, latest_version)
      results[resource.name] = if result == :success && is_downgraded
        :downgraded
      else
        result
      end
    rescue => e
      opoo "Failed to update resource \"#{resource.name}\": #{e}"
      results[resource.name] = :fetch_failed
    end
  end

  results
end