octokit 3.8.0 → 4.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 +78 -5
- data/lib/octokit.rb +35 -9
- data/lib/octokit/client.rb +7 -196
- data/lib/octokit/client/commit_comments.rb +2 -2
- data/lib/octokit/client/contents.rb +15 -2
- data/lib/octokit/client/hooks.rb +9 -26
- data/lib/octokit/client/issues.rb +2 -1
- data/lib/octokit/client/licenses.rb +50 -0
- data/lib/octokit/client/organizations.rb +46 -6
- data/lib/octokit/client/pub_sub_hubbub.rb +1 -8
- data/lib/octokit/client/pull_requests.rb +2 -14
- data/lib/octokit/client/users.rb +1 -1
- data/lib/octokit/configurable.rb +19 -0
- data/lib/octokit/connection.rb +196 -0
- data/lib/octokit/default.rb +14 -0
- data/lib/octokit/enterprise_admin_client.rb +36 -0
- data/lib/octokit/enterprise_admin_client/admin_stats.rb +120 -0
- data/lib/octokit/enterprise_admin_client/license.rb +18 -0
- data/lib/octokit/enterprise_admin_client/search_indexing.rb +83 -0
- data/lib/octokit/enterprise_admin_client/users.rb +53 -0
- data/lib/octokit/enterprise_management_console_client.rb +50 -0
- data/lib/octokit/enterprise_management_console_client/management_console.rb +176 -0
- data/lib/octokit/middleware/follow_redirects.rb +131 -0
- data/lib/octokit/repository.rb +2 -0
- data/lib/octokit/version.rb +2 -2
- data/lib/octokit/warnable.rb +17 -0
- metadata +14 -4
- data/lib/octokit/backports/uri.rb +0 -56
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
# Adapted from lostisland/faraday_middleware. Trimmed down to just the logic
|
5
|
+
# that we need for octokit.rb.
|
6
|
+
#
|
7
|
+
# https://github.com/lostisland/faraday_middleware/blob/138766e/lib/faraday_middleware/response/follow_redirects.rb
|
8
|
+
|
9
|
+
module Octokit
|
10
|
+
|
11
|
+
module Middleware
|
12
|
+
|
13
|
+
# Public: Exception thrown when the maximum amount of requests is exceeded.
|
14
|
+
class RedirectLimitReached < Faraday::Error::ClientError
|
15
|
+
attr_reader :response
|
16
|
+
|
17
|
+
def initialize(response)
|
18
|
+
super "too many redirects; last one to: #{response['location']}"
|
19
|
+
@response = response
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Public: Follow HTTP 301, 302, 303, and 307 redirects.
|
24
|
+
#
|
25
|
+
# For HTTP 303, the original GET, POST, PUT, DELETE, or PATCH request gets
|
26
|
+
# converted into a GET. For HTTP 301, 302, and 307, the HTTP method remains
|
27
|
+
# unchanged.
|
28
|
+
#
|
29
|
+
# This middleware currently only works with synchronous requests; i.e. it
|
30
|
+
# doesn't support parallelism.
|
31
|
+
class FollowRedirects < Faraday::Middleware
|
32
|
+
# HTTP methods for which 30x redirects can be followed
|
33
|
+
ALLOWED_METHODS = Set.new [:head, :options, :get, :post, :put, :patch, :delete]
|
34
|
+
|
35
|
+
# HTTP redirect status codes that this middleware implements
|
36
|
+
REDIRECT_CODES = Set.new [301, 302, 303, 307]
|
37
|
+
|
38
|
+
# Keys in env hash which will get cleared between requests
|
39
|
+
ENV_TO_CLEAR = Set.new [:status, :response, :response_headers]
|
40
|
+
|
41
|
+
# Default value for max redirects followed
|
42
|
+
FOLLOW_LIMIT = 3
|
43
|
+
|
44
|
+
# Regex that matches characters that need to be escaped in URLs, sans
|
45
|
+
# the "%" character which we assume already represents an escaped
|
46
|
+
# sequence.
|
47
|
+
URI_UNSAFE = /[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]%]/
|
48
|
+
|
49
|
+
# Public: Initialize the middleware.
|
50
|
+
#
|
51
|
+
# options - An options Hash (default: {}):
|
52
|
+
# :limit - A Fixnum redirect limit (default: 3).
|
53
|
+
def initialize(app, options = {})
|
54
|
+
super(app)
|
55
|
+
@options = options
|
56
|
+
|
57
|
+
@convert_to_get = Set.new [303]
|
58
|
+
end
|
59
|
+
|
60
|
+
def call(env)
|
61
|
+
perform_with_redirection(env, follow_limit)
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def convert_to_get?(response)
|
67
|
+
![:head, :options].include?(response.env[:method]) &&
|
68
|
+
@convert_to_get.include?(response.status)
|
69
|
+
end
|
70
|
+
|
71
|
+
def perform_with_redirection(env, follows)
|
72
|
+
request_body = env[:body]
|
73
|
+
response = @app.call(env)
|
74
|
+
|
75
|
+
response.on_complete do |response_env|
|
76
|
+
if follow_redirect?(response_env, response)
|
77
|
+
raise(RedirectLimitReached, response) if follows.zero?
|
78
|
+
new_request_env = update_env(response_env, request_body, response)
|
79
|
+
response = perform_with_redirection(new_request_env, follows - 1)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
response
|
83
|
+
end
|
84
|
+
|
85
|
+
def update_env(env, request_body, response)
|
86
|
+
original_url = env[:url]
|
87
|
+
env[:url] += safe_escape(response["location"])
|
88
|
+
unless same_host?(original_url, env[:url])
|
89
|
+
env[:request_headers].delete("Authorization")
|
90
|
+
end
|
91
|
+
|
92
|
+
if convert_to_get?(response)
|
93
|
+
env[:method] = :get
|
94
|
+
env[:body] = nil
|
95
|
+
else
|
96
|
+
env[:body] = request_body
|
97
|
+
end
|
98
|
+
|
99
|
+
ENV_TO_CLEAR.each { |key| env.delete(key) }
|
100
|
+
|
101
|
+
env
|
102
|
+
end
|
103
|
+
|
104
|
+
def follow_redirect?(env, response)
|
105
|
+
ALLOWED_METHODS.include?(env[:method]) &&
|
106
|
+
REDIRECT_CODES.include?(response.status)
|
107
|
+
end
|
108
|
+
|
109
|
+
def follow_limit
|
110
|
+
@options.fetch(:limit, FOLLOW_LIMIT)
|
111
|
+
end
|
112
|
+
|
113
|
+
def same_host?(original_url, redirect_url)
|
114
|
+
original_uri = Addressable::URI.parse(original_url)
|
115
|
+
redirect_uri = Addressable::URI.parse(redirect_url)
|
116
|
+
|
117
|
+
redirect_uri.host.nil? || original_uri.host == redirect_uri.host
|
118
|
+
end
|
119
|
+
|
120
|
+
# Internal: Escapes unsafe characters from a URL which might be a path
|
121
|
+
# component only or a fully-qualified URI so that it can be joined onto a
|
122
|
+
# URI:HTTP using the `+` operator. Doesn't escape "%" characters so to not
|
123
|
+
# risk double-escaping.
|
124
|
+
def safe_escape(uri)
|
125
|
+
uri.to_s.gsub(URI_UNSAFE) { |match|
|
126
|
+
"%" + match.unpack("H2" * match.bytesize).join("%").upcase
|
127
|
+
}
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
data/lib/octokit/repository.rb
CHANGED
data/lib/octokit/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Octokit
|
2
|
+
|
3
|
+
# Allows warnings to be suppressed via environment variable.
|
4
|
+
module Warnable
|
5
|
+
|
6
|
+
# Wrapper around Kernel#warn to print warnings unless
|
7
|
+
# OCTOKIT_SILENT is set to true.
|
8
|
+
#
|
9
|
+
# @return [nil]
|
10
|
+
def octokit_warn(*message)
|
11
|
+
unless ENV['OCTOKIT_SILENT']
|
12
|
+
warn message
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octokit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wynn Netherland
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-06-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -63,7 +63,6 @@ files:
|
|
63
63
|
- lib/octokit.rb
|
64
64
|
- lib/octokit/arguments.rb
|
65
65
|
- lib/octokit/authentication.rb
|
66
|
-
- lib/octokit/backports/uri.rb
|
67
66
|
- lib/octokit/client.rb
|
68
67
|
- lib/octokit/client/authorizations.rb
|
69
68
|
- lib/octokit/client/commit_comments.rb
|
@@ -80,6 +79,7 @@ files:
|
|
80
79
|
- lib/octokit/client/issues.rb
|
81
80
|
- lib/octokit/client/labels.rb
|
82
81
|
- lib/octokit/client/legacy_search.rb
|
82
|
+
- lib/octokit/client/licenses.rb
|
83
83
|
- lib/octokit/client/markdown.rb
|
84
84
|
- lib/octokit/client/meta.rb
|
85
85
|
- lib/octokit/client/milestones.rb
|
@@ -100,9 +100,18 @@ files:
|
|
100
100
|
- lib/octokit/client/statuses.rb
|
101
101
|
- lib/octokit/client/users.rb
|
102
102
|
- lib/octokit/configurable.rb
|
103
|
+
- lib/octokit/connection.rb
|
103
104
|
- lib/octokit/default.rb
|
105
|
+
- lib/octokit/enterprise_admin_client.rb
|
106
|
+
- lib/octokit/enterprise_admin_client/admin_stats.rb
|
107
|
+
- lib/octokit/enterprise_admin_client/license.rb
|
108
|
+
- lib/octokit/enterprise_admin_client/search_indexing.rb
|
109
|
+
- lib/octokit/enterprise_admin_client/users.rb
|
110
|
+
- lib/octokit/enterprise_management_console_client.rb
|
111
|
+
- lib/octokit/enterprise_management_console_client/management_console.rb
|
104
112
|
- lib/octokit/error.rb
|
105
113
|
- lib/octokit/gist.rb
|
114
|
+
- lib/octokit/middleware/follow_redirects.rb
|
106
115
|
- lib/octokit/organization.rb
|
107
116
|
- lib/octokit/rate_limit.rb
|
108
117
|
- lib/octokit/repo_arguments.rb
|
@@ -111,6 +120,7 @@ files:
|
|
111
120
|
- lib/octokit/response/raise_error.rb
|
112
121
|
- lib/octokit/user.rb
|
113
122
|
- lib/octokit/version.rb
|
123
|
+
- lib/octokit/warnable.rb
|
114
124
|
- octokit.gemspec
|
115
125
|
homepage: https://github.com/octokit/octokit.rb
|
116
126
|
licenses:
|
@@ -132,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
142
|
version: 1.3.5
|
133
143
|
requirements: []
|
134
144
|
rubyforge_project:
|
135
|
-
rubygems_version: 2.2.
|
145
|
+
rubygems_version: 2.2.3
|
136
146
|
signing_key:
|
137
147
|
specification_version: 4
|
138
148
|
summary: Ruby toolkit for working with the GitHub API
|
@@ -1,56 +0,0 @@
|
|
1
|
-
# :stopdoc:
|
2
|
-
|
3
|
-
# Stolen from ruby core's uri/common.rb, with modifications to support 1.8.x
|
4
|
-
#
|
5
|
-
# https://github.com/ruby/ruby/blob/trunk/lib/uri/common.rb
|
6
|
-
#
|
7
|
-
#
|
8
|
-
|
9
|
-
module URI
|
10
|
-
TBLENCWWWCOMP_ = {} # :nodoc:
|
11
|
-
256.times do |i|
|
12
|
-
TBLENCWWWCOMP_[i.chr] = '%%%02X' % i
|
13
|
-
end
|
14
|
-
TBLENCWWWCOMP_[' '] = '+'
|
15
|
-
TBLENCWWWCOMP_.freeze
|
16
|
-
TBLDECWWWCOMP_ = {} # :nodoc:
|
17
|
-
256.times do |i|
|
18
|
-
h, l = i>>4, i&15
|
19
|
-
TBLDECWWWCOMP_['%%%X%X' % [h, l]] = i.chr
|
20
|
-
TBLDECWWWCOMP_['%%%x%X' % [h, l]] = i.chr
|
21
|
-
TBLDECWWWCOMP_['%%%X%x' % [h, l]] = i.chr
|
22
|
-
TBLDECWWWCOMP_['%%%x%x' % [h, l]] = i.chr
|
23
|
-
end
|
24
|
-
TBLDECWWWCOMP_['+'] = ' '
|
25
|
-
TBLDECWWWCOMP_.freeze
|
26
|
-
|
27
|
-
# Encode given +s+ to URL-encoded form data.
|
28
|
-
#
|
29
|
-
# This method doesn't convert *, -, ., 0-9, A-Z, _, a-z, but does convert SP
|
30
|
-
# (ASCII space) to + and converts others to %XX.
|
31
|
-
#
|
32
|
-
# This is an implementation of
|
33
|
-
# http://www.w3.org/TR/html5/forms.html#url-encoded-form-data
|
34
|
-
#
|
35
|
-
# See URI.decode_www_form_component, URI.encode_www_form
|
36
|
-
def self.encode_www_form_component(s)
|
37
|
-
str = s.to_s
|
38
|
-
if RUBY_VERSION < "1.9" && $KCODE =~ /u/i
|
39
|
-
str.gsub(/([^ a-zA-Z0-9_.-]+)/) do
|
40
|
-
'%' + $1.unpack('H2' * Rack::Utils.bytesize($1)).join('%').upcase
|
41
|
-
end.tr(' ', '+')
|
42
|
-
else
|
43
|
-
str.gsub(/[^*\-.0-9A-Z_a-z]/) {|m| TBLENCWWWCOMP_[m]}
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# Decode given +str+ of URL-encoded form data.
|
48
|
-
#
|
49
|
-
# This decodes + to SP.
|
50
|
-
#
|
51
|
-
# See URI.encode_www_form_component, URI.decode_www_form
|
52
|
-
def self.decode_www_form_component(str, enc=nil)
|
53
|
-
raise ArgumentError, "invalid %-encoding (#{str})" unless /\A(?:%[0-9a-fA-F]{2}|[^%])*\z/ =~ str
|
54
|
-
str.gsub(/\+|%[0-9a-fA-F]{2}/) {|m| TBLDECWWWCOMP_[m]}
|
55
|
-
end
|
56
|
-
end
|