Skip to content
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

[fix] drop old code made for ruby < 2.6 #21878

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion deliver/lib/deliver/download_screenshots.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative 'module'
require 'spaceship'
require 'open-uri'

module Deliver
class DownloadScreenshots
Expand Down Expand Up @@ -67,7 +68,7 @@ def self.download_screenshots(folder_path, localization)
end

path = File.join(containing_folder, file_name)
File.binwrite(path, FastlaneCore::Helper.open_uri(url).read)
File.binwrite(path, URI.open(url).read)
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion fastlane/actions/plugin_scores.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ def self.run(params)
end

def self.fetch_plugins(cache_path)
require 'open-uri'
page = 1
plugins = []
loop do
url = "https://rubygems.org/api/v1/search.json?query=fastlane-plugin-&page=#{page}"
puts("RubyGems API Request: #{url}")
results = JSON.parse(FastlaneCore::Helper.open_uri(url).read)
results = JSON.parse(URI.open(url).read)
break if results.count == 0

plugins += results.collect do |current|
Expand Down
3 changes: 2 additions & 1 deletion fastlane/lib/fastlane/actions/update_project_provisioning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ def self.run(params)
# download certificate
unless File.exist?(params[:certificate]) && File.size(params[:certificate]) > 0
UI.message("Downloading root certificate from (#{ROOT_CERTIFICATE_URL}) to path '#{params[:certificate]}'")
require 'open-uri'
File.open(params[:certificate], "w:ASCII-8BIT") do |file|
file.write(FastlaneCore::Helper.open_uri(ROOT_CERTIFICATE_URL, "rb").read)
file.write(URI.open(ROOT_CERTIFICATE_URL, "rb").read)
end
end

Expand Down
3 changes: 2 additions & 1 deletion fastlane/lib/fastlane/plugins/plugin_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ class PluginFetcher
# Returns an array of FastlanePlugin objects
def self.fetch_gems(search_query: nil)
require 'json'
require 'open-uri'

page = 1
plugins = []
loop do
url = "https://rubygems.org/api/v1/search.json?query=#{PluginManager.plugin_prefix}&page=#{page}"
FastlaneCore::UI.verbose("RubyGems API Request: #{url}")
results = JSON.parse(FastlaneCore::Helper.open_uri(url).read)
results = JSON.parse(URI.open(url).read)
break if results.count == 0

plugins += results.collect do |current|
Expand Down
3 changes: 2 additions & 1 deletion fastlane/lib/fastlane/plugins/plugin_info_collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ def plugin_name_valid?(name)
# Checks if the gem name is still free on RubyGems
def gem_name_taken?(name)
require 'json'
require 'open-uri'
url = "https://rubygems.org/api/v1/gems/#{name}.json"
response = JSON.parse(FastlaneCore::Helper.open_uri(url).read)
response = JSON.parse(URI.open(url).read)
return !!response['version']
rescue
false
Expand Down
3 changes: 2 additions & 1 deletion fastlane/lib/fastlane/plugins/plugin_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ def attach_plugins_to_gemfile!(path_to_gemfile)

def self.fetch_gem_info_from_rubygems(gem_name)
require 'json'
require 'open-uri'
url = "https://rubygems.org/api/v1/gems/#{gem_name}.json"
begin
JSON.parse(FastlaneCore::Helper.open_uri(url).read)
JSON.parse(URI.open(url).read)
rescue
nil
end
Expand Down
15 changes: 0 additions & 15 deletions fastlane_core/lib/fastlane_core/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -482,20 +482,5 @@ def self.ask_password(message: "Passphrase: ", confirm: nil, confirmation_messag
UI.error("Your entries do not match. Please try again")
end
end

# URI.open added by `require 'open-uri'` is not available in Ruby 2.4. This helper lets you open a URI
# by choosing appropriate interface to do so depending on Ruby version. This helper is subject to be removed
# when fastlane drops Ruby 2.4 support.
def self.open_uri(*rest, &block)
require 'open-uri'

if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.5')
dup = rest.dup
uri = dup.shift
URI.parse(uri).open(*dup, &block)
else
URI.open(*rest, &block)
end
end
end
end
4 changes: 0 additions & 4 deletions fastlane_core/lib/fastlane_core/ui/fastlane_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,6 @@ def suggest_ruby_reinstall(e)
ui.error(e.to_s)
ui.error("")
ui.error("SSL errors can be caused by various components on your local machine.")
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.1')
ui.error("Apple has recently changed their servers to require TLS 1.2, which may")
ui.error("not be available to your system installed Ruby (#{RUBY_VERSION})")
end
ui.error("")
ui.error("The best solution is to use the self-contained fastlane version.")
ui.error("Which ships with a bundled OpenSSL,ruby and all gems - so you don't depend on system libraries")
Expand Down
6 changes: 1 addition & 5 deletions fastlane_core/lib/fastlane_core/ui/help_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ def template(name)
# fastlane only customizes the global command help
return super unless name == :help

if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.6')
ERB.new(File.read(File.join(File.dirname(__FILE__), "help.erb")), nil, '-')
else
ERB.new(File.read(File.join(File.dirname(__FILE__), "help.erb")), trim_mode: '-')
end
ERB.new(File.read(File.join(File.dirname(__FILE__), "help.erb")), trim_mode: '-')
end
end
end
32 changes: 0 additions & 32 deletions fastlane_core/spec/helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,37 +230,5 @@
expect(FastlaneCore::Helper.fastlane_enabled?).to be(true)
end
end

describe '#open_uri' do
before do
stub_request(:get, 'https://fastlane.tools').to_return(body: 'SOME_TEXT', status: 200)
end

it 'performs URI.open and return IO like object that can be read' do
expect(FastlaneCore::Helper.open_uri('https://fastlane.tools')).to respond_to(:read)
end

it 'performs URI.open with block' do
is_block_called = false
FastlaneCore::Helper.open_uri('https://fastlane.tools') do |content|
expect(content).to respond_to(:read)
is_block_called = true
end
expect(is_block_called).to be(true)
end

it 'performs URI.open with options' do
expect(FastlaneCore::Helper.open_uri('https://fastlane.tools', 'rb')).to respond_to(:read)
end

it 'performs URI.open with options and block' do
is_block_called = false
FastlaneCore::Helper.open_uri('https://fastlane.tools', 'rb') do |content|
expect(content).to respond_to(:read)
is_block_called = true
end
expect(is_block_called).to be(true)
end
end
end
end