octokit 3.8.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2dedaa6599d61d3a75894f9d9650fc19f795510
4
- data.tar.gz: cb4a2597cfa0df06f1f82c002e81e1dec0fee990
3
+ metadata.gz: 4db1a3149648f98eb7e918999ef0ed6eaf62ce7a
4
+ data.tar.gz: 780d60412f1b2d069b6fbceb99c9b7a6f2b52e16
5
5
  SHA512:
6
- metadata.gz: 6b7d47dd30eff757599a6ce3080c60f7fdbdb99089cc9c9cee724f8e7cd5255b10a714698725a3f00ed59aee32e620e6ae9e6ac86f8c88590bccb463dcd72fb7
7
- data.tar.gz: 826384c7909a6dcfd31f8590a9a6eeadbdda2a9b4b281f0bcb06d601e2d9ba74b0533d1cd946820650c09be07639236e1dde5b1549043ee6c430061a3ce5ac0f
6
+ metadata.gz: 3ebe426f79dd955dce9a8aa7595f0707ded3ae62170e03512f5dd28b6f11a37aeee4132cc74abb4b4f5dc11fddb16c2c2c7afeca330dcc0faa78a956eb75f46a
7
+ data.tar.gz: 91787763f68ec589cdbb07afa258943ad3c79fb96d0a128d348bb58a654c9bd3a600d8a8d9b4f065eafea3fc71ffc583fc4c38554d0dc106ad83a518a2c0b333
data/README.md CHANGED
@@ -257,6 +257,64 @@ custom pattern for traversing large lists.
257
257
 
258
258
  [paginated]: http://developer.github.com/v3/#pagination
259
259
 
260
+ ## Working with GitHub Enterprise
261
+
262
+ With a bit of setup, you can also use Octokit with your Github Enterprise instance.
263
+
264
+ ### Interacting with the GitHub.com APIs in GitHub Enterprise
265
+
266
+ To interact with the "regular" GitHub.com APIs in GitHub Enterprise, simply configure the `api_endpoint` to match your hostname. For example:
267
+
268
+ ``` ruby
269
+ Octokit.configure do |c|
270
+ c.api_endpoint = "<hostname>/api/v3/"
271
+ end
272
+ client = Octokit::Client.new(:access_token => "<your 40 char token>")
273
+ ```
274
+
275
+ ### Interacting with the GitHub Enterprise Admin APIs
276
+
277
+ The GitHub Enterprise Admin APIs are under a different client: `EnterpriseAdminClient`. You'll need to have an administrator account in order to use these APIs.
278
+
279
+ ``` ruby
280
+ admin_client = Octokit::EnterpriseAdminClient.new \
281
+ :access_token => "<your 40 char token>",
282
+ :api_endpoint = "https://<hostname>/api/v3/"
283
+
284
+ # or
285
+ Octokit.configure do |c|
286
+ c.api_endpoint = "https://hostname/api/v3/"
287
+ c.access_token = "<your 40 char token>"
288
+ end
289
+ admin_client = Octokit.enterprise_admin_client
290
+ ```
291
+
292
+ ### Interacting with the GitHub Enterprise Management Console APIs
293
+
294
+ The GitHub Enterprise Management Console APIs are also under a separate client: `EnterpriseManagementConsoleClient`. In order to use it, you'll need to provide both your management console password as well as the endpoint to your management console. This is different than the API endpoint provided above.
295
+
296
+ ``` ruby
297
+ management_console_client = Octokit::EnterpriseManagementConsoleClient.new \
298
+ :management_console_password => "secret",
299
+ :management_console_endpoint = "https://hostname:8633"
300
+ # or
301
+ Octokit.configure do |c|
302
+ c.management_console_endpoint = "https://hostname:8633"
303
+ c.management_console_password = "secret"
304
+ end
305
+ management_console_client = Octokit.enterprise_management_console_client
306
+ ```
307
+
308
+ ### SSL Connection Errors
309
+
310
+ You *may* need to disable SSL temporarily while first setting up your GitHub Enterprise install. You can do that with the following configuration:
311
+
312
+ ``` ruby
313
+ client.connection_options[:ssl] = { :verify => false }
314
+ ```
315
+
316
+ Do remember to turn `:verify` back to `true`, as it's important for secure communication.
317
+
260
318
  ## Configuration and defaults
261
319
 
262
320
  While `Octokit::Client` accepts a range of options when creating a new client
@@ -362,6 +420,18 @@ construction currently used throughout the client.
362
420
 
363
421
  ## Upgrading guide
364
422
 
423
+ Version 4.0
424
+
425
+ - **removes support for a [long-deprecated overload][list-pulls] for
426
+ passing state as a positional argument** when listing pull requests. Instead,
427
+ pass `state` in the method options.
428
+ - **drops support for Ruby < 2.0**.
429
+ - adds support for new [Enterprise-only APIs](#working-with-github-enterprise).
430
+ - adds support for [Repository redirects][redirects].
431
+
432
+ [list-pulls]: https://github.com/octokit/octokit.rb/commit/e48e91f736d5fce51e3bf74d7c9022aaa52f5c5c
433
+ [redirects]: https://developer.github.com/changes/2015-05-26-repository-redirects-are-coming/
434
+
365
435
  Version 3.0 includes a couple breaking changes when upgrading from v2.x.x:
366
436
 
367
437
  The [default media type][default-media-type] is now `v3` instead of `beta`. If
@@ -510,6 +580,11 @@ ENV Variable | Description |
510
580
  `OCTOKIT_TEST_GITHUB_CLIENT_SECRET` | Test OAuth application client secret.
511
581
  `OCTOKIT_TEST_GITHUB_REPOSITORY` | Test repository to perform destructive actions against, this should not be set to any repository of importance. **Automatically created by the test suite if nonexistent** Default: `api-sandbox`
512
582
  `OCTOKIT_TEST_GITHUB_ORGANIZATION` | Test organization.
583
+ `OCTOKIT_TEST_GITHUB_ENTERPRISE_LOGIN` | GitHub Enterprise login name
584
+ `OCTOKIT_TEST_GITHUB_ENTERPRISE_TOKEN` | GitHub Enterprise token
585
+ `OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_PASSWORD` | GitHub Enterprise management console password
586
+ `OCTOKIT_TEST_GITHUB_ENTERPRISE_ENDPOINT` | GitHub Enterprise hostname
587
+ `OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT` | GitHub Enterprise Management Console endpoint
513
588
 
514
589
  Since we periodically refresh our cassettes, please keep some points in mind
515
590
  when writing new specs.
@@ -532,10 +607,9 @@ when writing new specs.
532
607
  This library aims to support and is [tested against][travis] the following Ruby
533
608
  implementations:
534
609
 
535
- * Ruby 1.9.2
536
- * Ruby 1.9.3
537
- * Ruby 2.0.0
538
- * Ruby 2.1.0
610
+ * Ruby 2.0
611
+ * Ruby 2.1
612
+ * Ruby 2.2
539
613
 
540
614
  If something doesn't work on one of these Ruby versions, it's a bug.
541
615
 
@@ -590,4 +664,3 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
590
664
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
591
665
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
592
666
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
593
-
@@ -1,4 +1,6 @@
1
1
  require 'octokit/client'
2
+ require 'octokit/enterprise_admin_client'
3
+ require 'octokit/enterprise_management_console_client'
2
4
  require 'octokit/default'
3
5
 
4
6
  # Ruby toolkit for the GitHub API
@@ -11,20 +13,44 @@ module Octokit
11
13
  #
12
14
  # @return [Octokit::Client] API wrapper
13
15
  def client
14
- @client = Octokit::Client.new(options) unless defined?(@client) && @client.same_options?(options)
15
- @client
16
+ return @client if defined?(@client) && @client.same_options?(options)
17
+ @client = Octokit::Client.new(options)
16
18
  end
17
19
 
18
- # @private
19
- def respond_to_missing?(method_name, include_private=false); client.respond_to?(method_name, include_private); end if RUBY_VERSION >= "1.9"
20
- # @private
21
- def respond_to?(method_name, include_private=false); client.respond_to?(method_name, include_private) || super; end if RUBY_VERSION < "1.9"
20
+ # EnterpriseAdminClient client based on configured options {Configurable}
21
+ #
22
+ # @return [Octokit::EnterpriseAdminClient] API wrapper
23
+ def enterprise_admin_client
24
+ return @enterprise_admin_client if defined?(@enterprise_admin_client) && @enterprise_admin_client.same_options?(options)
25
+ @enterprise_admin_client = Octokit::EnterpriseAdminClient.new(options)
26
+ end
22
27
 
23
- private
28
+ # EnterpriseManagementConsoleClient client based on configured options {Configurable}
29
+ #
30
+ # @return [Octokit::EnterpriseManagementConsoleClient] API wrapper
31
+ def enterprise_management_console_client
32
+ return @enterprise_management_console_client if defined?(@enterprise_management_console_client) && @enterprise_management_console_client.same_options?(options)
33
+ @enterprise_management_console_client = Octokit::EnterpriseManagementConsoleClient.new(options)
34
+ end
35
+
36
+ private
37
+
38
+ def respond_to_missing?(method_name, include_private=false)
39
+ client.respond_to?(method_name, include_private) ||
40
+ enterprise_admin_client.respond_to?(method_name, include_private) ||
41
+ enterprise_management_console_client.respond_to?(method_name, include_private)
42
+ end
24
43
 
25
44
  def method_missing(method_name, *args, &block)
26
- return super unless client.respond_to?(method_name)
27
- client.send(method_name, *args, &block)
45
+ if client.respond_to?(method_name)
46
+ return client.send(method_name, *args, &block)
47
+ elsif enterprise_admin_client.respond_to?(method_name)
48
+ return enterprise_admin_client.send(method_name, *args, &block)
49
+ elsif enterprise_management_console_client.respond_to?(method_name)
50
+ return enterprise_management_console_client.send(method_name, *args, &block)
51
+ end
52
+
53
+ super
28
54
  end
29
55
 
30
56
  end
@@ -1,4 +1,5 @@
1
- require 'sawyer'
1
+ require 'octokit/connection'
2
+ require 'octokit/warnable'
2
3
  require 'octokit/arguments'
3
4
  require 'octokit/repo_arguments'
4
5
  require 'octokit/configurable'
@@ -23,6 +24,7 @@ require 'octokit/client/hooks'
23
24
  require 'octokit/client/issues'
24
25
  require 'octokit/client/labels'
25
26
  require 'octokit/client/legacy_search'
27
+ require 'octokit/client/licenses'
26
28
  require 'octokit/client/meta'
27
29
  require 'octokit/client/markdown'
28
30
  require 'octokit/client/milestones'
@@ -52,6 +54,8 @@ module Octokit
52
54
 
53
55
  include Octokit::Authentication
54
56
  include Octokit::Configurable
57
+ include Octokit::Connection
58
+ include Octokit::Warnable
55
59
  include Octokit::Client::Authorizations
56
60
  include Octokit::Client::Commits
57
61
  include Octokit::Client::CommitComments
@@ -67,6 +71,7 @@ module Octokit
67
71
  include Octokit::Client::Issues
68
72
  include Octokit::Client::Labels
69
73
  include Octokit::Client::LegacySearch
74
+ include Octokit::Client::Licenses
70
75
  include Octokit::Client::Meta
71
76
  include Octokit::Client::Markdown
72
77
  include Octokit::Client::Milestones
@@ -99,14 +104,6 @@ module Octokit
99
104
  login_from_netrc unless user_authenticated? || application_authenticated?
100
105
  end
101
106
 
102
- # Compares client options to a Hash of requested options
103
- #
104
- # @param opts [Hash] Options to compare with current client options
105
- # @return [Boolean]
106
- def same_options?(opts)
107
- opts.hash == options.hash
108
- end
109
-
110
107
  # Text representation of the client, masking tokens and passwords
111
108
  #
112
109
  # @return [String]
@@ -115,6 +112,7 @@ module Octokit
115
112
 
116
113
  # mask password
117
114
  inspected = inspected.gsub! @password, "*******" if @password
115
+ inspected = inspected.gsub! @management_console_password, "*******" if @management_console_password
118
116
  # Only show last 4 of token, secret
119
117
  if @access_token
120
118
  inspected = inspected.gsub! @access_token, "#{'*'*36}#{@access_token[36..-1]}"
@@ -126,126 +124,6 @@ module Octokit
126
124
  inspected
127
125
  end
128
126
 
129
- # Make a HTTP GET request
130
- #
131
- # @param url [String] The path, relative to {#api_endpoint}
132
- # @param options [Hash] Query and header params for request
133
- # @return [Sawyer::Resource]
134
- def get(url, options = {})
135
- request :get, url, parse_query_and_convenience_headers(options)
136
- end
137
-
138
- # Make a HTTP POST request
139
- #
140
- # @param url [String] The path, relative to {#api_endpoint}
141
- # @param options [Hash] Body and header params for request
142
- # @return [Sawyer::Resource]
143
- def post(url, options = {})
144
- request :post, url, options
145
- end
146
-
147
- # Make a HTTP PUT request
148
- #
149
- # @param url [String] The path, relative to {#api_endpoint}
150
- # @param options [Hash] Body and header params for request
151
- # @return [Sawyer::Resource]
152
- def put(url, options = {})
153
- request :put, url, options
154
- end
155
-
156
- # Make a HTTP PATCH request
157
- #
158
- # @param url [String] The path, relative to {#api_endpoint}
159
- # @param options [Hash] Body and header params for request
160
- # @return [Sawyer::Resource]
161
- def patch(url, options = {})
162
- request :patch, url, options
163
- end
164
-
165
- # Make a HTTP DELETE request
166
- #
167
- # @param url [String] The path, relative to {#api_endpoint}
168
- # @param options [Hash] Query and header params for request
169
- # @return [Sawyer::Resource]
170
- def delete(url, options = {})
171
- request :delete, url, options
172
- end
173
-
174
- # Make a HTTP HEAD request
175
- #
176
- # @param url [String] The path, relative to {#api_endpoint}
177
- # @param options [Hash] Query and header params for request
178
- # @return [Sawyer::Resource]
179
- def head(url, options = {})
180
- request :head, url, parse_query_and_convenience_headers(options)
181
- end
182
-
183
- # Make one or more HTTP GET requests, optionally fetching
184
- # the next page of results from URL in Link response header based
185
- # on value in {#auto_paginate}.
186
- #
187
- # @param url [String] The path, relative to {#api_endpoint}
188
- # @param options [Hash] Query and header params for request
189
- # @param block [Block] Block to perform the data concatination of the
190
- # multiple requests. The block is called with two parameters, the first
191
- # contains the contents of the requests so far and the second parameter
192
- # contains the latest response.
193
- # @return [Sawyer::Resource]
194
- def paginate(url, options = {}, &block)
195
- opts = parse_query_and_convenience_headers(options.dup)
196
- if @auto_paginate || @per_page
197
- opts[:query][:per_page] ||= @per_page || (@auto_paginate ? 100 : nil)
198
- end
199
-
200
- data = request(:get, url, opts)
201
-
202
- if @auto_paginate
203
- while @last_response.rels[:next] && rate_limit.remaining > 0
204
- @last_response = @last_response.rels[:next].get
205
- if block_given?
206
- yield(data, @last_response)
207
- else
208
- data.concat(@last_response.data) if @last_response.data.is_a?(Array)
209
- end
210
- end
211
-
212
- end
213
-
214
- data
215
- end
216
-
217
- # Hypermedia agent for the GitHub API
218
- #
219
- # @return [Sawyer::Agent]
220
- def agent
221
- @agent ||= Sawyer::Agent.new(api_endpoint, sawyer_options) do |http|
222
- http.headers[:accept] = default_media_type
223
- http.headers[:content_type] = "application/json"
224
- http.headers[:user_agent] = user_agent
225
- if basic_authenticated?
226
- http.basic_auth(@login, @password)
227
- elsif token_authenticated?
228
- http.authorization 'token', @access_token
229
- elsif application_authenticated?
230
- http.params = http.params.merge application_authentication
231
- end
232
- end
233
- end
234
-
235
- # Fetch the root resource for the API
236
- #
237
- # @return [Sawyer::Resource]
238
- def root
239
- get "/"
240
- end
241
-
242
- # Response for last HTTP request
243
- #
244
- # @return [Sawyer::Response]
245
- def last_response
246
- @last_response if defined? @last_response
247
- end
248
-
249
127
  # Duplicate client using client_id and client_secret as
250
128
  # Basic Authentication credentials.
251
129
  # @example
@@ -310,72 +188,5 @@ module Octokit
310
188
  reset_agent
311
189
  @client_secret = value
312
190
  end
313
-
314
- # Wrapper around Kernel#warn to print warnings unless
315
- # OCTOKIT_SILENT is set to true.
316
- #
317
- # @return [nil]
318
- def octokit_warn(*message)
319
- unless ENV['OCTOKIT_SILENT']
320
- warn message
321
- end
322
- end
323
-
324
- private
325
-
326
- def reset_agent
327
- @agent = nil
328
- end
329
-
330
- def request(method, path, data, options = {})
331
- if data.is_a?(Hash)
332
- options[:query] = data.delete(:query) || {}
333
- options[:headers] = data.delete(:headers) || {}
334
- if accept = data.delete(:accept)
335
- options[:headers][:accept] = accept
336
- end
337
- end
338
-
339
- @last_response = response = agent.call(method, URI::Parser.new.escape(path.to_s), data, options)
340
- response.data
341
- end
342
-
343
- # Executes the request, checking if it was successful
344
- #
345
- # @return [Boolean] True on success, false otherwise
346
- def boolean_from_response(method, path, options = {})
347
- request(method, path, options)
348
- @last_response.status == 204
349
- rescue Octokit::NotFound
350
- false
351
- end
352
-
353
-
354
- def sawyer_options
355
- opts = {
356
- :links_parser => Sawyer::LinkParsers::Simple.new
357
- }
358
- conn_opts = @connection_options
359
- conn_opts[:builder] = @middleware if @middleware
360
- conn_opts[:proxy] = @proxy if @proxy
361
- opts[:faraday] = Faraday.new(conn_opts)
362
-
363
- opts
364
- end
365
-
366
- def parse_query_and_convenience_headers(options)
367
- headers = options.fetch(:headers, {})
368
- CONVENIENCE_HEADERS.each do |h|
369
- if header = options.delete(h)
370
- headers[h] = header
371
- end
372
- end
373
- query = options.delete(:query)
374
- opts = {:query => options}
375
- opts[:query].merge!(query) if query && query.is_a?(Hash)
376
- opts[:headers] = headers unless headers.empty?
377
-
378
- opts
379
- end
380
191
  end
381
192
  end
@@ -12,7 +12,7 @@ module Octokit
12
12
  # @return [Array] List of commit comments
13
13
  # @see https://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository
14
14
  def list_commit_comments(repo, options = {})
15
- get "#{Repository.path repo}/comments", options
15
+ paginate "#{Repository.path repo}/comments", options
16
16
  end
17
17
 
18
18
  # List comments for a single commit
@@ -22,7 +22,7 @@ module Octokit
22
22
  # @return [Array] List of commit comments
23
23
  # @see https://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit
24
24
  def commit_comments(repo, sha, options = {})
25
- get "#{Repository.path repo}/commits/#{sha}/comments", options
25
+ paginate "#{Repository.path repo}/commits/#{sha}/comments", options
26
26
  end
27
27
 
28
28
  # Get a single commit comment