-
Notifications
You must be signed in to change notification settings - Fork 9
Replace all instances of is_string
with type
#469
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
Conversation
is_string
with type
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.
Nice work and cleanup! ❤️
Left a couple of side-notes for some typos that we could consider fixing in the ConfigItem's descriptions while at it, but otherwise
lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_validate_lib_strings_action.rb
Outdated
Show resolved
Hide resolved
lib/fastlane/plugin/wpmreleasetoolkit/actions/common/setfrozentag_action.rb
Outdated
Show resolved
Hide resolved
lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_bump_version_hotfix.rb
Show resolved
Hide resolved
FastlaneCore::ConfigItem.new(key: :locales, | ||
env_name: 'FL_DOWNLOAD_METADATA_LOCALES', | ||
description: 'The hash with the GlotPress locale and the project locale association', | ||
is_string: false), | ||
type: Hash), |
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.
@spencertransier @AliSoftware Is this the correct type for this item? According to this we are checking if it's an Array
or a String
. I've also checked the locales parameter we are passing from WPAndroid and Ruby is telling me that it's an Array
.
I was trying to test the auto-retry downloading metadata strings PR and I've hit an issue where fastlane
is telling me that 'locales' value must be a Hash! Found Array instead
. I thought it was something I was doing wrong, but I think this change is the culprit.
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.
Ah, this is confusing indeed!
According to this we are checking if it's an Array or a String.
The params[:locales]
is expected to be an Enumerable
, on which we call params[:locales].each do |loc| …
to iterate over each loc
element. And those individual array elements are what we check for them to be an Array
or a String
.
In practice:
- if
params[:locales]
is aHash
(e.g.{'fr'=>'fr-FR', 'de'=>'de-DE', 'en'=>'en-US'}
, then iterating over thatHash
yields elements that each are 2-item arrays of the form[key, value]
(e.g.['fr', 'fr-FR']
). We thus then falls into theif loc.is_a?(Array)
branch inside the loop.irb> {'fr'=>'fr-FR', 'de'=>'de-DE'}.each { |loc| puts loc.inspect } ["fr", "fr-FR"] ["de", "de-DE"]
- if
params[:locales]
is anArray
, then it can be either anArray
ofStrings
(['fr', 'de', 'en']
) and fall into theif loc.is_a?(String)
branch inside the loop… or be anArray
of 2-element-Arrays ([['fr', 'fr-FR'], ['de', 'de-DE'], ['en', 'en-US']
) and fall into theif loc.is_a?(Array)
branch.
So in reality, this parameter can be either a Hash
or an Array<String>
or an Array<[String,String]>
(the latter being what WPAndroid uses) 😓
I think down the line our long term plan was to replace this legacy gp_download_metadata
with a more modern API, including because of this odd API around the parameters like locales
here. But until then we're stuck with this API that is a bit confusing and too flexible to be consistent.
I guess the best option here would be to set type: Enumerable
and better document the parameter in the description
. That being said, I've never seen type: Enumerable
being used for a ConfigItem
(as it's more common to provide explicit types), so we better test that this more generic type would work and be supported by ConfigItem
's implementation. So I guess this would be the ideal time to write some specs for that action (even minimalistic ones for now, that would only focus on feeding different type of inputs for this parameter) to ensure type: Enumerable
would work as expected (or what would need to be used instead if not).
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.
Could we temporarily revert the change and open a separate issue for this? Since it's a breaking issue we need to address it immediately and I unfortunately don't have the bandwidth to handle it properly.
I could also test if type: Enumerable
works for WPAndroid and handle the hotfix and the releases if that's good enough for now.
cc @spencertransier In case you have more availability to follow up on this better than I can.
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.
@oguzkocer I'll revert it and get the 7.1.2 release going.
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.
Created separate issue for this here: #484
What does it do?
This PR replaces all instances of the deprecated
is_string
with the appropriatetype
in FastlaneConfigItem
's.According to the Fastlane documentation,
type: Boolean
shouldn't be used because "Ruby does not have a single class to represent a Boolean type". However, if you search the Fastlane PRs fortype: Boolean
, there are dozens of examples wheretype: Boolean
was accepted and merged in. I went ahead and usedtype: Boolean
in this PR for consistency and clarity.A few of these had already been replaced in #425 (search for
is_string
), but I decided to replicate those changes here since that fork hasn't been merged in yet and it's been nearly 6 months.Fixes #278
Checklist before requesting a review
bundle exec rubocop
to test for code style violations and recommendationsspecs/*_spec.rb
) if applicablebundle exec rspec
to run the whole test suite and ensure all your tests passCHANGELOG.md
file to describe your changes under the approprioate existing###
subsection of the existing## Trunk
section.