octokit 4.22.0 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +113 -75
- data/Rakefile +20 -14
- data/lib/ext/sawyer/relation.rb +4 -2
- data/lib/octokit/arguments.rb +2 -2
- data/lib/octokit/authentication.rb +10 -3
- data/lib/octokit/client/actions_artifacts.rb +71 -0
- data/lib/octokit/client/actions_secrets.rb +10 -9
- 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 +26 -26
- data/lib/octokit/client/checks.rb +18 -9
- data/lib/octokit/client/code_scanning.rb +53 -0
- data/lib/octokit/client/codespaces_secrets.rb +59 -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 +20 -21
- data/lib/octokit/client/dependabot_secrets.rb +59 -0
- 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/environments.rb +55 -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 +0 -6
- 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/pub_sub_hubbub.rb +15 -15
- data/lib/octokit/client/pull_requests.rb +54 -42
- data/lib/octokit/client/rate_limit.rb +9 -11
- data/lib/octokit/client/reactions.rb +13 -16
- data/lib/octokit/client/refs.rb +14 -17
- data/lib/octokit/client/releases.rb +13 -13
- data/lib/octokit/client/repositories.rb +49 -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 +27 -33
- data/lib/octokit/client.rb +40 -16
- data/lib/octokit/configurable.rb +34 -30
- data/lib/octokit/connection.rb +28 -21
- data/lib/octokit/default.rb +48 -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 +32 -32
- data/lib/octokit/enterprise_management_console_client.rb +8 -2
- data/lib/octokit/error.rb +45 -34
- data/lib/octokit/gist.rb +3 -4
- data/lib/octokit/middleware/follow_redirects.rb +12 -11
- data/lib/octokit/organization.rb +3 -1
- data/lib/octokit/rate_limit.rb +8 -6
- data/lib/octokit/repo_arguments.rb +2 -3
- data/lib/octokit/repository.rb +24 -24
- 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 +15 -8
- data/octokit.gemspec +12 -11
- metadata +20 -33
- data/lib/octokit/client/authorizations.rb +0 -182
- data/lib/octokit/preview.rb +0 -46
@@ -1,34 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Octokit
|
2
4
|
class EnterpriseManagementConsoleClient
|
3
|
-
|
4
5
|
# Methods for the Enterprise Management Console API
|
5
6
|
#
|
6
7
|
# @see https://developer.github.com/v3/enterprise-admin/management_console/
|
7
8
|
module ManagementConsole
|
8
|
-
|
9
9
|
# Uploads a license for the first time
|
10
10
|
#
|
11
11
|
# @param license [String] The path to your .ghl license file.
|
12
12
|
# @param settings [Hash] A hash configuration of the initial settings.
|
13
13
|
#
|
14
|
-
# @see
|
14
|
+
# @see https://docs.github.com/en/enterprise-server@3.4/rest/enterprise-admin/management-console#create-a-github-license
|
15
15
|
# @return nil
|
16
16
|
def upload_license(license, settings = nil)
|
17
17
|
conn = faraday_configuration
|
18
18
|
|
19
|
-
params = {
|
19
|
+
params = {}
|
20
20
|
params[:license] = Faraday::UploadIO.new(license, 'binary')
|
21
21
|
params[:password] = @management_console_password
|
22
|
-
params[:settings] =
|
22
|
+
params[:settings] = settings.to_json.to_s unless settings.nil?
|
23
23
|
|
24
|
-
@last_response = conn.post(
|
24
|
+
@last_response = conn.post('/setup/api/start', params)
|
25
25
|
end
|
26
26
|
|
27
27
|
# Start a configuration process.
|
28
28
|
#
|
29
29
|
# @return nil
|
30
30
|
def start_configuration
|
31
|
-
post
|
31
|
+
post '/setup/api/configure', password_hash
|
32
32
|
end
|
33
33
|
|
34
34
|
# Upgrade an Enterprise installation
|
@@ -39,27 +39,27 @@ module Octokit
|
|
39
39
|
def upgrade(license)
|
40
40
|
conn = faraday_configuration
|
41
41
|
|
42
|
-
params = {
|
42
|
+
params = {}
|
43
43
|
params[:license] = Faraday::UploadIO.new(license, 'binary')
|
44
44
|
params[:api_key] = @management_console_password
|
45
|
-
@last_response = conn.post(
|
45
|
+
@last_response = conn.post('/setup/api/upgrade', params)
|
46
46
|
end
|
47
47
|
|
48
48
|
# Get information about the Enterprise installation
|
49
49
|
#
|
50
50
|
# @return [Sawyer::Resource] The installation information
|
51
51
|
def config_status
|
52
|
-
get
|
52
|
+
get '/setup/api/configcheck', password_hash
|
53
53
|
end
|
54
|
-
alias
|
54
|
+
alias config_check config_status
|
55
55
|
|
56
56
|
# Get information about the Enterprise installation
|
57
57
|
#
|
58
58
|
# @return [Sawyer::Resource] The settings
|
59
59
|
def settings
|
60
|
-
get
|
60
|
+
get '/setup/api/settings', password_hash
|
61
61
|
end
|
62
|
-
alias
|
62
|
+
alias get_settings settings
|
63
63
|
|
64
64
|
# Modify the Enterprise settings
|
65
65
|
#
|
@@ -68,17 +68,17 @@ module Octokit
|
|
68
68
|
# @return [nil]
|
69
69
|
def edit_settings(settings)
|
70
70
|
queries = password_hash
|
71
|
-
queries[:query][:settings] =
|
72
|
-
put
|
71
|
+
queries[:query][:settings] = settings.to_json.to_s
|
72
|
+
put '/setup/api/settings', queries
|
73
73
|
end
|
74
74
|
|
75
75
|
# Get information about the Enterprise maintenance status
|
76
76
|
#
|
77
77
|
# @return [Sawyer::Resource] The maintenance status
|
78
78
|
def maintenance_status
|
79
|
-
get
|
79
|
+
get '/setup/api/maintenance', password_hash
|
80
80
|
end
|
81
|
-
alias
|
81
|
+
alias get_maintenance_status maintenance_status
|
82
82
|
|
83
83
|
# Start (or turn off) the Enterprise maintenance mode
|
84
84
|
#
|
@@ -86,18 +86,18 @@ module Octokit
|
|
86
86
|
# @return [nil]
|
87
87
|
def set_maintenance_status(maintenance)
|
88
88
|
queries = password_hash
|
89
|
-
queries[:query][:maintenance] =
|
90
|
-
post
|
89
|
+
queries[:query][:maintenance] = maintenance.to_json.to_s
|
90
|
+
post '/setup/api/maintenance', queries
|
91
91
|
end
|
92
|
-
alias
|
92
|
+
alias edit_maintenance_status set_maintenance_status
|
93
93
|
|
94
94
|
# Fetch the authorized SSH keys on the Enterprise install
|
95
95
|
#
|
96
96
|
# @return [Sawyer::Resource] An array of authorized SSH keys
|
97
97
|
def authorized_keys
|
98
|
-
get
|
98
|
+
get '/setup/api/settings/authorized-keys', password_hash
|
99
99
|
end
|
100
|
-
alias
|
100
|
+
alias get_authorized_keys authorized_keys
|
101
101
|
|
102
102
|
# Add an authorized SSH keys on the Enterprise install
|
103
103
|
#
|
@@ -108,7 +108,7 @@ module Octokit
|
|
108
108
|
case key
|
109
109
|
when String
|
110
110
|
if File.exist?(key)
|
111
|
-
key = File.open(key,
|
111
|
+
key = File.open(key, 'r')
|
112
112
|
content = key.read.strip
|
113
113
|
key.close
|
114
114
|
else
|
@@ -120,7 +120,7 @@ module Octokit
|
|
120
120
|
end
|
121
121
|
|
122
122
|
queries[:query][:authorized_key] = content
|
123
|
-
post
|
123
|
+
post '/setup/api/settings/authorized-keys', queries
|
124
124
|
end
|
125
125
|
|
126
126
|
# Removes an authorized SSH keys from the Enterprise install
|
@@ -132,7 +132,7 @@ module Octokit
|
|
132
132
|
case key
|
133
133
|
when String
|
134
134
|
if File.exist?(key)
|
135
|
-
key = File.open(key,
|
135
|
+
key = File.open(key, 'r')
|
136
136
|
content = key.read.strip
|
137
137
|
key.close
|
138
138
|
else
|
@@ -144,27 +144,27 @@ module Octokit
|
|
144
144
|
end
|
145
145
|
|
146
146
|
queries[:query][:authorized_key] = content
|
147
|
-
delete
|
147
|
+
delete '/setup/api/settings/authorized-keys', queries
|
148
148
|
end
|
149
|
-
alias
|
150
|
-
|
149
|
+
alias delete_authorized_key remove_authorized_key
|
151
150
|
end
|
151
|
+
|
152
152
|
private
|
153
153
|
|
154
154
|
def password_hash
|
155
|
-
{ :
|
155
|
+
{ query: { api_key: @management_console_password } }
|
156
156
|
end
|
157
157
|
|
158
158
|
# We fall back to raw Faraday for handling the licenses because I'm suspicious
|
159
|
-
# that Sawyer isn't handling binary POSTs correctly:
|
159
|
+
# that Sawyer isn't handling binary POSTs correctly: https://github.com/lostisland/sawyer/blob/03fca4c020f465ec42856d0486ec3991859b0aed/lib/sawyer/agent.rb#L85
|
160
160
|
def faraday_configuration
|
161
|
-
@faraday_configuration ||= Faraday.new(:
|
161
|
+
@faraday_configuration ||= Faraday.new(url: @management_console_endpoint) do |http|
|
162
162
|
http.headers[:user_agent] = user_agent
|
163
163
|
http.request :multipart
|
164
164
|
http.request :url_encoded
|
165
165
|
|
166
166
|
# Disabling SSL is essential for certain self-hosted Enterprise instances
|
167
|
-
if
|
167
|
+
if connection_options[:ssl] && !connection_options[:ssl][:verify]
|
168
168
|
http.ssl[:verify] = false
|
169
169
|
end
|
170
170
|
|
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'octokit/configurable'
|
2
4
|
require 'octokit/connection'
|
3
5
|
require 'octokit/warnable'
|
4
6
|
require 'octokit/enterprise_management_console_client/management_console'
|
5
7
|
|
6
8
|
module Octokit
|
7
|
-
|
8
9
|
# EnterpriseManagementConsoleClient is only meant to be used by GitHub Enterprise Admins
|
9
10
|
# and provides access to the management console API endpoints.
|
10
11
|
#
|
@@ -12,7 +13,6 @@ module Octokit
|
|
12
13
|
# and GitHub Enterprise.
|
13
14
|
# @see https://developer.github.com/v3/enterprise-admin/management_console/
|
14
15
|
class EnterpriseManagementConsoleClient
|
15
|
-
|
16
16
|
include Octokit::Configurable
|
17
17
|
include Octokit::Connection
|
18
18
|
include Octokit::Warnable
|
@@ -20,7 +20,13 @@ module Octokit
|
|
20
20
|
|
21
21
|
def initialize(options = {})
|
22
22
|
# Use options passed in, but fall back to module defaults
|
23
|
+
# rubocop:disable Style/HashEachMethods
|
24
|
+
#
|
25
|
+
# This may look like a `.keys.each` which should be replaced with `#each_key`, but
|
26
|
+
# this doesn't actually work, since `#keys` is just a method we've defined ourselves.
|
27
|
+
# The class doesn't fulfill the whole `Enumerable` contract.
|
23
28
|
Octokit::Configurable.keys.each do |key|
|
29
|
+
# rubocop:enable Style/HashEachMethods
|
24
30
|
instance_variable_set(:"@#{key}", options[key] || Octokit.instance_variable_get(:"@#{key}"))
|
25
31
|
end
|
26
32
|
end
|
data/lib/octokit/error.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Octokit
|
2
4
|
# Custom error class for rescuing from all GitHub errors
|
3
5
|
class Error < StandardError
|
4
6
|
attr_reader :context
|
7
|
+
|
5
8
|
# Returns the appropriate Octokit::Error subclass based
|
6
9
|
# on status and response message
|
7
10
|
#
|
@@ -34,13 +37,13 @@ module Octokit
|
|
34
37
|
end
|
35
38
|
end
|
36
39
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
def build_error_context
|
41
|
+
if RATE_LIMITED_ERRORS.include?(self.class)
|
42
|
+
@context = Octokit::RateLimit.from_response(@response)
|
43
|
+
end
|
44
|
+
end
|
42
45
|
|
43
|
-
def initialize(response=nil)
|
46
|
+
def initialize(response = nil)
|
44
47
|
@response = response
|
45
48
|
super(build_error_message)
|
46
49
|
build_error_context
|
@@ -55,7 +58,9 @@ module Octokit
|
|
55
58
|
|
56
59
|
# Returns most appropriate error for 401 HTTP status code
|
57
60
|
# @private
|
61
|
+
# rubocop:disable Naming/VariableNumber
|
58
62
|
def self.error_for_401(headers)
|
63
|
+
# rubocop:enbale Naming/VariableNumber
|
59
64
|
if Octokit::OneTimePasswordRequired.required_header(headers)
|
60
65
|
Octokit::OneTimePasswordRequired
|
61
66
|
else
|
@@ -66,25 +71,27 @@ module Octokit
|
|
66
71
|
# Returns most appropriate error for 403 HTTP status code
|
67
72
|
# @private
|
68
73
|
def self.error_for_403(body)
|
69
|
-
|
74
|
+
# rubocop:enable Naming/VariableNumber
|
75
|
+
case body
|
76
|
+
when /rate limit exceeded/i, /exceeded a secondary rate limit/i
|
70
77
|
Octokit::TooManyRequests
|
71
|
-
|
78
|
+
when /login attempts exceeded/i
|
72
79
|
Octokit::TooManyLoginAttempts
|
73
|
-
|
80
|
+
when /(returns|for) blobs (up to|between) [0-9-]+ MB/i
|
74
81
|
Octokit::TooLargeContent
|
75
|
-
|
82
|
+
when /abuse/i
|
76
83
|
Octokit::AbuseDetected
|
77
|
-
|
84
|
+
when /repository access blocked/i
|
78
85
|
Octokit::RepositoryUnavailable
|
79
|
-
|
86
|
+
when /email address must be verified/i
|
80
87
|
Octokit::UnverifiedEmail
|
81
|
-
|
88
|
+
when /account was suspended/i
|
82
89
|
Octokit::AccountSuspended
|
83
|
-
|
90
|
+
when /billing issue/i
|
84
91
|
Octokit::BillingIssue
|
85
|
-
|
92
|
+
when /Resource protected by organization SAML enforcement/i
|
86
93
|
Octokit::SAMLProtected
|
87
|
-
|
94
|
+
when /suspended your access|This installation has been suspended/i
|
88
95
|
Octokit::InstallationSuspended
|
89
96
|
else
|
90
97
|
Octokit::Forbidden
|
@@ -93,7 +100,9 @@ module Octokit
|
|
93
100
|
|
94
101
|
# Return most appropriate error for 404 HTTP status code
|
95
102
|
# @private
|
103
|
+
# rubocop:disable Naming/VariableNumber
|
96
104
|
def self.error_for_404(body)
|
105
|
+
# rubocop:enable Naming/VariableNumber
|
97
106
|
if body =~ /Branch not protected/i
|
98
107
|
Octokit::BranchNotProtected
|
99
108
|
else
|
@@ -103,7 +112,9 @@ module Octokit
|
|
103
112
|
|
104
113
|
# Return most appropriate error for 422 HTTP status code
|
105
114
|
# @private
|
115
|
+
# rubocop:disable Naming/VariableNumber
|
106
116
|
def self.error_for_422(body)
|
117
|
+
# rubocop:enable Naming/VariableNumber
|
107
118
|
if body =~ /PullRequestReviewComment/i && body =~ /(commit_id|end_commit_oid) is not part of the pull request/i
|
108
119
|
Octokit::CommitIsNotPartOfPullRequest
|
109
120
|
elsif body =~ /Path diff too large/i
|
@@ -116,7 +127,7 @@ module Octokit
|
|
116
127
|
# Array of validation errors
|
117
128
|
# @return [Array<Hash>] Error info
|
118
129
|
def errors
|
119
|
-
if data
|
130
|
+
if data.is_a?(Hash)
|
120
131
|
data[:errors] || []
|
121
132
|
else
|
122
133
|
[]
|
@@ -150,15 +161,13 @@ module Octokit
|
|
150
161
|
@data ||=
|
151
162
|
if (body = @response[:body]) && !body.empty?
|
152
163
|
if body.is_a?(String) &&
|
153
|
-
|
154
|
-
|
164
|
+
@response[:response_headers] &&
|
165
|
+
@response[:response_headers][:content_type] =~ /json/
|
155
166
|
|
156
167
|
Sawyer::Agent.serializer.decode(body)
|
157
168
|
else
|
158
169
|
body
|
159
170
|
end
|
160
|
-
else
|
161
|
-
nil
|
162
171
|
end
|
163
172
|
end
|
164
173
|
|
@@ -178,10 +187,10 @@ module Octokit
|
|
178
187
|
def response_error_summary
|
179
188
|
return nil unless data.is_a?(Hash) && !Array(data[:errors]).empty?
|
180
189
|
|
181
|
-
summary = "\nError summary:\n"
|
190
|
+
summary = +"\nError summary:\n"
|
182
191
|
summary << data[:errors].map do |error|
|
183
192
|
if error.is_a? Hash
|
184
|
-
error.map { |k,v| " #{k}: #{v}" }
|
193
|
+
error.map { |k, v| " #{k}: #{v}" }
|
185
194
|
else
|
186
195
|
" #{error}"
|
187
196
|
end
|
@@ -193,19 +202,21 @@ module Octokit
|
|
193
202
|
def build_error_message
|
194
203
|
return nil if @response.nil?
|
195
204
|
|
196
|
-
message =
|
197
|
-
message << redact_url(@response[:url].to_s)
|
205
|
+
message = +"#{@response[:method].to_s.upcase} "
|
206
|
+
message << "#{redact_url(@response[:url].to_s.dup)}: "
|
198
207
|
message << "#{@response[:status]} - "
|
199
|
-
message <<
|
200
|
-
message <<
|
201
|
-
message <<
|
208
|
+
message << response_message.to_s unless response_message.nil?
|
209
|
+
message << response_error.to_s unless response_error.nil?
|
210
|
+
message << response_error_summary.to_s unless response_error_summary.nil?
|
202
211
|
message << " // See: #{documentation_url}" unless documentation_url.nil?
|
203
212
|
message
|
204
213
|
end
|
205
214
|
|
206
215
|
def redact_url(url_string)
|
207
|
-
%w[client_secret access_token].each do |token|
|
208
|
-
|
216
|
+
%w[client_secret access_token api_key].each do |token|
|
217
|
+
if url_string.include? token
|
218
|
+
url_string.gsub!(/#{token}=\S+/, "#{token}=(redacted)")
|
219
|
+
end
|
209
220
|
end
|
210
221
|
url_string
|
211
222
|
end
|
@@ -223,10 +234,10 @@ module Octokit
|
|
223
234
|
# Raised when GitHub returns a 401 HTTP status code
|
224
235
|
# and headers include "X-GitHub-OTP"
|
225
236
|
class OneTimePasswordRequired < ClientError
|
226
|
-
|
227
|
-
OTP_DELIVERY_PATTERN = /required; (\w+)/i
|
237
|
+
# @private
|
238
|
+
OTP_DELIVERY_PATTERN = /required; (\w+)/i.freeze
|
228
239
|
|
229
|
-
|
240
|
+
# @private
|
230
241
|
def self.required_header(headers)
|
231
242
|
OTP_DELIVERY_PATTERN.match headers['X-GitHub-OTP'].to_s
|
232
243
|
end
|
@@ -348,5 +359,5 @@ module Octokit
|
|
348
359
|
# Raised when a repository is created with an invalid format
|
349
360
|
class InvalidRepository < ArgumentError; end
|
350
361
|
|
351
|
-
RATE_LIMITED_ERRORS = [Octokit::TooManyRequests, Octokit::AbuseDetected]
|
362
|
+
RATE_LIMITED_ERRORS = [Octokit::TooManyRequests, Octokit::AbuseDetected].freeze
|
352
363
|
end
|
data/lib/octokit/gist.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module Octokit
|
3
4
|
# Class to parse and create Gist URLs
|
4
5
|
class Gist
|
5
|
-
|
6
6
|
# !@attribute id
|
7
7
|
# @return [String] Gist ID
|
8
8
|
attr_accessor :id
|
@@ -10,7 +10,7 @@ module Octokit
|
|
10
10
|
# Instantiate {Gist} object from Gist URL
|
11
11
|
# @ return [Gist]
|
12
12
|
def self.from_url(url)
|
13
|
-
Gist.new(URI.parse(url).path[1
|
13
|
+
Gist.new(URI.parse(url).path[1..])
|
14
14
|
end
|
15
15
|
|
16
16
|
def initialize(gist)
|
@@ -31,6 +31,5 @@ module Octokit
|
|
31
31
|
def url
|
32
32
|
"https://gist.github.com/#{@id}"
|
33
33
|
end
|
34
|
-
|
35
34
|
end
|
36
35
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'faraday'
|
2
4
|
require 'set'
|
3
5
|
|
@@ -7,9 +9,7 @@ require 'set'
|
|
7
9
|
# https://github.com/lostisland/faraday_middleware/blob/138766e/lib/faraday_middleware/response/follow_redirects.rb
|
8
10
|
|
9
11
|
module Octokit
|
10
|
-
|
11
12
|
module Middleware
|
12
|
-
|
13
13
|
# Public: Exception thrown when the maximum amount of requests is exceeded.
|
14
14
|
class RedirectLimitReached < Faraday::ClientError
|
15
15
|
attr_reader :response
|
@@ -30,13 +30,13 @@ module Octokit
|
|
30
30
|
# doesn't support parallelism.
|
31
31
|
class FollowRedirects < Faraday::Middleware
|
32
32
|
# HTTP methods for which 30x redirects can be followed
|
33
|
-
ALLOWED_METHODS = Set.new [
|
33
|
+
ALLOWED_METHODS = Set.new %i[head options get post put patch delete]
|
34
34
|
|
35
35
|
# HTTP redirect status codes that this middleware implements
|
36
36
|
REDIRECT_CODES = Set.new [301, 302, 303, 307]
|
37
37
|
|
38
38
|
# Keys in env hash which will get cleared between requests
|
39
|
-
ENV_TO_CLEAR = Set.new [
|
39
|
+
ENV_TO_CLEAR = Set.new %i[status response response_headers]
|
40
40
|
|
41
41
|
# Default value for max redirects followed
|
42
42
|
FOLLOW_LIMIT = 3
|
@@ -44,7 +44,7 @@ module Octokit
|
|
44
44
|
# Regex that matches characters that need to be escaped in URLs, sans
|
45
45
|
# the "%" character which we assume already represents an escaped
|
46
46
|
# sequence.
|
47
|
-
URI_UNSAFE =
|
47
|
+
URI_UNSAFE = %r{[^\-_.!~*'()a-zA-Z\d;/?:@&=+$,\[\]%]}.freeze
|
48
48
|
|
49
49
|
# Public: Initialize the middleware.
|
50
50
|
#
|
@@ -64,7 +64,7 @@ module Octokit
|
|
64
64
|
private
|
65
65
|
|
66
66
|
def convert_to_get?(response)
|
67
|
-
|
67
|
+
!%i[head options].include?(response.env[:method]) &&
|
68
68
|
@convert_to_get.include?(response.status)
|
69
69
|
end
|
70
70
|
|
@@ -75,6 +75,7 @@ module Octokit
|
|
75
75
|
response.on_complete do |response_env|
|
76
76
|
if follow_redirect?(response_env, response)
|
77
77
|
raise(RedirectLimitReached, response) if follows.zero?
|
78
|
+
|
78
79
|
new_request_env = update_env(response_env, request_body, response)
|
79
80
|
response = perform_with_redirection(new_request_env, follows - 1)
|
80
81
|
end
|
@@ -84,12 +85,12 @@ module Octokit
|
|
84
85
|
|
85
86
|
def update_env(env, request_body, response)
|
86
87
|
original_url = env[:url]
|
87
|
-
env[:url] += safe_escape(response[
|
88
|
+
env[:url] += safe_escape(response['location'])
|
88
89
|
unless same_host?(original_url, env[:url])
|
89
90
|
# HACK: Faraday’s Authorization middlewares don’t touch the request if the `Authorization` header is set.
|
90
91
|
# This is a workaround to drop authentication info.
|
91
92
|
# See https://github.com/octokit/octokit.rb/pull/1359#issuecomment-925609697
|
92
|
-
env[:request_headers][
|
93
|
+
env[:request_headers]['Authorization'] = 'dummy'
|
93
94
|
end
|
94
95
|
|
95
96
|
if convert_to_get?(response)
|
@@ -125,9 +126,9 @@ module Octokit
|
|
125
126
|
# URI:HTTP using the `+` operator. Doesn't escape "%" characters so to not
|
126
127
|
# risk double-escaping.
|
127
128
|
def safe_escape(uri)
|
128
|
-
uri.to_s.gsub(URI_UNSAFE)
|
129
|
-
"
|
130
|
-
|
129
|
+
uri.to_s.gsub(URI_UNSAFE) do |match|
|
130
|
+
"%#{match.unpack('H2' * match.bytesize).join('%').upcase}"
|
131
|
+
end
|
131
132
|
end
|
132
133
|
end
|
133
134
|
end
|
data/lib/octokit/organization.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Octokit
|
2
4
|
# GitHub organization class to generate API path urls
|
3
5
|
class Organization
|
@@ -5,7 +7,7 @@ module Octokit
|
|
5
7
|
#
|
6
8
|
# @param org [String, Integer] GitHub organization login or id
|
7
9
|
# @return [String] Organization Api path
|
8
|
-
def self.path
|
10
|
+
def self.path(org)
|
9
11
|
case org
|
10
12
|
when String
|
11
13
|
"orgs/#{org}"
|
data/lib/octokit/rate_limit.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module Octokit
|
3
4
|
# Class for API Rate Limit info
|
4
5
|
#
|
5
6
|
# @!attribute [w] limit
|
@@ -13,17 +14,18 @@ module Octokit
|
|
13
14
|
#
|
14
15
|
# @see https://developer.github.com/v3/#rate-limiting
|
15
16
|
class RateLimit < Struct.new(:limit, :remaining, :resets_at, :resets_in)
|
16
|
-
|
17
17
|
# Get rate limit info from HTTP response
|
18
18
|
#
|
19
19
|
# @param response [#headers] HTTP response
|
20
20
|
# @return [RateLimit]
|
21
21
|
def self.from_response(response)
|
22
22
|
info = new
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
info.
|
23
|
+
headers = response.headers if response.respond_to?(:headers) && !response.headers.nil?
|
24
|
+
headers ||= response.response_headers if response.respond_to?(:response_headers) && !response.response_headers.nil?
|
25
|
+
if headers
|
26
|
+
info.limit = (headers['X-RateLimit-Limit'] || 1).to_i
|
27
|
+
info.remaining = (headers['X-RateLimit-Remaining'] || 1).to_i
|
28
|
+
info.resets_at = Time.at((headers['X-RateLimit-Reset'] || Time.now).to_i)
|
27
29
|
info.resets_in = [(info.resets_at - Time.now).to_i, 0].max
|
28
30
|
end
|
29
31
|
|
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module Octokit
|
3
4
|
# Class to extract options from Ruby arguments for
|
4
5
|
# Repository-related methods
|
5
6
|
class RepoArguments < Arguments
|
6
|
-
|
7
7
|
# !@attribute [r] repo
|
8
8
|
# @return [Repository]
|
9
9
|
attr_reader :repo
|
@@ -14,6 +14,5 @@ module Octokit
|
|
14
14
|
|
15
15
|
arguments
|
16
16
|
end
|
17
|
-
|
18
17
|
end
|
19
18
|
end
|