Skip to content

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

Merged
merged 8 commits into from
Apr 27, 2023

Conversation

spencertransier
Copy link
Contributor

@spencertransier spencertransier commented Apr 26, 2023

What does it do?

This PR replaces all instances of the deprecated is_string with the appropriate type in Fastlane ConfigItem'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 for type: Boolean, there are dozens of examples where type: Boolean was accepted and merged in. I went ahead and used type: 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

  • Run bundle exec rubocop to test for code style violations and recommendations
  • Add Unit Tests (aka specs/*_spec.rb) if applicable
  • Run bundle exec rspec to run the whole test suite and ensure all your tests pass
  • Make sure you added an entry in the CHANGELOG.md file to describe your changes under the approprioate existing ### subsection of the existing ## Trunk section.

@spencertransier spencertransier changed the title Update/is string to type Replace all instances of is_string with type Apr 26, 2023
@spencertransier spencertransier requested a review from a team April 26, 2023 23:00
@spencertransier spencertransier marked this pull request as ready for review April 26, 2023 23:23
Copy link
Contributor

@AliSoftware AliSoftware left a 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 :shipit:

@spencertransier spencertransier merged commit 3ee6cd7 into trunk Apr 27, 2023
@spencertransier spencertransier deleted the update/is_string-to-type branch April 27, 2023 14:13
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),
Copy link
Contributor

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.

Copy link
Contributor

@AliSoftware AliSoftware May 12, 2023

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 a Hash (e.g. {'fr'=>'fr-FR', 'de'=>'de-DE', 'en'=>'en-US'}, then iterating over that Hash yields elements that each are 2-item arrays of the form [key, value] (e.g. ['fr', 'fr-FR']). We thus then falls into the if 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 an Array, then it can be either an Array of Strings (['fr', 'de', 'en']) and fall into the if loc.is_a?(String) branch inside the loop… or be an Array of 2-element-Arrays ([['fr', 'fr-FR'], ['de', 'de-DE'], ['en', 'en-US']) and fall into the if 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).

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Address the use of the legacy api of ConfigItem constructor (aka is_string vs type).
3 participants