octokit 4.22.0 → 9.2.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 +117 -95
- 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 -26
- 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 +25 -33
- 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 +100 -56
- 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 +62 -16
- data/lib/octokit/client/refs.rb +14 -17
- 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 +42 -18
- data/lib/octokit/configurable.rb +51 -31
- data/lib/octokit/connection.rb +30 -21
- 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 +51 -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 +13 -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 +19 -31
- 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.request
|
264
|
+
http.request(*FARADAY_BASIC_AUTH_KEYS, @login, @password)
|
242
265
|
elsif token_authenticated?
|
243
266
|
http.request :authorization, 'token', @access_token
|
244
267
|
elsif bearer_authenticated?
|
245
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.request
|
111
|
+
http.request(*FARADAY_BASIC_AUTH_KEYS, @login, @password)
|
111
112
|
elsif token_authenticated?
|
112
113
|
http.request :authorization, 'token', @access_token
|
113
114
|
elsif bearer_authenticated?
|
114
115
|
http.request :authorization, 'Bearer', @bearer_token
|
115
116
|
elsif application_authenticated?
|
116
|
-
http.request
|
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
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
|
data/lib/octokit/default.rb
CHANGED
@@ -1,31 +1,46 @@
|
|
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'
|
4
6
|
require 'octokit/version'
|
7
|
+
require 'octokit/warnable'
|
5
8
|
|
6
|
-
|
9
|
+
if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
|
10
|
+
begin
|
11
|
+
require 'faraday/retry'
|
12
|
+
rescue LoadError
|
13
|
+
Octokit::Warnable.octokit_warn 'To use retry middleware with Faraday v2.0+, install `faraday-retry` gem'
|
14
|
+
end
|
15
|
+
end
|
7
16
|
|
17
|
+
module Octokit
|
8
18
|
# Default configuration options for {Client}
|
9
19
|
module Default
|
10
|
-
|
11
20
|
# Default API endpoint
|
12
|
-
API_ENDPOINT =
|
21
|
+
API_ENDPOINT = 'https://api.github.com'
|
13
22
|
|
14
23
|
# Default User Agent header string
|
15
|
-
USER_AGENT = "Octokit Ruby Gem #{Octokit::VERSION}"
|
24
|
+
USER_AGENT = "Octokit Ruby Gem #{Octokit::VERSION}"
|
16
25
|
|
17
26
|
# Default media type
|
18
|
-
MEDIA_TYPE =
|
27
|
+
MEDIA_TYPE = 'application/vnd.github.v3+json'
|
19
28
|
|
20
29
|
# Default WEB endpoint
|
21
|
-
WEB_ENDPOINT =
|
22
|
-
|
23
|
-
# In Faraday 0.9, Faraday::Builder was renamed to Faraday::RackBuilder
|
24
|
-
RACK_BUILDER_CLASS = defined?(Faraday::RackBuilder) ? Faraday::RackBuilder : Faraday::Builder
|
30
|
+
WEB_ENDPOINT = 'https://github.com'
|
25
31
|
|
26
32
|
# Default Faraday middleware stack
|
27
|
-
MIDDLEWARE =
|
28
|
-
|
33
|
+
MIDDLEWARE = Faraday::RackBuilder.new do |builder|
|
34
|
+
# In Faraday 2.x, Faraday::Request::Retry was moved to a separate gem
|
35
|
+
# so we use it only when it's available.
|
36
|
+
if defined?(Faraday::Request::Retry)
|
37
|
+
retry_exceptions = Faraday::Request::Retry::DEFAULT_EXCEPTIONS + [Octokit::ServerError]
|
38
|
+
builder.use Faraday::Request::Retry, exceptions: retry_exceptions
|
39
|
+
elsif defined?(Faraday::Retry::Middleware)
|
40
|
+
retry_exceptions = Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Octokit::ServerError]
|
41
|
+
builder.use Faraday::Retry::Middleware, exceptions: retry_exceptions
|
42
|
+
end
|
43
|
+
|
29
44
|
builder.use Octokit::Middleware::FollowRedirects
|
30
45
|
builder.use Octokit::Response::RaiseError
|
31
46
|
builder.use Octokit::Response::FeedParser
|
@@ -33,68 +48,85 @@ module Octokit
|
|
33
48
|
end
|
34
49
|
|
35
50
|
class << self
|
36
|
-
|
37
51
|
# Configuration options
|
38
52
|
# @return [Hash]
|
39
53
|
def options
|
40
|
-
|
54
|
+
Octokit::Configurable.keys.to_h { |key| [key, send(key)] }
|
41
55
|
end
|
42
56
|
|
43
57
|
# Default access token from ENV
|
44
58
|
# @return [String]
|
45
59
|
def access_token
|
46
|
-
ENV
|
60
|
+
ENV.fetch('OCTOKIT_ACCESS_TOKEN', nil)
|
47
61
|
end
|
48
62
|
|
49
63
|
# Default API endpoint from ENV or {API_ENDPOINT}
|
50
64
|
# @return [String]
|
51
65
|
def api_endpoint
|
52
|
-
ENV
|
66
|
+
ENV.fetch('OCTOKIT_API_ENDPOINT') { API_ENDPOINT }
|
53
67
|
end
|
54
68
|
|
55
69
|
# Default pagination preference from ENV
|
56
70
|
# @return [String]
|
57
71
|
def auto_paginate
|
58
|
-
ENV
|
72
|
+
ENV.fetch('OCTOKIT_AUTO_PAGINATE', nil)
|
59
73
|
end
|
60
74
|
|
61
75
|
# Default bearer token from ENV
|
62
76
|
# @return [String]
|
63
77
|
def bearer_token
|
64
|
-
ENV
|
78
|
+
ENV.fetch('OCTOKIT_BEARER_TOKEN', nil)
|
65
79
|
end
|
66
80
|
|
67
81
|
# Default OAuth app key from ENV
|
68
82
|
# @return [String]
|
69
83
|
def client_id
|
70
|
-
ENV
|
84
|
+
ENV.fetch('OCTOKIT_CLIENT_ID', nil)
|
71
85
|
end
|
72
86
|
|
73
87
|
# Default OAuth app secret from ENV
|
74
88
|
# @return [String]
|
75
89
|
def client_secret
|
76
|
-
ENV
|
90
|
+
ENV.fetch('OCTOKIT_SECRET', nil)
|
77
91
|
end
|
78
92
|
|
79
93
|
# Default management console password from ENV
|
80
94
|
# @return [String]
|
81
95
|
def management_console_password
|
82
|
-
ENV
|
96
|
+
ENV.fetch('OCTOKIT_ENTERPRISE_MANAGEMENT_CONSOLE_PASSWORD', nil)
|
83
97
|
end
|
84
98
|
|
85
99
|
# Default management console endpoint from ENV
|
86
100
|
# @return [String]
|
87
101
|
def management_console_endpoint
|
88
|
-
ENV
|
102
|
+
ENV.fetch('OCTOKIT_ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT', nil)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Default GHES Manage API endpoint from ENV
|
106
|
+
# @return [String]
|
107
|
+
def manage_ghes_endpoint
|
108
|
+
ENV.fetch('OCTOKIT_MANAGE_GHES_ENDPOINT', nil)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Default GHES Manage API username from ENV
|
112
|
+
# @return [String]
|
113
|
+
def manage_ghes_username
|
114
|
+
ENV.fetch('OCTOKIT_MANAGE_GHES_USERNAME', nil)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Default GHES Manage API password from ENV
|
118
|
+
# @return [String]
|
119
|
+
def manage_ghes_password
|
120
|
+
ENV.fetch('OCTOKIT_MANAGE_GHES_PASSWORD', nil)
|
89
121
|
end
|
90
122
|
|
91
123
|
# Default options for Faraday::Connection
|
92
124
|
# @return [Hash]
|
93
125
|
def connection_options
|
94
126
|
{
|
95
|
-
:
|
96
|
-
:
|
97
|
-
:
|
127
|
+
headers: {
|
128
|
+
accept: default_media_type,
|
129
|
+
user_agent: user_agent
|
98
130
|
}
|
99
131
|
}
|
100
132
|
end
|
@@ -102,13 +134,13 @@ module Octokit
|
|
102
134
|
# Default media type from ENV or {MEDIA_TYPE}
|
103
135
|
# @return [String]
|
104
136
|
def default_media_type
|
105
|
-
ENV
|
137
|
+
ENV.fetch('OCTOKIT_DEFAULT_MEDIA_TYPE') { MEDIA_TYPE }
|
106
138
|
end
|
107
139
|
|
108
140
|
# Default GitHub username for Basic Auth from ENV
|
109
141
|
# @return [String]
|
110
142
|
def login
|
111
|
-
ENV
|
143
|
+
ENV.fetch('OCTOKIT_LOGIN', nil)
|
112
144
|
end
|
113
145
|
|
114
146
|
# Default middleware stack for Faraday::Connection
|
@@ -121,21 +153,21 @@ module Octokit
|
|
121
153
|
# Default GitHub password for Basic Auth from ENV
|
122
154
|
# @return [String]
|
123
155
|
def password
|
124
|
-
ENV
|
156
|
+
ENV.fetch('OCTOKIT_PASSWORD', nil)
|
125
157
|
end
|
126
158
|
|
127
159
|
# Default pagination page size from ENV
|
128
160
|
# @return [Integer] Page size
|
129
161
|
def per_page
|
130
|
-
page_size = ENV
|
162
|
+
page_size = ENV.fetch('OCTOKIT_PER_PAGE', nil)
|
131
163
|
|
132
|
-
page_size
|
164
|
+
page_size&.to_i
|
133
165
|
end
|
134
166
|
|
135
167
|
# Default proxy server URI for Faraday connection from ENV
|
136
168
|
# @return [String]
|
137
169
|
def proxy
|
138
|
-
ENV
|
170
|
+
ENV.fetch('OCTOKIT_PROXY', nil)
|
139
171
|
end
|
140
172
|
|
141
173
|
# Default SSL verify mode from ENV
|
@@ -150,27 +182,26 @@ module Octokit
|
|
150
182
|
# Default User-Agent header string from ENV or {USER_AGENT}
|
151
183
|
# @return [String]
|
152
184
|
def user_agent
|
153
|
-
ENV
|
185
|
+
ENV.fetch('OCTOKIT_USER_AGENT') { USER_AGENT }
|
154
186
|
end
|
155
187
|
|
156
188
|
# Default web endpoint from ENV or {WEB_ENDPOINT}
|
157
189
|
# @return [String]
|
158
190
|
def web_endpoint
|
159
|
-
ENV
|
191
|
+
ENV.fetch('OCTOKIT_WEB_ENDPOINT') { WEB_ENDPOINT }
|
160
192
|
end
|
161
193
|
|
162
194
|
# Default behavior for reading .netrc file
|
163
195
|
# @return [Boolean]
|
164
196
|
def netrc
|
165
|
-
ENV
|
197
|
+
ENV.fetch('OCTOKIT_NETRC', false)
|
166
198
|
end
|
167
199
|
|
168
200
|
# Default path for .netrc file
|
169
201
|
# @return [String]
|
170
202
|
def netrc_file
|
171
|
-
ENV
|
203
|
+
ENV.fetch('OCTOKIT_NETRC_FILE') { File.join(Dir.home.to_s, '.netrc') }
|
172
204
|
end
|
173
|
-
|
174
205
|
end
|
175
206
|
end
|
176
207
|
end
|