Skip to content

Commit

Permalink
Split audit_synced_versions_formulae checks into reusable methods
Browse files Browse the repository at this point in the history
- This way we can use them in the audit and in `bump`.
  • Loading branch information
issyl0 committed Jan 23, 2024
1 parent c7ed62a commit be25e20
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
26 changes: 10 additions & 16 deletions Library/Homebrew/dev-cmd/bump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,14 @@ def retrieve_and_display_info_and_open_pr(formula_or_cask, name, repositories, a
Latest livecheck version: #{new_versions}
Latest Repology version: #{repology_latest}
EOS
puts <<~EOS if synced_with_other_formulae?(formula_or_cask)
if formula_or_cask.is_a?(Formula)
require "formula_auditor"
auditor = FormulaAuditor.new(formula_or_cask)
puts <<~EOS if T.must(auditor).synced_with_other_formulae?
Version syncing: #{title_name} version should be kept in sync with
#{synced_with(T.cast(formula_or_cask, Formula), new_version.general).join(", ")}.
EOS
#{synced_with(T.must(auditor), formula_or_cask, new_version.general).join(", ")}.
EOS
end
puts <<~EOS unless args.no_pull_requests?
Open pull requests: #{open_pull_requests || "none"}
Closed pull requests: #{closed_pull_requests || "none"}
Expand Down Expand Up @@ -502,27 +506,17 @@ def retrieve_and_display_info_and_open_pr(formula_or_cask, name, repositories, a
system HOMEBREW_BREW_FILE, *bump_cask_pr_args
end

sig { params(formula_or_cask: T.any(Formula, Cask::Cask)).returns(T::Boolean) }
def synced_with_other_formulae?(formula_or_cask)
return false if formula_or_cask.is_a?(Cask)

synced_versions_formulae_file = "#{formula_or_cask.tap.path}/synced_versions_formulae.json"
return false unless File.exist?(synced_versions_formulae_file)

synced_versions_formulae = JSON.parse(File.read(synced_versions_formulae_file))
synced_versions_formulae.any? { |synced_formulae| synced_formulae.include?(formula_or_cask.name) }
end

sig {
params(
auditor: FormulaAuditor,
formula: Formula,
new_version: T.nilable(T.any(Version, Cask::DSL::Version)),
).returns(T::Array[String])
}
def synced_with(formula, new_version)
def synced_with(auditor, formula, new_version)
synced_with = []

JSON.parse(File.read("#{T.must(formula.tap).path}/synced_versions_formulae.json")).each do |synced_formulae|
auditor.synced_versions_formulae_json.each do |synced_formulae|
next unless synced_formulae.include?(formula.name)

synced_formulae.each do |synced_formula|
Expand Down
22 changes: 15 additions & 7 deletions Library/Homebrew/formula_auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,28 @@ def self.aliases
@aliases ||= Formula.aliases + Formula.tap_aliases
end

SYNCED_VERSIONS_FORMULAE_FILE = "synced_versions_formulae.json"
def synced_versions_formulae_json
@synced_versions_formulae_json ||= JSON.parse(File.read("#{formula.tap.path}/synced_versions_formulae.json"))
end

def synced_with_other_formulae?
return false unless formula.tap

synced_versions_formulae_file = "#{formula.tap.path}/synced_versions_formulae.json"
return false unless File.exist?(synced_versions_formulae_file)

synced_versions_formulae_json.any? { |synced_version_formulae| synced_version_formulae.include?(formula.name) }
end

def audit_synced_versions_formulae
return unless formula.tap

synced_versions_formulae_file = formula.tap.path/SYNCED_VERSIONS_FORMULAE_FILE
return unless synced_versions_formulae_file.file?
return unless synced_with_other_formulae?

name = formula.name
version = formula.version

synced_versions_formulae = JSON.parse(synced_versions_formulae_file.read)
synced_versions_formulae.each do |synced_version_formulae|
next unless synced_version_formulae.include? name
synced_versions_formulae_json.each do |synced_version_formulae|
next unless synced_version_formulae.include?(name)

synced_version_formulae.each do |synced_formula|
next if synced_formula == name
Expand Down

0 comments on commit be25e20

Please sign in to comment.