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] remove dependency on unmaintained rest-client library #21898

Merged
merged 4 commits into from
Feb 29, 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
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ gem "danger-junit", "~> 1.0"
# A fake filesystem.
# Version 1.9+ requires Ruby >=2.7, while fastlane uses a `required_ruby_version` of `>= 2.6`.
gem "fakefs", "1.8"
# for file uploads with Faraday
gem "mime-types", ['>= 1.16', '< 4.0']
# Fast XML parser and object marshaller.
gem "ox", "2.13.2"
# Provides an interactive debugging environment for Ruby.
Expand All @@ -31,8 +33,6 @@ gem "rake"
# A readline implementation in Ruby
# See: https://github.com/deivid-rodriguez/byebug/issues/289#issuecomment-251383465
gem "rb-readline"
# A simple and flexible REST client.
gem "rest-client", ">= 1.8.0"
# Behavior-driven testing tool for Ruby.
gem "rspec", "~> 3.10"
# Formatter for RSpec to generate JUnit compatible reports.
Expand Down
13 changes: 3 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ GEM
signet (>= 0.16, < 2.a)
hashdiff (1.0.1)
highline (2.0.3)
http-accept (1.7.0)
http-cookie (1.0.5)
domain_name (~> 0.5)
httpclient (2.8.3)
Expand All @@ -198,9 +197,9 @@ GEM
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
method_source (1.0.0)
mime-types (3.3.1)
mime-types (3.5.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2021.0225)
mime-types-data (3.2024.0206)
mini_magick (4.12.0)
mini_mime (1.1.5)
multi_json (1.15.0)
Expand All @@ -210,7 +209,6 @@ GEM
nanaimo (0.3.0)
nap (1.1.0)
naturally (2.2.1)
netrc (0.11.0)
no_proxy_fix (0.1.2)
octokit (4.25.1)
faraday (>= 1, < 3)
Expand Down Expand Up @@ -250,11 +248,6 @@ GEM
declarative (< 0.1.0)
trailblazer-option (>= 0.1.1, < 0.2.0)
uber (< 0.2.0)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
retriable (3.1.2)
rexml (3.2.6)
rouge (2.0.7)
Expand Down Expand Up @@ -377,14 +370,14 @@ DEPENDENCIES
fastlane-plugin-clubmate
fastlane-plugin-ruby
fastlane-plugin-slack_train (>= 0.2.0)
mime-types (>= 1.16, < 4.0)
ox (= 2.13.2)
pry
pry-byebug
pry-rescue
pry-stack_explorer
rake
rb-readline
rest-client (>= 1.8.0)
rspec (~> 3.10)
rspec_junit_formatter (~> 0.4.1)
rubocop (= 1.50.2)
Expand Down
38 changes: 30 additions & 8 deletions fastlane/lib/fastlane/actions/mailgun.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ def self.is_supported?(platform)
end

def self.run(options)
Actions.verify_gem!('rest-client')
require 'rest-client'
Actions.verify_gem!('faraday')
Actions.verify_gem!('mime-types')
require 'faraday'
begin
# Use mime/types/columnar if available, for reduced memory usage
require 'mime/types/columnar'
rescue LoadError
require 'mime/types'
end
handle_params_transition(options)
mailgunit(options)
end
Expand Down Expand Up @@ -101,11 +108,15 @@ def self.author
end

def self.handle_params_transition(options)
options[:postmaster] = options[:mailgun_sandbox_postmaster] if options[:mailgun_sandbox_postmaster]
puts("\nUsing :mailgun_sandbox_postmaster is deprecated, please change to :postmaster".yellow) if options[:mailgun_sandbox_postmaster]
if options[:mailgun_sandbox_postmaster] && !options[:postmaster]
options[:postmaster] = options[:mailgun_sandbox_postmaster]
puts("\nUsing :mailgun_sandbox_postmaster is deprecated, please change to :postmaster".yellow)
end

options[:apikey] = options[:mailgun_apikey] if options[:mailgun_apikey]
puts("\nUsing :mailgun_apikey is deprecated, please change to :apikey".yellow) if options[:mailgun_apikey]
if options[:mailgun_apikey] && !options[:apikey]
options[:apikey] = options[:mailgun_apikey]
puts("\nUsing :mailgun_apikey is deprecated, please change to :apikey".yellow)
end
end

def self.mailgunit(options)
Expand All @@ -122,14 +133,25 @@ def self.mailgunit(options)

unless options[:attachment].nil?
attachment_filenames = [*options[:attachment]]
attachments = attachment_filenames.map { |filename| File.new(filename, 'rb') }
attachments = attachment_filenames.map { |filename| Faraday::UploadIO.new(filename, mime_for(filename), filename) }
params.store(:attachment, attachments)
end

RestClient.post("https://api:#{options[:apikey]}@api.mailgun.net/v3/#{sandbox_domain}/messages", params)
conn = Faraday.new(url: "https://api:#{options[:apikey]}@api.mailgun.net") do |f|
f.request(:multipart)
f.request(:url_encoded)
f.adapter(:net_http)
end
response = conn.post("/v3/#{sandbox_domain}/messages", params)
UI.user_error!("Failed to send message via Mailgun, response: #{response.status}: #{response.body}.") if response.status != 200
mail_template(options)
end

def self.mime_for(path)
mime = MIME::Types.type_for(path)
mime.empty? ? 'text/plain' : mime[0].content_type
end

def self.mail_template(options)
hash = {
author: Actions.git_author_email,
Expand Down
6 changes: 4 additions & 2 deletions fastlane/lib/fastlane/actions/upload_symbols_to_sentry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ def self.run(params)
UI.important("GitHub: https://github.com/getsentry/fastlane-plugin-sentry")
UI.important("Installation: fastlane add_plugin sentry")

Actions.verify_gem!('rest-client')
require 'rest-client'
UI.user_error!("This plugin is now completely deprecated")
# the code below doesn't run anymore
# Actions.verify_gem!('rest-client')
# require 'rest-client'

# Params - API
host = params[:api_host]
Expand Down
83 changes: 0 additions & 83 deletions fastlane/spec/actions_specs/upload_symbols_to_sentry_spec.rb

This file was deleted.

4 changes: 2 additions & 2 deletions fastlane/spec/fastlane_require_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
end

it "formats gem require name for non-fastlane-plugin" do
gem_name = "rest-client"
gem_name = "some-lib"
gem_require_name = Fastlane::FastlaneRequire.format_gem_require_name(gem_name)
expect(gem_require_name).to eq("rest-client")
expect(gem_require_name).to eq("some-lib")
end

describe "checks if a gem is installed" do
Expand Down