octokit 4.21.0 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +120 -96
- data/Rakefile +20 -14
- data/lib/ext/sawyer/relation.rb +4 -2
- data/lib/octokit/arguments.rb +3 -3
- data/lib/octokit/authentication.rb +10 -3
- data/lib/octokit/client/actions_artifacts.rb +71 -0
- data/lib/octokit/client/actions_secrets.rb +111 -8
- data/lib/octokit/client/actions_workflow_jobs.rb +65 -0
- data/lib/octokit/client/actions_workflow_runs.rb +23 -3
- data/lib/octokit/client/actions_workflows.rb +27 -2
- data/lib/octokit/client/apps.rb +63 -74
- data/lib/octokit/client/checks.rb +18 -9
- data/lib/octokit/client/code_scanning.rb +190 -0
- data/lib/octokit/client/codespaces_secrets.rb +108 -0
- data/lib/octokit/client/commit_branches.rb +2 -2
- data/lib/octokit/client/commit_comments.rb +8 -8
- data/lib/octokit/client/commit_pulls.rb +2 -2
- data/lib/octokit/client/commits.rb +31 -34
- data/lib/octokit/client/community_profile.rb +2 -3
- data/lib/octokit/client/contents.rb +19 -22
- data/lib/octokit/client/dependabot_secrets.rb +108 -0
- data/lib/octokit/client/deployments.rb +8 -8
- data/lib/octokit/client/downloads.rb +5 -6
- data/lib/octokit/client/emojis.rb +3 -3
- data/lib/octokit/client/environments.rb +58 -0
- data/lib/octokit/client/events.rb +4 -5
- data/lib/octokit/client/feeds.rb +4 -5
- data/lib/octokit/client/gists.rb +6 -6
- data/lib/octokit/client/gitignore.rb +3 -3
- data/lib/octokit/client/hooks.rb +9 -19
- data/lib/octokit/client/issues.rb +14 -15
- data/lib/octokit/client/labels.rb +10 -10
- data/lib/octokit/client/legacy_search.rb +3 -3
- data/lib/octokit/client/licenses.rb +3 -6
- data/lib/octokit/client/markdown.rb +3 -3
- data/lib/octokit/client/marketplace.rb +4 -4
- data/lib/octokit/client/meta.rb +4 -5
- data/lib/octokit/client/milestones.rb +5 -5
- data/lib/octokit/client/notifications.rb +6 -6
- data/lib/octokit/client/oauth_applications.rb +1 -7
- data/lib/octokit/client/objects.rb +14 -14
- data/lib/octokit/client/organizations.rb +106 -62
- data/lib/octokit/client/pages.rb +5 -7
- data/lib/octokit/client/projects.rb +44 -64
- data/lib/octokit/client/pull_requests.rb +66 -45
- data/lib/octokit/client/rate_limit.rb +9 -11
- data/lib/octokit/client/reactions.rb +78 -16
- data/lib/octokit/client/refs.rb +15 -18
- data/lib/octokit/client/releases.rb +13 -13
- data/lib/octokit/client/repositories.rb +92 -69
- data/lib/octokit/client/repository_invitations.rb +3 -3
- data/lib/octokit/client/reviews.rb +8 -8
- data/lib/octokit/client/say.rb +4 -5
- data/lib/octokit/client/search.rb +24 -10
- data/lib/octokit/client/service_status.rb +19 -9
- data/lib/octokit/client/source_import.rb +7 -12
- data/lib/octokit/client/stats.rb +10 -9
- data/lib/octokit/client/statuses.rb +5 -5
- data/lib/octokit/client/tokens.rb +31 -0
- data/lib/octokit/client/traffic.rb +6 -11
- data/lib/octokit/client/users.rb +54 -33
- data/lib/octokit/client.rb +44 -20
- data/lib/octokit/configurable.rb +51 -31
- data/lib/octokit/connection.rb +33 -24
- data/lib/octokit/default.rb +66 -35
- data/lib/octokit/enterprise_admin_client/admin_stats.rb +13 -14
- data/lib/octokit/enterprise_admin_client/license.rb +3 -4
- data/lib/octokit/enterprise_admin_client/orgs.rb +3 -4
- data/lib/octokit/enterprise_admin_client/search_indexing.rb +7 -8
- data/lib/octokit/enterprise_admin_client/users.rb +5 -4
- data/lib/octokit/enterprise_admin_client.rb +9 -3
- data/lib/octokit/enterprise_management_console_client/management_console.rb +51 -33
- data/lib/octokit/enterprise_management_console_client.rb +8 -2
- data/lib/octokit/error.rb +53 -34
- data/lib/octokit/gist.rb +3 -4
- data/lib/octokit/manage_ghes_client/manage_ghes.rb +178 -0
- data/lib/octokit/manage_ghes_client.rb +64 -0
- data/lib/octokit/middleware/follow_redirects.rb +16 -12
- data/lib/octokit/organization.rb +3 -1
- data/lib/octokit/rate_limit.rb +8 -6
- data/lib/octokit/repo_arguments.rb +3 -4
- data/lib/octokit/repository.rb +32 -25
- data/lib/octokit/response/base_middleware.rb +10 -0
- data/lib/octokit/response/feed_parser.rb +5 -7
- data/lib/octokit/response/raise_error.rb +4 -4
- data/lib/octokit/user.rb +4 -2
- data/lib/octokit/version.rb +4 -2
- data/lib/octokit/warnable.rb +4 -5
- data/lib/octokit.rb +30 -8
- data/octokit.gemspec +12 -11
- metadata +22 -34
- data/lib/octokit/client/authorizations.rb +0 -182
- data/lib/octokit/client/pub_sub_hubbub.rb +0 -111
- data/lib/octokit/preview.rb +0 -46
data/lib/octokit/client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'octokit/connection'
|
2
4
|
require 'octokit/warnable'
|
3
5
|
require 'octokit/arguments'
|
@@ -9,13 +11,15 @@ require 'octokit/rate_limit'
|
|
9
11
|
require 'octokit/repository'
|
10
12
|
require 'octokit/user'
|
11
13
|
require 'octokit/organization'
|
12
|
-
require 'octokit/
|
14
|
+
require 'octokit/client/actions_artifacts'
|
13
15
|
require 'octokit/client/actions_secrets'
|
14
16
|
require 'octokit/client/actions_workflows'
|
17
|
+
require 'octokit/client/actions_workflow_jobs'
|
15
18
|
require 'octokit/client/actions_workflow_runs'
|
16
19
|
require 'octokit/client/apps'
|
17
|
-
require 'octokit/client/authorizations'
|
18
20
|
require 'octokit/client/checks'
|
21
|
+
require 'octokit/client/code_scanning'
|
22
|
+
require 'octokit/client/codespaces_secrets'
|
19
23
|
require 'octokit/client/commits'
|
20
24
|
require 'octokit/client/commit_comments'
|
21
25
|
require 'octokit/client/commit_pulls'
|
@@ -23,7 +27,9 @@ require 'octokit/client/commit_branches'
|
|
23
27
|
require 'octokit/client/community_profile'
|
24
28
|
require 'octokit/client/contents'
|
25
29
|
require 'octokit/client/downloads'
|
30
|
+
require 'octokit/client/dependabot_secrets'
|
26
31
|
require 'octokit/client/deployments'
|
32
|
+
require 'octokit/client/environments'
|
27
33
|
require 'octokit/client/emojis'
|
28
34
|
require 'octokit/client/events'
|
29
35
|
require 'octokit/client/feeds'
|
@@ -44,7 +50,6 @@ require 'octokit/client/objects'
|
|
44
50
|
require 'octokit/client/organizations'
|
45
51
|
require 'octokit/client/pages'
|
46
52
|
require 'octokit/client/projects'
|
47
|
-
require 'octokit/client/pub_sub_hubbub'
|
48
53
|
require 'octokit/client/pull_requests'
|
49
54
|
require 'octokit/client/rate_limit'
|
50
55
|
require 'octokit/client/reactions'
|
@@ -59,33 +64,35 @@ require 'octokit/client/service_status'
|
|
59
64
|
require 'octokit/client/source_import'
|
60
65
|
require 'octokit/client/stats'
|
61
66
|
require 'octokit/client/statuses'
|
67
|
+
require 'octokit/client/tokens'
|
62
68
|
require 'octokit/client/traffic'
|
63
69
|
require 'octokit/client/users'
|
64
70
|
require 'ext/sawyer/relation'
|
65
71
|
|
66
72
|
module Octokit
|
67
|
-
|
68
73
|
# Client for the GitHub API
|
69
74
|
#
|
70
75
|
# @see https://developer.github.com
|
71
76
|
class Client
|
72
|
-
|
73
77
|
include Octokit::Authentication
|
74
78
|
include Octokit::Configurable
|
75
79
|
include Octokit::Connection
|
76
|
-
include Octokit::Preview
|
77
80
|
include Octokit::Warnable
|
81
|
+
include Octokit::Client::ActionsArtifacts
|
78
82
|
include Octokit::Client::ActionsSecrets
|
79
|
-
include Octokit::Client::Authorizations
|
80
83
|
include Octokit::Client::Checks
|
84
|
+
include Octokit::Client::CodeScanning
|
85
|
+
include Octokit::Client::CodespacesSecrets
|
81
86
|
include Octokit::Client::Commits
|
82
87
|
include Octokit::Client::CommitComments
|
83
88
|
include Octokit::Client::CommitPulls
|
84
89
|
include Octokit::Client::CommitBranches
|
85
90
|
include Octokit::Client::CommunityProfile
|
86
91
|
include Octokit::Client::Contents
|
92
|
+
include Octokit::Client::DependabotSecrets
|
87
93
|
include Octokit::Client::Deployments
|
88
94
|
include Octokit::Client::Downloads
|
95
|
+
include Octokit::Client::Environments
|
89
96
|
include Octokit::Client::Emojis
|
90
97
|
include Octokit::Client::Events
|
91
98
|
include Octokit::Client::Feeds
|
@@ -93,6 +100,7 @@ module Octokit
|
|
93
100
|
include Octokit::Client::Gitignore
|
94
101
|
include Octokit::Client::Hooks
|
95
102
|
include Octokit::Client::ActionsWorkflows
|
103
|
+
include Octokit::Client::ActionsWorkflowJobs
|
96
104
|
include Octokit::Client::ActionsWorkflowRuns
|
97
105
|
include Octokit::Client::Apps
|
98
106
|
include Octokit::Client::Issues
|
@@ -109,7 +117,6 @@ module Octokit
|
|
109
117
|
include Octokit::Client::Organizations
|
110
118
|
include Octokit::Client::Pages
|
111
119
|
include Octokit::Client::Projects
|
112
|
-
include Octokit::Client::PubSubHubbub
|
113
120
|
include Octokit::Client::PullRequests
|
114
121
|
include Octokit::Client::RateLimit
|
115
122
|
include Octokit::Client::Reactions
|
@@ -124,16 +131,24 @@ module Octokit
|
|
124
131
|
include Octokit::Client::SourceImport
|
125
132
|
include Octokit::Client::Stats
|
126
133
|
include Octokit::Client::Statuses
|
134
|
+
include Octokit::Client::Tokens
|
127
135
|
include Octokit::Client::Traffic
|
128
136
|
include Octokit::Client::Users
|
129
137
|
|
130
138
|
# Header keys that can be passed in options hash to {#get},{#head}
|
131
|
-
CONVENIENCE_HEADERS = Set.new([
|
139
|
+
CONVENIENCE_HEADERS = Set.new(%i[accept content_type])
|
132
140
|
|
133
141
|
def initialize(options = {})
|
134
142
|
# Use options passed in, but fall back to module defaults
|
143
|
+
#
|
144
|
+
# rubocop:disable Style/HashEachMethods
|
145
|
+
#
|
146
|
+
# This may look like a `.keys.each` which should be replaced with `#each_key`, but
|
147
|
+
# this doesn't actually work, since `#keys` is just a method we've defined ourselves.
|
148
|
+
# The class doesn't fulfill the whole `Enumerable` contract.
|
135
149
|
Octokit::Configurable.keys.each do |key|
|
136
|
-
|
150
|
+
# rubocop:enable Style/HashEachMethods
|
151
|
+
value = options[key].nil? ? Octokit.instance_variable_get(:"@#{key}") : options[key]
|
137
152
|
instance_variable_set(:"@#{key}", value)
|
138
153
|
end
|
139
154
|
|
@@ -148,11 +163,17 @@ module Octokit
|
|
148
163
|
|
149
164
|
# mask password
|
150
165
|
inspected.gsub! @password, '*******' if @password
|
151
|
-
|
166
|
+
if @management_console_password
|
167
|
+
inspected.gsub! @management_console_password, '*******'
|
168
|
+
end
|
152
169
|
inspected.gsub! @bearer_token, '********' if @bearer_token
|
153
170
|
# Only show last 4 of token, secret
|
154
|
-
|
155
|
-
|
171
|
+
if @access_token
|
172
|
+
inspected.gsub! @access_token, "#{'*' * 36}#{@access_token[36..]}"
|
173
|
+
end
|
174
|
+
if @client_secret
|
175
|
+
inspected.gsub! @client_secret, "#{'*' * 36}#{@client_secret[36..]}"
|
176
|
+
end
|
156
177
|
|
157
178
|
inspected
|
158
179
|
end
|
@@ -170,11 +191,12 @@ module Octokit
|
|
170
191
|
# # GET https://foo:bar@api.github.com/
|
171
192
|
# client.get "/"
|
172
193
|
# end
|
173
|
-
def as_app(key = client_id, secret = client_secret
|
194
|
+
def as_app(key = client_id, secret = client_secret)
|
174
195
|
if key.to_s.empty? || secret.to_s.empty?
|
175
|
-
raise ApplicationCredentialsRequired,
|
196
|
+
raise ApplicationCredentialsRequired, 'client_id and client_secret required'
|
176
197
|
end
|
177
|
-
|
198
|
+
|
199
|
+
app_client = dup
|
178
200
|
app_client.client_id = app_client.client_secret = nil
|
179
201
|
app_client.login = key
|
180
202
|
app_client.password = secret
|
@@ -235,15 +257,17 @@ module Octokit
|
|
235
257
|
conn_opts[:url] = @api_endpoint
|
236
258
|
conn_opts[:builder] = @middleware.dup if @middleware
|
237
259
|
conn_opts[:proxy] = @proxy if @proxy
|
238
|
-
conn_opts[:ssl] = { :
|
260
|
+
conn_opts[:ssl] = { verify_mode: @ssl_verify_mode } if @ssl_verify_mode
|
239
261
|
conn = Faraday.new(conn_opts) do |http|
|
262
|
+
http_cache_middleware = http.builder.handlers.delete(Faraday::HttpCache) if Faraday.const_defined?(:HttpCache)
|
240
263
|
if basic_authenticated?
|
241
|
-
http.
|
264
|
+
http.request(*FARADAY_BASIC_AUTH_KEYS, @login, @password)
|
242
265
|
elsif token_authenticated?
|
243
|
-
http.authorization 'token', @access_token
|
266
|
+
http.request :authorization, 'token', @access_token
|
244
267
|
elsif bearer_authenticated?
|
245
|
-
http.authorization 'Bearer', @bearer_token
|
268
|
+
http.request :authorization, 'Bearer', @bearer_token
|
246
269
|
end
|
270
|
+
http.builder.handlers.push(http_cache_middleware) unless http_cache_middleware.nil?
|
247
271
|
http.headers['accept'] = options[:accept] if options.key?(:accept)
|
248
272
|
end
|
249
273
|
conn.builder.delete(Octokit::Middleware::FollowRedirects)
|
data/lib/octokit/configurable.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module Octokit
|
3
4
|
# Configuration options for {Client}, defaulting to values
|
4
5
|
# in {Default}
|
5
6
|
module Configurable
|
@@ -31,6 +32,12 @@ module Octokit
|
|
31
32
|
# @return [String] An admin password set up for your GitHub Enterprise management console
|
32
33
|
# @!attribute management_console_endpoint
|
33
34
|
# @return [String] Base URL for API requests to the GitHub Enterprise management console
|
35
|
+
# @!attribute manage_ghes_endpoint
|
36
|
+
# @return [String] Base URL for API requests to the GitHub Enterprise Server Manage API
|
37
|
+
# @!attribute manage_ghes_username
|
38
|
+
# @return [String] API username for requests to the GitHub Enterprise Server Manage API
|
39
|
+
# @!attribute manage_ghes_password
|
40
|
+
# @return [String] API user password for requests to the GitHub Enterprise Server Manage API
|
34
41
|
# @!attribute middleware
|
35
42
|
# @see https://github.com/lostisland/faraday
|
36
43
|
# @return [Faraday::Builder or Faraday::RackBuilder] Configure middleware for Faraday
|
@@ -58,34 +65,39 @@ module Octokit
|
|
58
65
|
:middleware, :netrc, :netrc_file,
|
59
66
|
:per_page, :proxy, :ssl_verify_mode, :user_agent
|
60
67
|
attr_writer :password, :web_endpoint, :api_endpoint, :login,
|
61
|
-
:management_console_endpoint, :management_console_password
|
68
|
+
:management_console_endpoint, :management_console_password,
|
69
|
+
:manage_ghes_endpoint,
|
70
|
+
:manage_ghes_username,
|
71
|
+
:manage_ghes_password
|
62
72
|
|
63
73
|
class << self
|
64
|
-
|
65
74
|
# List of configurable keys for {Octokit::Client}
|
66
75
|
# @return [Array] of option keys
|
67
76
|
def keys
|
68
|
-
@keys ||= [
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
77
|
+
@keys ||= %i[
|
78
|
+
access_token
|
79
|
+
api_endpoint
|
80
|
+
auto_paginate
|
81
|
+
bearer_token
|
82
|
+
client_id
|
83
|
+
client_secret
|
84
|
+
connection_options
|
85
|
+
default_media_type
|
86
|
+
login
|
87
|
+
management_console_endpoint
|
88
|
+
management_console_password
|
89
|
+
manage_ghes_endpoint
|
90
|
+
manage_ghes_username
|
91
|
+
manage_ghes_password
|
92
|
+
middleware
|
93
|
+
netrc
|
94
|
+
netrc_file
|
95
|
+
per_page
|
96
|
+
password
|
97
|
+
proxy
|
98
|
+
ssl_verify_mode
|
99
|
+
user_agent
|
100
|
+
web_endpoint
|
89
101
|
]
|
90
102
|
end
|
91
103
|
end
|
@@ -97,7 +109,13 @@ module Octokit
|
|
97
109
|
|
98
110
|
# Reset configuration options to default values
|
99
111
|
def reset!
|
112
|
+
# rubocop:disable Style/HashEachMethods
|
113
|
+
#
|
114
|
+
# This may look like a `.keys.each` which should be replaced with `#each_key`, but
|
115
|
+
# this doesn't actually work, since `#keys` is just a method we've defined ourselves.
|
116
|
+
# The class doesn't fulfill the whole `Enumerable` contract.
|
100
117
|
Octokit::Configurable.keys.each do |key|
|
118
|
+
# rubocop:enable Style/HashEachMethods
|
101
119
|
instance_variable_set(:"@#{key}", Octokit::Default.options[key])
|
102
120
|
end
|
103
121
|
self
|
@@ -113,24 +131,26 @@ module Octokit
|
|
113
131
|
end
|
114
132
|
|
115
133
|
def api_endpoint
|
116
|
-
File.join(@api_endpoint,
|
134
|
+
File.join(@api_endpoint, '')
|
117
135
|
end
|
118
136
|
|
119
137
|
def management_console_endpoint
|
120
|
-
File.join(@management_console_endpoint,
|
138
|
+
File.join(@management_console_endpoint, '')
|
139
|
+
end
|
140
|
+
|
141
|
+
def manage_ghes_endpoint
|
142
|
+
File.join(@manage_ghes_endpoint, '')
|
121
143
|
end
|
122
144
|
|
123
145
|
# Base URL for generated web URLs
|
124
146
|
#
|
125
147
|
# @return [String] Default: https://github.com/
|
126
148
|
def web_endpoint
|
127
|
-
File.join(@web_endpoint,
|
149
|
+
File.join(@web_endpoint, '')
|
128
150
|
end
|
129
151
|
|
130
152
|
def login
|
131
|
-
@login ||=
|
132
|
-
user.login if token_authenticated?
|
133
|
-
end
|
153
|
+
@login ||= (user.login if token_authenticated?)
|
134
154
|
end
|
135
155
|
|
136
156
|
def netrc?
|
@@ -140,7 +160,7 @@ module Octokit
|
|
140
160
|
private
|
141
161
|
|
142
162
|
def options
|
143
|
-
|
163
|
+
Octokit::Configurable.keys.to_h { |key| [key, instance_variable_get(:"@#{key}")] }
|
144
164
|
end
|
145
165
|
|
146
166
|
def fetch_client_id_and_secret(overrides = {})
|
data/lib/octokit/connection.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'sawyer'
|
2
4
|
require 'octokit/authentication'
|
3
5
|
module Octokit
|
4
|
-
|
5
6
|
# Network layer for API clients.
|
6
7
|
module Connection
|
7
|
-
|
8
8
|
include Octokit::Authentication
|
9
9
|
|
10
10
|
# Header keys that can be passed in options hash to {#get},{#head}
|
11
|
-
CONVENIENCE_HEADERS = Set.new([
|
11
|
+
CONVENIENCE_HEADERS = Set.new(%i[accept content_type])
|
12
12
|
|
13
13
|
# Make a HTTP GET request
|
14
14
|
#
|
@@ -75,17 +75,17 @@ module Octokit
|
|
75
75
|
# contains the contents of the requests so far and the second parameter
|
76
76
|
# contains the latest response.
|
77
77
|
# @return [Sawyer::Resource]
|
78
|
-
def paginate(url, options = {}
|
78
|
+
def paginate(url, options = {})
|
79
79
|
opts = parse_query_and_convenience_headers(options)
|
80
80
|
if @auto_paginate || @per_page
|
81
|
-
opts[:query][:per_page] ||=
|
81
|
+
opts[:query][:per_page] ||= @per_page || (@auto_paginate ? 100 : nil)
|
82
82
|
end
|
83
83
|
|
84
84
|
data = request(:get, url, opts.dup)
|
85
85
|
|
86
86
|
if @auto_paginate
|
87
87
|
while @last_response.rels[:next] && rate_limit.remaining > 0
|
88
|
-
@last_response = @last_response.rels[:next].get(:
|
88
|
+
@last_response = @last_response.rels[:next].get(headers: opts[:headers])
|
89
89
|
if block_given?
|
90
90
|
yield(data, @last_response)
|
91
91
|
else
|
@@ -104,17 +104,19 @@ module Octokit
|
|
104
104
|
def agent
|
105
105
|
@agent ||= Sawyer::Agent.new(endpoint, sawyer_options) do |http|
|
106
106
|
http.headers[:accept] = default_media_type
|
107
|
-
http.headers[:content_type] =
|
107
|
+
http.headers[:content_type] = 'application/json'
|
108
108
|
http.headers[:user_agent] = user_agent
|
109
|
+
http_cache_middleware = http.builder.handlers.delete(Faraday::HttpCache) if Faraday.const_defined?(:HttpCache)
|
109
110
|
if basic_authenticated?
|
110
|
-
http.
|
111
|
+
http.request(*FARADAY_BASIC_AUTH_KEYS, @login, @password)
|
111
112
|
elsif token_authenticated?
|
112
|
-
http.authorization 'token', @access_token
|
113
|
+
http.request :authorization, 'token', @access_token
|
113
114
|
elsif bearer_authenticated?
|
114
|
-
http.authorization 'Bearer', @bearer_token
|
115
|
+
http.request :authorization, 'Bearer', @bearer_token
|
115
116
|
elsif application_authenticated?
|
116
|
-
http.
|
117
|
+
http.request(*FARADAY_BASIC_AUTH_KEYS, @client_id, @client_secret)
|
117
118
|
end
|
119
|
+
http.builder.handlers.push(http_cache_middleware) unless http_cache_middleware.nil?
|
118
120
|
end
|
119
121
|
end
|
120
122
|
|
@@ -122,7 +124,7 @@ module Octokit
|
|
122
124
|
#
|
123
125
|
# @return [Sawyer::Resource]
|
124
126
|
def root
|
125
|
-
get
|
127
|
+
get '/'
|
126
128
|
end
|
127
129
|
|
128
130
|
# Response for last HTTP request
|
@@ -154,10 +156,10 @@ module Octokit
|
|
154
156
|
end
|
155
157
|
|
156
158
|
@last_response = response = agent.call(method, Addressable::URI.parse(path.to_s).normalize.to_s, data, options)
|
157
|
-
response
|
158
|
-
rescue Octokit::Error =>
|
159
|
+
response_data_correctly_encoded(response)
|
160
|
+
rescue Octokit::Error => e
|
159
161
|
@last_response = nil
|
160
|
-
raise
|
162
|
+
raise e
|
161
163
|
end
|
162
164
|
|
163
165
|
# Executes the request, checking if it was successful
|
@@ -170,21 +172,20 @@ module Octokit
|
|
170
172
|
false
|
171
173
|
end
|
172
174
|
|
173
|
-
|
174
175
|
def sawyer_options
|
175
176
|
opts = {
|
176
|
-
:
|
177
|
+
links_parser: Sawyer::LinkParsers::Simple.new
|
177
178
|
}
|
178
179
|
conn_opts = @connection_options
|
179
|
-
conn_opts[:builder] = @middleware if @middleware
|
180
|
+
conn_opts[:builder] = @middleware.dup if @middleware
|
180
181
|
conn_opts[:proxy] = @proxy if @proxy
|
181
182
|
if conn_opts[:ssl].nil?
|
182
|
-
conn_opts[:ssl] = { :
|
183
|
+
conn_opts[:ssl] = { verify_mode: @ssl_verify_mode } if @ssl_verify_mode
|
183
184
|
else
|
184
185
|
verify = @connection_options[:ssl][:verify]
|
185
186
|
conn_opts[:ssl] = {
|
186
|
-
:
|
187
|
-
:
|
187
|
+
verify: verify,
|
188
|
+
verify_mode: verify == false ? 0 : @ssl_verify_mode
|
188
189
|
}
|
189
190
|
end
|
190
191
|
opts[:faraday] = Faraday.new(conn_opts)
|
@@ -194,18 +195,26 @@ module Octokit
|
|
194
195
|
|
195
196
|
def parse_query_and_convenience_headers(options)
|
196
197
|
options = options.dup
|
197
|
-
headers = options.delete(:headers) {
|
198
|
+
headers = options.delete(:headers) { {} }
|
198
199
|
CONVENIENCE_HEADERS.each do |h|
|
199
200
|
if header = options.delete(h)
|
200
201
|
headers[h] = header
|
201
202
|
end
|
202
203
|
end
|
203
204
|
query = options.delete(:query)
|
204
|
-
opts = {:
|
205
|
-
opts[:query].merge!(query) if query
|
205
|
+
opts = { query: options }
|
206
|
+
opts[:query].merge!(query) if query.is_a?(Hash)
|
206
207
|
opts[:headers] = headers unless headers.empty?
|
207
208
|
|
208
209
|
opts
|
209
210
|
end
|
211
|
+
|
212
|
+
def response_data_correctly_encoded(response)
|
213
|
+
content_type = response.headers.fetch('content-type', '')
|
214
|
+
return response.data unless content_type.include?('charset') && response.data.is_a?(String)
|
215
|
+
|
216
|
+
reported_encoding = content_type.match(/charset=([^ ]+)/)[1]
|
217
|
+
response.data.force_encoding(reported_encoding)
|
218
|
+
end
|
210
219
|
end
|
211
220
|
end
|