From 72a77464fe229a2e5f123ad6ff15cd86a5493c5b Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Tue, 31 Aug 2021 13:08:22 +0900 Subject: [PATCH 1/8] Fix deprecation warning since Faraday 1.7.1 --- lib/octokit/client.rb | 6 +++--- lib/octokit/client/pub_sub_hubbub.rb | 4 ++-- lib/octokit/connection.rb | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/octokit/client.rb b/lib/octokit/client.rb index b6d4a480f..569156526 100644 --- a/lib/octokit/client.rb +++ b/lib/octokit/client.rb @@ -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.set_authorization_header :basic_auth, @login, @password elsif token_authenticated? - http.authorization 'token', @access_token + http.set_authorization_header :authorization, 'token', @access_token elsif bearer_authenticated? - http.authorization 'Bearer', @bearer_token + http.set_authorization_header :authorization, 'Bearer', @bearer_token end http.headers['accept'] = options[:accept] if options.key?(:accept) end diff --git a/lib/octokit/client/pub_sub_hubbub.rb b/lib/octokit/client/pub_sub_hubbub.rb index 69ae334e0..75c8722fb 100644 --- a/lib/octokit/client/pub_sub_hubbub.rb +++ b/lib/octokit/client/pub_sub_hubbub.rb @@ -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.set_authorization_header :basic_auth, @login, @password elsif token_authenticated? - http.authorization 'token', @access_token + http.set_authorization_header :authorization, 'token', @access_token end http.request :url_encoded http.use Octokit::Response::RaiseError diff --git a/lib/octokit/connection.rb b/lib/octokit/connection.rb index fbe71ef1f..93035e0ca 100644 --- a/lib/octokit/connection.rb +++ b/lib/octokit/connection.rb @@ -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.set_authorization_header :basic_auth, @login, @password elsif token_authenticated? - http.authorization 'token', @access_token + http.set_authorization_header :authorization, 'token', @access_token elsif bearer_authenticated? - http.authorization 'Bearer', @bearer_token + http.set_authorization_header :authorization, 'Bearer', @bearer_token elsif application_authenticated? - http.basic_auth(@client_id, @client_secret) + http.set_authorization_header :basic_auth, @client_id, @client_secret end end end From c34a880b504eb283dcfb26e29c0ae9ab3e9411e7 Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Wed, 22 Sep 2021 19:02:12 +0900 Subject: [PATCH 2/8] Replace `#set_authorization_header` with `#request` --- lib/octokit/client.rb | 6 +++--- lib/octokit/client/pub_sub_hubbub.rb | 4 ++-- lib/octokit/connection.rb | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/octokit/client.rb b/lib/octokit/client.rb index 569156526..677a00a58 100644 --- a/lib/octokit/client.rb +++ b/lib/octokit/client.rb @@ -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.set_authorization_header :basic_auth, @login, @password + http.request :basic_auth, @login, @password elsif token_authenticated? - http.set_authorization_header :authorization, 'token', @access_token + http.request :token_auth, @access_token elsif bearer_authenticated? - http.set_authorization_header :authorization, 'Bearer', @bearer_token + http.request :authorization, 'Bearer', @bearer_token end http.headers['accept'] = options[:accept] if options.key?(:accept) end diff --git a/lib/octokit/client/pub_sub_hubbub.rb b/lib/octokit/client/pub_sub_hubbub.rb index 75c8722fb..90c729ec8 100644 --- a/lib/octokit/client/pub_sub_hubbub.rb +++ b/lib/octokit/client/pub_sub_hubbub.rb @@ -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.set_authorization_header :basic_auth, @login, @password + http.request :basic_auth, @login, @password elsif token_authenticated? - http.set_authorization_header :authorization, 'token', @access_token + http.request :token_auth, @access_token end http.request :url_encoded http.use Octokit::Response::RaiseError diff --git a/lib/octokit/connection.rb b/lib/octokit/connection.rb index 93035e0ca..5d63e8975 100644 --- a/lib/octokit/connection.rb +++ b/lib/octokit/connection.rb @@ -107,13 +107,13 @@ def agent http.headers[:content_type] = "application/json" http.headers[:user_agent] = user_agent if basic_authenticated? - http.set_authorization_header :basic_auth, @login, @password + http.request :basic_auth, @login, @password elsif token_authenticated? - http.set_authorization_header :authorization, 'token', @access_token + http.request :token_auth, @access_token elsif bearer_authenticated? - http.set_authorization_header :authorization, 'Bearer', @bearer_token + http.request :authorization, 'Bearer', @bearer_token elsif application_authenticated? - http.set_authorization_header :basic_auth, @client_id, @client_secret + http.request :basic_auth, @client_id, @client_secret end end end From 1680badb7567d361c593dd8bc7767caa6a9c73ad Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Wed, 22 Sep 2021 22:43:00 +0900 Subject: [PATCH 3/8] Change `MIDDLEWARE` to `MIDDLEWARE.dup` --- lib/octokit/default.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/octokit/default.rb b/lib/octokit/default.rb index ef91dfcac..5ba0a3d17 100644 --- a/lib/octokit/default.rb +++ b/lib/octokit/default.rb @@ -115,7 +115,7 @@ def login # from {MIDDLEWARE} # @return [Faraday::RackBuilder or Faraday::Builder] def middleware - MIDDLEWARE + MIDDLEWARE.dup end # Default GitHub password for Basic Auth from ENV From 9fadd8bb26c731d0fede842f00251cf7f4ac020d Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Wed, 22 Sep 2021 23:36:59 +0900 Subject: [PATCH 4/8] Call `dup` before using `@middleware` --- lib/octokit/connection.rb | 2 +- lib/octokit/default.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/octokit/connection.rb b/lib/octokit/connection.rb index 5d63e8975..c57493603 100644 --- a/lib/octokit/connection.rb +++ b/lib/octokit/connection.rb @@ -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 diff --git a/lib/octokit/default.rb b/lib/octokit/default.rb index 5ba0a3d17..ef91dfcac 100644 --- a/lib/octokit/default.rb +++ b/lib/octokit/default.rb @@ -115,7 +115,7 @@ def login # from {MIDDLEWARE} # @return [Faraday::RackBuilder or Faraday::Builder] def middleware - MIDDLEWARE.dup + MIDDLEWARE end # Default GitHub password for Basic Auth from ENV From c7b5fa2bf23850806651fbef03123f229aff4855 Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Thu, 23 Sep 2021 01:20:34 +0900 Subject: [PATCH 5/8] Replace `:token_auth` with `:authorization, 'token'` --- lib/octokit/client.rb | 2 +- lib/octokit/client/pub_sub_hubbub.rb | 2 +- lib/octokit/connection.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/octokit/client.rb b/lib/octokit/client.rb index 677a00a58..779f85a67 100644 --- a/lib/octokit/client.rb +++ b/lib/octokit/client.rb @@ -240,7 +240,7 @@ def client_without_redirects(options = {}) if basic_authenticated? http.request :basic_auth, @login, @password elsif token_authenticated? - http.request :token_auth, @access_token + http.request :authorization, 'token', @access_token elsif bearer_authenticated? http.request :authorization, 'Bearer', @bearer_token end diff --git a/lib/octokit/client/pub_sub_hubbub.rb b/lib/octokit/client/pub_sub_hubbub.rb index 90c729ec8..1ed9f2e6e 100644 --- a/lib/octokit/client/pub_sub_hubbub.rb +++ b/lib/octokit/client/pub_sub_hubbub.rb @@ -93,7 +93,7 @@ def pub_sub_hubbub_request(options = {}) if basic_authenticated? http.request :basic_auth, @login, @password elsif token_authenticated? - http.request :token_auth, @access_token + http.request :authorization, 'token', @access_token end http.request :url_encoded http.use Octokit::Response::RaiseError diff --git a/lib/octokit/connection.rb b/lib/octokit/connection.rb index c57493603..9c34aa103 100644 --- a/lib/octokit/connection.rb +++ b/lib/octokit/connection.rb @@ -109,7 +109,7 @@ def agent if basic_authenticated? http.request :basic_auth, @login, @password elsif token_authenticated? - http.request :token_auth, @access_token + http.request :authorization, 'token', @access_token elsif bearer_authenticated? http.request :authorization, 'Bearer', @bearer_token elsif application_authenticated? From 23b4a5e4beffd01888430c2cddd1f90fc587ed52 Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Thu, 23 Sep 2021 22:52:47 +0900 Subject: [PATCH 6/8] Add workaround into `FollowRedirects` middleware --- lib/octokit/middleware/follow_redirects.rb | 5 ++++- spec/octokit/client_spec.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/octokit/middleware/follow_redirects.rb b/lib/octokit/middleware/follow_redirects.rb index 3b3556ee7..60ca6c16d 100644 --- a/lib/octokit/middleware/follow_redirects.rb +++ b/lib/octokit/middleware/follow_redirects.rb @@ -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) diff --git a/spec/octokit/client_spec.rb b/spec/octokit/client_spec.rb index 206c0c499..d07134044 100644 --- a/spec/octokit/client_spec.rb +++ b/spec/octokit/client_spec.rb @@ -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 From 6809310721ca9c77c03aab49f2d4d36442e75e16 Mon Sep 17 00:00:00 2001 From: Rahul Zhade Date: Fri, 3 Dec 2021 15:16:37 -0800 Subject: [PATCH 7/8] Update broken migration documentation links --- lib/octokit/client/organizations.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/octokit/client/organizations.rb b/lib/octokit/client/organizations.rb index 1e27bf7db..237e1b803 100644 --- a/lib/octokit/client/organizations.rb +++ b/lib/octokit/client/organizations.rb @@ -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 @@ -744,7 +744,7 @@ def start_migration(org, repositories, options = {}) # # @param org [String, Integer] Organization GitHub login or id. # @return [Array] 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 @@ -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 @@ -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" @@ -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 @@ -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 From 25a27b4efc4348361bdd467ac148651a56fdee5b Mon Sep 17 00:00:00 2001 From: Ashish Keshan Date: Fri, 7 Jan 2022 10:54:37 -0800 Subject: [PATCH 8/8] don't require pry-byebug on ruby -V >= 3.2 --- spec/helper.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/helper.rb b/spec/helper.rb index 22c836a62..659650d53 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -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!()