Skip to content

Commit 6c62c46

Browse files
authored
fix: Remove the Faraday multipart warning and tweak the error message raised at runtime when Faraday Multipart is not installed
Remove the Faraday multipart warning and tweak the error message raised at runtime when Faraday Multipart is not installed
2 parents 71e3d20 + 32b73b6 commit 6c62c46

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

lib/octokit/default.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
rescue LoadError
1313
Octokit::Warnable.octokit_warn 'To use retry middleware with Faraday v2.0+, install `faraday-retry` gem'
1414
end
15-
begin
16-
require 'faraday/multipart'
17-
rescue LoadError
18-
Octokit::Warnable.octokit_warn 'To use multipart middleware with Faraday v2.0+, install `faraday-multipart` gem; note: this is used by the ManageGHES client for uploading licenses'
19-
end
2015
end
2116

2217
module Octokit

lib/octokit/enterprise_management_console_client/management_console.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,14 @@ def password_hash
171171
def faraday_configuration
172172
@faraday_configuration ||= Faraday.new(url: @management_console_endpoint) do |http|
173173
http.headers[:user_agent] = user_agent
174-
http.request :multipart
174+
begin
175+
http.request :multipart
176+
rescue Faraday::Error
177+
raise Faraday::Error, <<~ERROR
178+
The `faraday-multipart` gem is required to upload a license.
179+
Please add `gem "faraday-multipart"` to your Gemfile.
180+
ERROR
181+
end
175182
http.request :url_encoded
176183

177184
# Disabling SSL is essential for certain self-hosted Enterprise instances

lib/octokit/manage_ghes_client/manage_ghes.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ def set_maintenance_mode(enabled, options = {})
3636
# @return [nil]
3737
def upload_license(license)
3838
conn = authenticated_client
39-
conn.request :multipart
39+
begin
40+
conn.request :multipart
41+
rescue Faraday::Error
42+
raise Faraday::Error, <<~ERROR
43+
The `faraday-multipart` gem is required to upload a license.
44+
Please add `gem "faraday-multipart"` to your Gemfile.
45+
ERROR
46+
end
4047
params = {}
4148
params[:license] = Faraday::FilePart.new(license, 'binary')
4249
params[:password] = @manage_ghes_password

spec/octokit/enterprise_management_console_client/management_console_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
expect(@enterprise_management_console_client.last_response.status).to eq(202)
1515
assert_requested :post, github_management_console_url('setup/api/start')
1616
end
17+
18+
it 'raises an error if the faraday-multipart gem is not installed' do
19+
middleware_key = :multipart
20+
middleware = Faraday::Request.unregister_middleware(middleware_key)
21+
22+
expect { @enterprise_management_console_client.upload_license(@license) }.to raise_error Faraday::Error
23+
ensure
24+
Faraday::Request.register_middleware(middleware_key => middleware) if middleware
25+
end
1726
end # .upload_license
1827

1928
describe '.start_configuration', :vcr do

spec/octokit/ghes_manage_client/ghes_manage_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@
3838
expect(@manage_ghes.last_response.status).to eq(202)
3939
assert_requested :post, github_manage_ghes_url('/manage/v1/config/init')
4040
end
41+
42+
it 'raises an error if the faraday-multipart gem is not installed' do
43+
middleware_key = :multipart
44+
middleware = Faraday::Request.unregister_middleware(middleware_key)
45+
46+
expect { @manage_ghes.upload_license(@license) }.to raise_error Faraday::Error
47+
ensure
48+
Faraday::Request.register_middleware(middleware_key => middleware) if middleware
49+
end
4150
end # .upload_license
4251

4352
describe '.start_configuration', :vcr do

0 commit comments

Comments
 (0)