Skip to content

Commit

Permalink
Merge branch '4-stable' into readme_logger_update
Browse files Browse the repository at this point in the history
  • Loading branch information
Heather Harvey authored Jan 11, 2022
2 parents d5b2c7f + 098dfa0 commit 240e611
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 19 deletions.
6 changes: 3 additions & 3 deletions lib/octokit/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ def client_without_redirects(options = {})
conn_opts[:ssl] = { :verify_mode => @ssl_verify_mode } if @ssl_verify_mode
conn = Faraday.new(conn_opts) do |http|
if basic_authenticated?
http.basic_auth(@login, @password)
http.request :basic_auth, @login, @password
elsif token_authenticated?
http.authorization 'token', @access_token
http.request :authorization, 'token', @access_token
elsif bearer_authenticated?
http.authorization 'Bearer', @bearer_token
http.request :authorization, 'Bearer', @bearer_token
end
http.headers['accept'] = options[:accept] if options.key?(:accept)
end
Expand Down
12 changes: 6 additions & 6 deletions lib/octokit/client/organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ def remove_organization_membership(org, options = {})
# @return [Sawyer::Resource] Hash representing the new migration.
# @example
# @client.start_migration('github', ['github/dotfiles'])
# @see https://developer.github.com/v3/orgs/migrations/#start-a-migration
# @see https://docs.github.com/en/rest/reference/migrations#start-an-organization-migration
def start_migration(org, repositories, options = {})
options = ensure_api_media_type(:migrations, options)
options[:repositories] = repositories
Expand All @@ -744,7 +744,7 @@ def start_migration(org, repositories, options = {})
#
# @param org [String, Integer] Organization GitHub login or id.
# @return [Array<Sawyer::Resource>] Array of migration resources.
# @see https://developer.github.com/v3/orgs/migrations/#get-a-list-of-migrations
# @see https://docs.github.com/en/rest/reference/migrations#list-organization-migrations
def migrations(org, options = {})
options = ensure_api_media_type(:migrations, options)
paginate "#{Organization.path(org)}/migrations", options
Expand All @@ -756,7 +756,7 @@ def migrations(org, options = {})
#
# @param org [String, Integer] Organization GitHub login or id.
# @param id [Integer] ID number of the migration.
# @see https://developer.github.com/v3/orgs/migrations/#get-the-status-of-a-migration
# @see https://docs.github.com/en/rest/reference/migrations#get-an-organization-migration-status
def migration_status(org, id, options = {})
options = ensure_api_media_type(:migrations, options)
get "#{Organization.path(org)}/migrations/#{id}", options
Expand All @@ -768,7 +768,7 @@ def migration_status(org, id, options = {})
#
# @param org [String, Integer] Organization GitHub login or id.
# @param id [Integer] ID number of the migration.
# @see https://developer.github.com/v3/orgs/migrations/#download-a-migration-archive
# @see https://docs.github.com/en/rest/reference/migrations#download-an-organization-migration-archive
def migration_archive_url(org, id, options = {})
options = ensure_api_media_type(:migrations, options)
url = "#{Organization.path(org)}/migrations/#{id}/archive"
Expand All @@ -783,7 +783,7 @@ def migration_archive_url(org, id, options = {})
#
# @param org [String, Integer] Organization GitHub login or id.
# @param id [Integer] ID number of the migration.
# @see https://developer.github.com/v3/orgs/migrations/#delete-a-migration-archive
# @see https://docs.github.com/en/rest/reference/migrations#delete-an-organization-migration-archive
def delete_migration_archive(org, id, options = {})
options = ensure_api_media_type(:migrations, options)
delete "#{Organization.path(org)}/migrations/#{id}/archive", options
Expand All @@ -796,7 +796,7 @@ def delete_migration_archive(org, id, options = {})
# @param org [String, Integer] Organization GitHub login or id.
# @param id [Integer] ID number of the migration.
# @param repo [String] Name of the repository.
# @see https://developer.github.com/v3/orgs/migrations/#unlock-a-repository
# @see https://docs.github.com/en/rest/reference/migrations#unlock-an-organization-repository
def unlock_repository(org, id, repo, options = {})
options = ensure_api_media_type(:migrations, options)
delete "#{Organization.path(org)}/migrations/#{id}/repos/#{repo}/lock", options
Expand Down
4 changes: 2 additions & 2 deletions lib/octokit/client/pub_sub_hubbub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def pub_sub_hubbub_request(options = {})
conn = Faraday.new(:url => @api_endpoint) do |http|
http.headers[:user_agent] = user_agent
if basic_authenticated?
http.basic_auth(@login, @password)
http.request :basic_auth, @login, @password
elsif token_authenticated?
http.authorization 'token', @access_token
http.request :authorization, 'token', @access_token
end
http.request :url_encoded
http.use Octokit::Response::RaiseError
Expand Down
10 changes: 5 additions & 5 deletions lib/octokit/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ def agent
http.headers[:content_type] = "application/json"
http.headers[:user_agent] = user_agent
if basic_authenticated?
http.basic_auth(@login, @password)
http.request :basic_auth, @login, @password
elsif token_authenticated?
http.authorization 'token', @access_token
http.request :authorization, 'token', @access_token
elsif bearer_authenticated?
http.authorization 'Bearer', @bearer_token
http.request :authorization, 'Bearer', @bearer_token
elsif application_authenticated?
http.basic_auth(@client_id, @client_secret)
http.request :basic_auth, @client_id, @client_secret
end
end
end
Expand Down Expand Up @@ -176,7 +176,7 @@ def sawyer_options
:links_parser => Sawyer::LinkParsers::Simple.new
}
conn_opts = @connection_options
conn_opts[:builder] = @middleware if @middleware
conn_opts[:builder] = @middleware.dup if @middleware
conn_opts[:proxy] = @proxy if @proxy
if conn_opts[:ssl].nil?
conn_opts[:ssl] = { :verify_mode => @ssl_verify_mode } if @ssl_verify_mode
Expand Down
5 changes: 4 additions & 1 deletion lib/octokit/middleware/follow_redirects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ def update_env(env, request_body, response)
original_url = env[:url]
env[:url] += safe_escape(response["location"])
unless same_host?(original_url, env[:url])
env[:request_headers].delete("Authorization")
# HACK: Faraday’s Authorization middlewares don’t touch the request if the `Authorization` header is set.
# This is a workaround to drop authentication info.
# See https://github.com/octokit/octokit.rb/pull/1359#issuecomment-925609697
env[:request_headers]["Authorization"] = "dummy"
end

if convert_to_get?(response)
Expand Down
5 changes: 4 additions & 1 deletion spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
require 'webmock/rspec'
require 'base64'
require 'jwt'
require 'pry-byebug'
# latest version of pry-byebug is not compatible with Ruby 3.2.0
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.2.0')
require 'pry-byebug'
end

WebMock.disable_net_connect!()

Expand Down
2 changes: 1 addition & 1 deletion spec/octokit/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@

assert_requested original_request
assert_requested(:get, "https://example.com/bar") { |req|
req.headers["Authorization"].nil?
req.headers["Authorization"] == "dummy"
}
end

Expand Down

0 comments on commit 240e611

Please sign in to comment.