-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor rename/migration handling in Formulary
.
#16595
Refactor rename/migration handling in Formulary
.
#16595
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me but would like to see ✅ from @Bo98 and/or @apainintheneck as they've been working here recently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me. From what I can tell Formulary.loader_for
doesn't have [m]any tests but the loader code should be tested pretty well indirectly through all of the Formulary.factory
tests so I'm not too worried about this change.
def self.tap_formula_name_path(tapped_name, warn:) | ||
def self.tap_formula_name_type(tapped_name, warn:) | ||
user, repo, name = tapped_name.split("/", 3).map(&:downcase) | ||
tap = Tap.fetch user, repo | ||
path = Formulary.find_formula_in_tap(name, tap) | ||
|
||
unless path.file? | ||
if (possible_alias = tap.alias_dir/name).file? | ||
path = possible_alias.resolved_path | ||
name = path.basename(".rb").to_s | ||
elsif (new_name = tap.formula_renames[name].presence) && | ||
(new_path = Formulary.find_formula_in_tap(new_name, tap)).file? | ||
old_name = name | ||
path = new_path | ||
name = new_name | ||
new_name = tap.core_tap? ? name : "#{tap}/#{name}" | ||
elsif (new_tap_name = tap.tap_migrations[name].presence) | ||
new_tap_user, new_tap_repo, = new_tap_name.split("/") | ||
new_tap_name = "#{new_tap_user}/#{new_tap_repo}" | ||
new_tap = Tap.fetch new_tap_name | ||
new_tap.ensure_installed! | ||
new_tapped_name = "#{new_tap_name}/#{name}" | ||
name, path, tap = Formulary.tap_formula_name_path(new_tapped_name, warn: false) | ||
old_name = tapped_name | ||
new_name = new_tap.core_tap? ? name : new_tapped_name | ||
end | ||
|
||
opoo "Formula #{old_name} was renamed to #{new_name}." if warn && old_name && new_name | ||
type = nil | ||
|
||
if (possible_alias = tap.alias_table[name].presence) | ||
name = possible_alias | ||
type = :alias | ||
elsif (new_name = tap.formula_renames[name].presence) | ||
old_name = name | ||
name = new_name | ||
new_name = tap.core_tap? ? name : "#{tap}/#{name}" | ||
type = :rename | ||
elsif (new_tap_name = tap.tap_migrations[name].presence) | ||
new_tap_user, new_tap_repo, = new_tap_name.split("/") | ||
new_tap_name = "#{new_tap_user}/#{new_tap_repo}" | ||
new_tap = Tap.fetch new_tap_name | ||
new_tap.ensure_installed! | ||
new_tapped_name = "#{new_tap_name}/#{name}" | ||
name, tap, = Formulary.tap_formula_name_type(new_tapped_name, warn: false) | ||
old_name = tapped_name | ||
new_name = new_tap.core_tap? ? name : new_tapped_name | ||
type = :migration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, previously it would just skip all this if the formula path exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the attention and fix here, @apainintheneck @reitermarkus 🥰
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@reitermarkus @apainintheneck @dduugg Should we revert this PR given #16628 is still open?
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?Merge most of the code paths for loading with/without API. Instead of checking if the renamed/alias file exists, we simply assume so, as the end result is an error anyways if it doesn't.