octokit 4.24.0 → 5.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 +3 -2
- data/Rakefile +5 -3
- data/lib/ext/sawyer/relation.rb +4 -2
- data/lib/octokit/arguments.rb +2 -2
- data/lib/octokit/authentication.rb +4 -5
- data/lib/octokit/client/actions_secrets.rb +2 -3
- data/lib/octokit/client/actions_workflow_runs.rb +2 -0
- data/lib/octokit/client/actions_workflows.rb +2 -1
- data/lib/octokit/client/apps.rb +26 -26
- data/lib/octokit/client/authorizations.rb +20 -17
- data/lib/octokit/client/checks.rb +5 -5
- 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 +25 -33
- data/lib/octokit/client/community_profile.rb +2 -2
- data/lib/octokit/client/contents.rb +20 -21
- data/lib/octokit/client/deployments.rb +6 -6
- data/lib/octokit/client/downloads.rb +5 -6
- data/lib/octokit/client/emojis.rb +3 -3
- data/lib/octokit/client/events.rb +4 -4
- 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 +10 -10
- data/lib/octokit/client/issues.rb +14 -14
- data/lib/octokit/client/labels.rb +6 -6
- data/lib/octokit/client/legacy_search.rb +3 -3
- data/lib/octokit/client/licenses.rb +3 -3
- 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 +0 -2
- data/lib/octokit/client/objects.rb +14 -14
- data/lib/octokit/client/organizations.rb +42 -42
- data/lib/octokit/client/pages.rb +3 -3
- data/lib/octokit/client/projects.rb +18 -19
- data/lib/octokit/client/pub_sub_hubbub.rb +15 -15
- data/lib/octokit/client/pull_requests.rb +41 -42
- data/lib/octokit/client/rate_limit.rb +9 -11
- data/lib/octokit/client/reactions.rb +6 -6
- data/lib/octokit/client/refs.rb +13 -14
- data/lib/octokit/client/releases.rb +13 -13
- data/lib/octokit/client/repositories.rb +36 -36
- data/lib/octokit/client/repository_invitations.rb +3 -3
- data/lib/octokit/client/reviews.rb +7 -7
- data/lib/octokit/client/say.rb +4 -5
- data/lib/octokit/client/search.rb +9 -9
- data/lib/octokit/client/service_status.rb +2 -2
- data/lib/octokit/client/source_import.rb +6 -6
- data/lib/octokit/client/stats.rb +10 -9
- data/lib/octokit/client/statuses.rb +5 -5
- data/lib/octokit/client/traffic.rb +2 -3
- data/lib/octokit/client/users.rb +27 -26
- data/lib/octokit/client.rb +25 -11
- data/lib/octokit/configurable.rb +33 -27
- data/lib/octokit/connection.rb +19 -20
- data/lib/octokit/default.rb +16 -15
- 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 +30 -30
- data/lib/octokit/enterprise_management_console_client.rb +8 -2
- data/lib/octokit/error.rb +23 -21
- data/lib/octokit/gist.rb +2 -3
- data/lib/octokit/middleware/follow_redirects.rb +12 -11
- data/lib/octokit/organization.rb +3 -1
- data/lib/octokit/preview.rb +29 -29
- data/lib/octokit/rate_limit.rb +3 -3
- data/lib/octokit/repo_arguments.rb +2 -3
- data/lib/octokit/repository.rb +23 -24
- data/lib/octokit/response/base_middleware.rb +2 -0
- data/lib/octokit/response/feed_parser.rb +3 -5
- data/lib/octokit/response/raise_error.rb +2 -2
- data/lib/octokit/user.rb +4 -2
- data/lib/octokit/version.rb +4 -2
- data/lib/octokit/warnable.rb +3 -6
- data/lib/octokit.rb +14 -6
- data/octokit.gemspec +11 -9
- metadata +23 -22
@@ -1,11 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Octokit
|
2
4
|
class Client
|
3
|
-
|
4
5
|
# Methods for the Traffic API
|
5
6
|
#
|
6
7
|
# @see https://developer.github.com/v3/repos/traffic/
|
7
8
|
module Traffic
|
8
|
-
|
9
9
|
# Get the top 10 referrers over the last 14 days
|
10
10
|
#
|
11
11
|
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
@@ -63,7 +63,6 @@ module Octokit
|
|
63
63
|
opts = ensure_api_media_type(:traffic, options)
|
64
64
|
get "#{Repository.path repo}/traffic/clones", opts
|
65
65
|
end
|
66
|
-
|
67
66
|
end
|
68
67
|
end
|
69
68
|
end
|
data/lib/octokit/client/users.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Octokit
|
2
4
|
class Client
|
3
|
-
|
4
5
|
# Methods for the Users API
|
5
6
|
#
|
6
7
|
# @see https://developer.github.com/v3/users/
|
7
8
|
module Users
|
8
|
-
|
9
9
|
# List all GitHub users
|
10
10
|
#
|
11
11
|
# This provides a list of every user, in the order that they signed up
|
@@ -19,7 +19,7 @@ module Octokit
|
|
19
19
|
#
|
20
20
|
# @return [Array<Sawyer::Resource>] List of GitHub users.
|
21
21
|
def all_users(options = {})
|
22
|
-
paginate
|
22
|
+
paginate 'users', options
|
23
23
|
end
|
24
24
|
|
25
25
|
# Get a single user
|
@@ -30,7 +30,7 @@ module Octokit
|
|
30
30
|
# @see https://developer.github.com/v3/users/#get-the-authenticated-user
|
31
31
|
# @example
|
32
32
|
# Octokit.user("sferik")
|
33
|
-
def user(user=nil, options = {})
|
33
|
+
def user(user = nil, options = {})
|
34
34
|
get User.path(user), options
|
35
35
|
end
|
36
36
|
|
@@ -45,14 +45,14 @@ module Octokit
|
|
45
45
|
# Octokit.exchange_code_for_token('aaaa', 'xxxx', 'yyyy', {:accept => 'application/json'})
|
46
46
|
def exchange_code_for_token(code, app_id = client_id, app_secret = client_secret, options = {})
|
47
47
|
options = options.merge({
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
48
|
+
code: code,
|
49
|
+
client_id: app_id,
|
50
|
+
client_secret: app_secret,
|
51
|
+
headers: {
|
52
|
+
content_type: 'application/json',
|
53
|
+
accept: 'application/json'
|
54
|
+
}
|
55
|
+
})
|
56
56
|
|
57
57
|
post "#{web_endpoint}login/oauth/access_token", options
|
58
58
|
end
|
@@ -84,7 +84,7 @@ module Octokit
|
|
84
84
|
# @example
|
85
85
|
# Octokit.update_user(:name => "Erik Michaels-Ober", :email => "sferik@gmail.com", :company => "Code for America", :location => "San Francisco", :hireable => false)
|
86
86
|
def update_user(options)
|
87
|
-
patch
|
87
|
+
patch 'user', options
|
88
88
|
end
|
89
89
|
|
90
90
|
# Get a user's followers.
|
@@ -96,7 +96,7 @@ module Octokit
|
|
96
96
|
# @see https://developer.github.com/v3/users/followers/#list-followers-of-a-user
|
97
97
|
# @example
|
98
98
|
# Octokit.followers('pengwynn')
|
99
|
-
def followers(user=login, options = {})
|
99
|
+
def followers(user = login, options = {})
|
100
100
|
paginate "#{User.path user}/followers", options
|
101
101
|
end
|
102
102
|
|
@@ -109,7 +109,7 @@ module Octokit
|
|
109
109
|
# @see https://developer.github.com/v3/users/followers/#list-users-followed-by-another-user
|
110
110
|
# @example
|
111
111
|
# Octokit.following('pengwynn')
|
112
|
-
def following(user=login, options = {})
|
112
|
+
def following(user = login, options = {})
|
113
113
|
paginate "#{User.path user}/following", options
|
114
114
|
end
|
115
115
|
|
@@ -174,7 +174,7 @@ module Octokit
|
|
174
174
|
# @see https://developer.github.com/v3/activity/starring/#list-repositories-being-starred
|
175
175
|
# @example
|
176
176
|
# Octokit.starred('pengwynn')
|
177
|
-
def starred(user=login, options = {})
|
177
|
+
def starred(user = login, options = {})
|
178
178
|
paginate user_path(user, 'starred'), options
|
179
179
|
end
|
180
180
|
|
@@ -227,7 +227,7 @@ module Octokit
|
|
227
227
|
# @example
|
228
228
|
# @client.keys
|
229
229
|
def keys(options = {})
|
230
|
-
paginate
|
230
|
+
paginate 'user/keys', options
|
231
231
|
end
|
232
232
|
|
233
233
|
# Get list of public keys for user.
|
@@ -253,7 +253,7 @@ module Octokit
|
|
253
253
|
# @example
|
254
254
|
# @client.add_key('Personal projects key', 'ssh-rsa AAA...')
|
255
255
|
def add_key(title, key, options = {})
|
256
|
-
post
|
256
|
+
post 'user/keys', options.merge({ title: title, key: key })
|
257
257
|
end
|
258
258
|
|
259
259
|
# Update a public key
|
@@ -297,7 +297,7 @@ module Octokit
|
|
297
297
|
# @example
|
298
298
|
# @client.emails
|
299
299
|
def emails(options = {})
|
300
|
-
paginate
|
300
|
+
paginate 'user/emails', options
|
301
301
|
end
|
302
302
|
|
303
303
|
# Add email address to user.
|
@@ -309,9 +309,9 @@ module Octokit
|
|
309
309
|
# @see https://developer.github.com/v3/users/emails/#add-email-addresses
|
310
310
|
# @example
|
311
311
|
# @client.add_email('new_email@user.com')
|
312
|
-
def add_email(email,
|
312
|
+
def add_email(email, _options = {})
|
313
313
|
email = Array(email)
|
314
|
-
post
|
314
|
+
post 'user/emails', email
|
315
315
|
end
|
316
316
|
|
317
317
|
# Remove email from user.
|
@@ -325,7 +325,7 @@ module Octokit
|
|
325
325
|
# @client.remove_email('old_email@user.com')
|
326
326
|
def remove_email(email)
|
327
327
|
email = Array(email)
|
328
|
-
boolean_from_response :delete,
|
328
|
+
boolean_from_response :delete, 'user/emails', email
|
329
329
|
end
|
330
330
|
|
331
331
|
# List repositories being watched by a user.
|
@@ -335,10 +335,10 @@ module Octokit
|
|
335
335
|
# @see https://developer.github.com/v3/activity/watching/#list-repositories-being-watched
|
336
336
|
# @example
|
337
337
|
# @client.subscriptions("pengwynn")
|
338
|
-
def subscriptions(user=login, options = {})
|
338
|
+
def subscriptions(user = login, options = {})
|
339
339
|
paginate user_path(user, 'subscriptions'), options
|
340
340
|
end
|
341
|
-
alias
|
341
|
+
alias watched subscriptions
|
342
342
|
|
343
343
|
# Initiates the generation of a migration archive.
|
344
344
|
#
|
@@ -354,7 +354,7 @@ module Octokit
|
|
354
354
|
def start_user_migration(repositories, options = {})
|
355
355
|
options = ensure_api_media_type(:migrations, options)
|
356
356
|
options[:repositories] = repositories
|
357
|
-
post
|
357
|
+
post 'user/migrations', options
|
358
358
|
end
|
359
359
|
|
360
360
|
# Lists the most recent migrations.
|
@@ -365,7 +365,7 @@ module Octokit
|
|
365
365
|
# @see https://docs.github.com/en/rest/reference/migrations#list-user-migrations
|
366
366
|
def user_migrations(options = {})
|
367
367
|
options = ensure_api_media_type(:migrations, options)
|
368
|
-
paginate
|
368
|
+
paginate 'user/migrations', options
|
369
369
|
end
|
370
370
|
|
371
371
|
# Fetches the status of a migration.
|
@@ -429,6 +429,7 @@ module Octokit
|
|
429
429
|
end
|
430
430
|
|
431
431
|
private
|
432
|
+
|
432
433
|
# convenience method for constructing a user specific path, if the user is logged in
|
433
434
|
def user_path(user, path)
|
434
435
|
if user == login && user_authenticated?
|
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'
|
@@ -64,12 +66,10 @@ require 'octokit/client/users'
|
|
64
66
|
require 'ext/sawyer/relation'
|
65
67
|
|
66
68
|
module Octokit
|
67
|
-
|
68
69
|
# Client for the GitHub API
|
69
70
|
#
|
70
71
|
# @see https://developer.github.com
|
71
72
|
class Client
|
72
|
-
|
73
73
|
include Octokit::Authentication
|
74
74
|
include Octokit::Configurable
|
75
75
|
include Octokit::Connection
|
@@ -128,11 +128,18 @@ module Octokit
|
|
128
128
|
include Octokit::Client::Users
|
129
129
|
|
130
130
|
# Header keys that can be passed in options hash to {#get},{#head}
|
131
|
-
CONVENIENCE_HEADERS = Set.new([
|
131
|
+
CONVENIENCE_HEADERS = Set.new(%i[accept content_type])
|
132
132
|
|
133
133
|
def initialize(options = {})
|
134
134
|
# Use options passed in, but fall back to module defaults
|
135
|
+
#
|
136
|
+
# rubocop:disable Style/HashEachMethods
|
137
|
+
#
|
138
|
+
# This may look like a `.keys.each` which should be replaced with `#each_key`, but
|
139
|
+
# this doesn't actually work, since `#keys` is just a method we've defined ourselves.
|
140
|
+
# The class doesn't fulfill the whole `Enumerable` contract.
|
135
141
|
Octokit::Configurable.keys.each do |key|
|
142
|
+
# rubocop:enable Style/HashEachMethods
|
136
143
|
value = options[key].nil? ? Octokit.instance_variable_get(:"@#{key}") : options[key]
|
137
144
|
instance_variable_set(:"@#{key}", value)
|
138
145
|
end
|
@@ -148,11 +155,17 @@ module Octokit
|
|
148
155
|
|
149
156
|
# mask password
|
150
157
|
inspected.gsub! @password, '*******' if @password
|
151
|
-
|
158
|
+
if @management_console_password
|
159
|
+
inspected.gsub! @management_console_password, '*******'
|
160
|
+
end
|
152
161
|
inspected.gsub! @bearer_token, '********' if @bearer_token
|
153
162
|
# Only show last 4 of token, secret
|
154
|
-
|
155
|
-
|
163
|
+
if @access_token
|
164
|
+
inspected.gsub! @access_token, "#{'*' * 36}#{@access_token[36..-1]}"
|
165
|
+
end
|
166
|
+
if @client_secret
|
167
|
+
inspected.gsub! @client_secret, "#{'*' * 36}#{@client_secret[36..-1]}"
|
168
|
+
end
|
156
169
|
|
157
170
|
inspected
|
158
171
|
end
|
@@ -170,11 +183,12 @@ module Octokit
|
|
170
183
|
# # GET https://foo:bar@api.github.com/
|
171
184
|
# client.get "/"
|
172
185
|
# end
|
173
|
-
def as_app(key = client_id, secret = client_secret
|
186
|
+
def as_app(key = client_id, secret = client_secret)
|
174
187
|
if key.to_s.empty? || secret.to_s.empty?
|
175
|
-
raise ApplicationCredentialsRequired,
|
188
|
+
raise ApplicationCredentialsRequired, 'client_id and client_secret required'
|
176
189
|
end
|
177
|
-
|
190
|
+
|
191
|
+
app_client = dup
|
178
192
|
app_client.client_id = app_client.client_secret = nil
|
179
193
|
app_client.login = key
|
180
194
|
app_client.password = secret
|
@@ -235,10 +249,10 @@ module Octokit
|
|
235
249
|
conn_opts[:url] = @api_endpoint
|
236
250
|
conn_opts[:builder] = @middleware.dup if @middleware
|
237
251
|
conn_opts[:proxy] = @proxy if @proxy
|
238
|
-
conn_opts[:ssl] = { :
|
252
|
+
conn_opts[:ssl] = { verify_mode: @ssl_verify_mode } if @ssl_verify_mode
|
239
253
|
conn = Faraday.new(conn_opts) do |http|
|
240
254
|
if basic_authenticated?
|
241
|
-
http.request
|
255
|
+
http.request(*FARADAY_BASIC_AUTH_KEYS, @login, @password)
|
242
256
|
elsif token_authenticated?
|
243
257
|
http.request :authorization, 'token', @access_token
|
244
258
|
elsif bearer_authenticated?
|
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
|
@@ -61,31 +62,30 @@ module Octokit
|
|
61
62
|
:management_console_endpoint, :management_console_password
|
62
63
|
|
63
64
|
class << self
|
64
|
-
|
65
65
|
# List of configurable keys for {Octokit::Client}
|
66
66
|
# @return [Array] of option keys
|
67
67
|
def keys
|
68
|
-
@keys ||= [
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
68
|
+
@keys ||= %i[
|
69
|
+
access_token
|
70
|
+
api_endpoint
|
71
|
+
auto_paginate
|
72
|
+
bearer_token
|
73
|
+
client_id
|
74
|
+
client_secret
|
75
|
+
connection_options
|
76
|
+
default_media_type
|
77
|
+
login
|
78
|
+
management_console_endpoint
|
79
|
+
management_console_password
|
80
|
+
middleware
|
81
|
+
netrc
|
82
|
+
netrc_file
|
83
|
+
per_page
|
84
|
+
password
|
85
|
+
proxy
|
86
|
+
ssl_verify_mode
|
87
|
+
user_agent
|
88
|
+
web_endpoint
|
89
89
|
]
|
90
90
|
end
|
91
91
|
end
|
@@ -97,7 +97,13 @@ module Octokit
|
|
97
97
|
|
98
98
|
# Reset configuration options to default values
|
99
99
|
def reset!
|
100
|
+
# rubocop:disable Style/HashEachMethods
|
101
|
+
#
|
102
|
+
# This may look like a `.keys.each` which should be replaced with `#each_key`, but
|
103
|
+
# this doesn't actually work, since `#keys` is just a method we've defined ourselves.
|
104
|
+
# The class doesn't fulfill the whole `Enumerable` contract.
|
100
105
|
Octokit::Configurable.keys.each do |key|
|
106
|
+
# rubocop:enable Style/HashEachMethods
|
101
107
|
instance_variable_set(:"@#{key}", Octokit::Default.options[key])
|
102
108
|
end
|
103
109
|
self
|
@@ -113,18 +119,18 @@ module Octokit
|
|
113
119
|
end
|
114
120
|
|
115
121
|
def api_endpoint
|
116
|
-
File.join(@api_endpoint,
|
122
|
+
File.join(@api_endpoint, '')
|
117
123
|
end
|
118
124
|
|
119
125
|
def management_console_endpoint
|
120
|
-
File.join(@management_console_endpoint,
|
126
|
+
File.join(@management_console_endpoint, '')
|
121
127
|
end
|
122
128
|
|
123
129
|
# Base URL for generated web URLs
|
124
130
|
#
|
125
131
|
# @return [String] Default: https://github.com/
|
126
132
|
def web_endpoint
|
127
|
-
File.join(@web_endpoint,
|
133
|
+
File.join(@web_endpoint, '')
|
128
134
|
end
|
129
135
|
|
130
136
|
def login
|
@@ -140,7 +146,7 @@ module Octokit
|
|
140
146
|
private
|
141
147
|
|
142
148
|
def options
|
143
|
-
Hash[Octokit::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}]
|
149
|
+
Hash[Octokit::Configurable.keys.map { |key| [key, instance_variable_get(:"@#{key}")] }]
|
144
150
|
end
|
145
151
|
|
146
152
|
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,16 +104,16 @@ 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
109
|
if basic_authenticated?
|
110
|
-
http.request
|
110
|
+
http.request(*FARADAY_BASIC_AUTH_KEYS, @login, @password)
|
111
111
|
elsif token_authenticated?
|
112
112
|
http.request :authorization, 'token', @access_token
|
113
113
|
elsif bearer_authenticated?
|
114
114
|
http.request :authorization, 'Bearer', @bearer_token
|
115
115
|
elsif application_authenticated?
|
116
|
-
http.request
|
116
|
+
http.request(*FARADAY_BASIC_AUTH_KEYS, @client_id, @client_secret)
|
117
117
|
end
|
118
118
|
end
|
119
119
|
end
|
@@ -122,7 +122,7 @@ module Octokit
|
|
122
122
|
#
|
123
123
|
# @return [Sawyer::Resource]
|
124
124
|
def root
|
125
|
-
get
|
125
|
+
get '/'
|
126
126
|
end
|
127
127
|
|
128
128
|
# Response for last HTTP request
|
@@ -155,9 +155,9 @@ module Octokit
|
|
155
155
|
|
156
156
|
@last_response = response = agent.call(method, Addressable::URI.parse(path.to_s).normalize.to_s, data, options)
|
157
157
|
response.data
|
158
|
-
rescue Octokit::Error =>
|
158
|
+
rescue Octokit::Error => e
|
159
159
|
@last_response = nil
|
160
|
-
raise
|
160
|
+
raise e
|
161
161
|
end
|
162
162
|
|
163
163
|
# Executes the request, checking if it was successful
|
@@ -170,21 +170,20 @@ module Octokit
|
|
170
170
|
false
|
171
171
|
end
|
172
172
|
|
173
|
-
|
174
173
|
def sawyer_options
|
175
174
|
opts = {
|
176
|
-
:
|
175
|
+
links_parser: Sawyer::LinkParsers::Simple.new
|
177
176
|
}
|
178
177
|
conn_opts = @connection_options
|
179
178
|
conn_opts[:builder] = @middleware.dup if @middleware
|
180
179
|
conn_opts[:proxy] = @proxy if @proxy
|
181
180
|
if conn_opts[:ssl].nil?
|
182
|
-
conn_opts[:ssl] = { :
|
181
|
+
conn_opts[:ssl] = { verify_mode: @ssl_verify_mode } if @ssl_verify_mode
|
183
182
|
else
|
184
183
|
verify = @connection_options[:ssl][:verify]
|
185
184
|
conn_opts[:ssl] = {
|
186
|
-
:
|
187
|
-
:
|
185
|
+
verify: verify,
|
186
|
+
verify_mode: verify == false ? 0 : @ssl_verify_mode
|
188
187
|
}
|
189
188
|
end
|
190
189
|
opts[:faraday] = Faraday.new(conn_opts)
|
@@ -194,15 +193,15 @@ module Octokit
|
|
194
193
|
|
195
194
|
def parse_query_and_convenience_headers(options)
|
196
195
|
options = options.dup
|
197
|
-
headers = options.delete(:headers) {
|
196
|
+
headers = options.delete(:headers) { {} }
|
198
197
|
CONVENIENCE_HEADERS.each do |h|
|
199
198
|
if header = options.delete(h)
|
200
199
|
headers[h] = header
|
201
200
|
end
|
202
201
|
end
|
203
202
|
query = options.delete(:query)
|
204
|
-
opts = {:
|
205
|
-
opts[:query].merge!(query) if query
|
203
|
+
opts = { query: options }
|
204
|
+
opts[:query].merge!(query) if query&.is_a?(Hash)
|
206
205
|
opts[:headers] = headers unless headers.empty?
|
207
206
|
|
208
207
|
opts
|
data/lib/octokit/default.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'octokit/middleware/follow_redirects'
|
2
4
|
require 'octokit/response/raise_error'
|
3
5
|
require 'octokit/response/feed_parser'
|
@@ -13,28 +15,29 @@ if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
|
|
13
15
|
end
|
14
16
|
|
15
17
|
module Octokit
|
16
|
-
|
17
18
|
# Default configuration options for {Client}
|
18
19
|
module Default
|
19
|
-
|
20
20
|
# Default API endpoint
|
21
|
-
API_ENDPOINT =
|
21
|
+
API_ENDPOINT = 'https://api.github.com'
|
22
22
|
|
23
23
|
# Default User Agent header string
|
24
|
-
USER_AGENT = "Octokit Ruby Gem #{Octokit::VERSION}"
|
24
|
+
USER_AGENT = "Octokit Ruby Gem #{Octokit::VERSION}"
|
25
25
|
|
26
26
|
# Default media type
|
27
|
-
MEDIA_TYPE =
|
27
|
+
MEDIA_TYPE = 'application/vnd.github.v3+json'
|
28
28
|
|
29
29
|
# Default WEB endpoint
|
30
|
-
WEB_ENDPOINT =
|
30
|
+
WEB_ENDPOINT = 'https://github.com'
|
31
31
|
|
32
32
|
# Default Faraday middleware stack
|
33
33
|
MIDDLEWARE = Faraday::RackBuilder.new do |builder|
|
34
34
|
# In Faraday 2.x, Faraday::Request::Retry was moved to a separate gem
|
35
35
|
# so we use it only when it's available.
|
36
|
-
|
37
|
-
|
36
|
+
if defined?(Faraday::Request::Retry)
|
37
|
+
builder.use Faraday::Request::Retry, exceptions: [Octokit::ServerError]
|
38
|
+
elsif defined?(Faraday::Retry::Middleware)
|
39
|
+
builder.use Faraday::Retry::Middleware, exceptions: [Octokit::ServerError]
|
40
|
+
end
|
38
41
|
|
39
42
|
builder.use Octokit::Middleware::FollowRedirects
|
40
43
|
builder.use Octokit::Response::RaiseError
|
@@ -43,11 +46,10 @@ module Octokit
|
|
43
46
|
end
|
44
47
|
|
45
48
|
class << self
|
46
|
-
|
47
49
|
# Configuration options
|
48
50
|
# @return [Hash]
|
49
51
|
def options
|
50
|
-
Hash[Octokit::Configurable.keys.map{|key| [key, send(key)]}]
|
52
|
+
Hash[Octokit::Configurable.keys.map { |key| [key, send(key)] }]
|
51
53
|
end
|
52
54
|
|
53
55
|
# Default access token from ENV
|
@@ -102,9 +104,9 @@ module Octokit
|
|
102
104
|
# @return [Hash]
|
103
105
|
def connection_options
|
104
106
|
{
|
105
|
-
:
|
106
|
-
:
|
107
|
-
:
|
107
|
+
headers: {
|
108
|
+
accept: default_media_type,
|
109
|
+
user_agent: user_agent
|
108
110
|
}
|
109
111
|
}
|
110
112
|
end
|
@@ -139,7 +141,7 @@ module Octokit
|
|
139
141
|
def per_page
|
140
142
|
page_size = ENV['OCTOKIT_PER_PAGE']
|
141
143
|
|
142
|
-
page_size
|
144
|
+
page_size&.to_i
|
143
145
|
end
|
144
146
|
|
145
147
|
# Default proxy server URI for Faraday connection from ENV
|
@@ -180,7 +182,6 @@ module Octokit
|
|
180
182
|
def netrc_file
|
181
183
|
ENV['OCTOKIT_NETRC_FILE'] || File.join(ENV['HOME'].to_s, '.netrc')
|
182
184
|
end
|
183
|
-
|
184
185
|
end
|
185
186
|
end
|
186
187
|
end
|