octokit 4.22.0 → 4.23.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of octokit might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 072c9ec7fa2439cc75655ff5c925efeedc19fe386eae30a30be712524802b3ad
4
- data.tar.gz: 177806faf28428ecd942d0159c268cae122e2ec7a88d4bc3e0b34e41a2b3409c
3
+ metadata.gz: 7abf6a2c9179b01ec754c12ea122c53010ce0cedc46631e3a3a725daec1ed409
4
+ data.tar.gz: 13e23b71f45c6a36f330221d6bb9ee0769974ca77f07c32138262c65f84b59d7
5
5
  SHA512:
6
- metadata.gz: 7a087ec2c360f33db0cd6526ba76ae8762d57885a24577d36ada1baf1cf3019e93beeaa70455bb6cf08f64d9328e84112043d202526b42e94f8cb1bfb96faada
7
- data.tar.gz: 8425341fe9135936b066de860c2722ad77b8a3c3ce2d8fe478a5420a3c911fc56a419ce4808a290f55199074bab94953500d3cdbc7345f9d9137d66cccb9de39
6
+ metadata.gz: ae5965ed9aa64796fdb7073c9d2ea4d977df22dd428f21674504e6a46b32b743a63b8e22ad53991b6b0db5cc8eb0586250f733f7bd6e30ca11d632960b44d75c
7
+ data.tar.gz: e50fb32abc9045813a533bd28e8b69890d9fdac9f8fe05fca37f1064f14708c654fe0086d78172fb9ab134ab35fcedbd5d58867c54d6c8bfa651a143d38a6fb4
data/README.md CHANGED
@@ -10,23 +10,25 @@ Upgrading? Check the [Upgrade Guide](#upgrading-guide) before bumping to a new
10
10
  ## Table of Contents
11
11
 
12
12
  1. [Philosophy](#philosophy)
13
- 2. [Quick start](#quick-start)
13
+ 2. [Installation](#quick-start)
14
14
  3. [Making requests](#making-requests)
15
+ 1. [Additional Query Parameters](#additional-query-parameters)
15
16
  4. [Consuming resources](#consuming-resources)
16
17
  5. [Accessing HTTP responses](#accessing-http-responses)
17
- 6. [Authentication](#authentication)
18
+ 6. [Handling errors](#handling-errors)
19
+ 7. [Authentication](#authentication)
18
20
  1. [Basic Authentication](#basic-authentication)
19
21
  2. [OAuth access tokens](#oauth-access-tokens)
20
22
  3. [Two-Factor Authentication](#two-factor-authentication)
21
23
  4. [Using a .netrc file](#using-a-netrc-file)
22
24
  5. [Application authentication](#application-authentication)
23
- 7. [Pagination](#pagination)
25
+ 8. [Pagination](#pagination)
24
26
  1. [Auto pagination](#auto-pagination)
25
- 8. [Working with GitHub Enterprise](#working-with-github-enterprise)
27
+ 9. [Working with GitHub Enterprise](#working-with-github-enterprise)
26
28
  1. [Interacting with the GitHub.com APIs in GitHub Enterprise](#interacting-with-the-githubcom-apis-in-github-enterprise)
27
29
  2. [Interacting with the GitHub Enterprise Admin APIs](#interacting-with-the-github-enterprise-admin-apis)
28
30
  3. [Interacting with the GitHub Enterprise Management Console APIs](#interacting-with-the-github-enterprise-management-console-apis)
29
- 9. [SSL Connection Errors](#ssl-connection-errors)
31
+ 4. [SSL Connection Errors](#ssl-connection-errors)
30
32
  10. [Configuration and defaults](#configuration-and-defaults)
31
33
  1. [Configuring module defaults](#configuring-module-defaults)
32
34
  2. [Using ENV variables](#using-env-variables)
@@ -66,7 +68,7 @@ client.readme 'al3x/sovereign', :accept => 'application/vnd.github.html'
66
68
  [wrappers]: http://wynnnetherland.com/journal/what-makes-a-good-api-wrapper
67
69
  [github-api]: https://developer.github.com/v3/
68
70
 
69
- ## Quick start
71
+ ## Installation
70
72
 
71
73
  Install via Rubygems
72
74
 
@@ -80,7 +82,7 @@ Access the library in Ruby:
80
82
 
81
83
  require 'octokit'
82
84
 
83
- ### Making requests
85
+ ## Making requests
84
86
 
85
87
  [API methods][] are available as client instance methods.
86
88
 
@@ -95,7 +97,7 @@ client = Octokit::Client.new(:access_token => 'personal_access_token')
95
97
  client.user
96
98
  ```
97
99
 
98
- ### Additional Query Parameters
100
+ ### Additional query parameters
99
101
 
100
102
  When passing additional parameters to GET based request use the following syntax:
101
103
 
@@ -109,9 +111,9 @@ When passing additional parameters to GET based request use the following syntax
109
111
  client.contents('octokit/octokit.rb', path: 'path/to/file.rb', query: {ref: 'some-other-branch'})
110
112
  ```
111
113
 
112
- [API methods]: http://octokit.github.io/octokit.rb/method_list.html
114
+ [api methods]: http://octokit.github.io/octokit.rb/method_list.html
113
115
 
114
- ### Consuming resources
116
+ ## Consuming resources
115
117
 
116
118
  Most methods return a `Resource` object which provides dot notation and `[]`
117
119
  access for fields returned in the API response.
@@ -134,7 +136,7 @@ user.rels[:gists].href
134
136
  **Note:** URL fields are culled into a separate `.rels` collection for easier
135
137
  [Hypermedia](#hypermedia-agent) support.
136
138
 
137
- ### Accessing HTTP responses
139
+ ## Accessing HTTP responses
138
140
 
139
141
  While most methods return a `Resource` object or a Boolean, sometimes you may
140
142
  need access to the raw HTTP response headers. You can access the last HTTP
@@ -146,6 +148,23 @@ response = client.last_response
146
148
  etag = response.headers[:etag]
147
149
  ```
148
150
 
151
+ ## Handling errors
152
+
153
+ When the API returns an error response, Octokit will raise a Ruby exception.
154
+
155
+ A range of different exceptions can be raised depending on the error returned
156
+ by the API - for example:
157
+
158
+ * A `400 Bad Request` response will lead to an `Octokit::BadRequest` error
159
+ * A `403 Forbidden` error with a "rate limited exceeded" message will lead
160
+ to a `Octokit::TooManyRequests` error
161
+
162
+ All of the different exception classes inherit from `Octokit::Error` and
163
+ expose the `#response_status`, `#response_headers` and `#response_body`.
164
+ For validation errors, `#errors` will return an `Array` of `Hash`es
165
+ with the detailed information
166
+ [returned by the API](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#client-errors).
167
+
149
168
  ## Authentication
150
169
 
151
170
  Octokit supports the various [authentication methods supported by the GitHub
@@ -163,6 +182,7 @@ user = client.user
163
182
  user.login
164
183
  # => "defunkt"
165
184
  ```
185
+
166
186
  While Basic Authentication allows you to get started quickly, OAuth access
167
187
  tokens are the preferred way to authenticate on behalf of users.
168
188
 
@@ -171,9 +191,9 @@ tokens are the preferred way to authenticate on behalf of users.
171
191
  [OAuth access tokens][oauth] provide two main benefits over using your username
172
192
  and password:
173
193
 
174
- * **Revokable access**. Access tokens can be revoked, removing access for only
194
+ - **Revocable access**. Access tokens can be revoked, removing access for only
175
195
  that token without having to change your password everywhere.
176
- * **Limited access**. Access tokens have [access scopes][] which allow for more
196
+ - **Limited access**. Access tokens have [access scopes][] which allow for more
177
197
  granular access to API resources. For instance, you can grant a third party
178
198
  access to your gists but not your private repositories.
179
199
 
@@ -212,7 +232,7 @@ client = Octokit::Client.new \
212
232
  user = client.user("defunkt", :headers => { "X-GitHub-OTP" => "<your 2FA token>" })
213
233
  ```
214
234
 
215
- As you can imagine, this gets annoying quick since two-factor auth tokens are very short lived. So it is recommended to create an oauth token for the user to communicate with the API:
235
+ As you can imagine, this gets annoying quickly since two-factor auth tokens are very short lived. So it is recommended to create an oauth token for the user to communicate with the API:
216
236
 
217
237
  ```ruby
218
238
  client = Octokit::Client.new \
@@ -227,13 +247,14 @@ client.create_authorization(:scopes => ["user"], :note => "Name of token",
227
247
  ### Using a .netrc file
228
248
 
229
249
  Octokit supports reading credentials from a netrc file (defaulting to
230
- `~/.netrc`). Given these lines in your netrc:
250
+ `~/.netrc`). Given these lines in your netrc:
231
251
 
232
252
  ```
233
253
  machine api.github.com
234
254
  login defunkt
235
255
  password c0d3b4ssssss!
236
256
  ```
257
+
237
258
  You can now create a client with those credentials:
238
259
 
239
260
  ```ruby
@@ -241,6 +262,7 @@ client = Octokit::Client.new(:netrc => true)
241
262
  client.login
242
263
  # => "defunkt"
243
264
  ```
265
+
244
266
  But _I want to use OAuth_ you say. Since the GitHub API supports using an OAuth
245
267
  token as a Basic password, you totally can:
246
268
 
@@ -329,7 +351,7 @@ With a bit of setup, you can also use Octokit with your GitHub Enterprise instan
329
351
 
330
352
  To interact with the "regular" GitHub.com APIs in GitHub Enterprise, simply configure the `api_endpoint` to match your hostname. For example:
331
353
 
332
- ``` ruby
354
+ ```ruby
333
355
  Octokit.configure do |c|
334
356
  c.api_endpoint = "https://<hostname>/api/v3/"
335
357
  end
@@ -341,7 +363,7 @@ client = Octokit::Client.new(:access_token => "<your 40 char token>")
341
363
 
342
364
  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.
343
365
 
344
- ``` ruby
366
+ ```ruby
345
367
  admin_client = Octokit::EnterpriseAdminClient.new(
346
368
  :access_token => "<your 40 char token>",
347
369
  :api_endpoint => "https://<hostname>/api/v3/"
@@ -358,9 +380,9 @@ admin_client = Octokit.enterprise_admin_client.new
358
380
 
359
381
  ### Interacting with the GitHub Enterprise Management Console APIs
360
382
 
361
- 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.
383
+ 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 from the API endpoint provided above.
362
384
 
363
- ``` ruby
385
+ ```ruby
364
386
  management_console_client = Octokit::EnterpriseManagementConsoleClient.new(
365
387
  :management_console_password => "secret",
366
388
  :management_console_endpoint = "https://hostname:8633"
@@ -377,9 +399,9 @@ management_console_client = Octokit.enterprise_management_console_client.new
377
399
 
378
400
  ### SSL Connection Errors
379
401
 
380
- You *may* need to disable SSL temporarily while first setting up your GitHub Enterprise install. You can do that with the following configuration:
402
+ You _may_ need to disable SSL temporarily while first setting up your GitHub Enterprise install. You can do that with the following configuration:
381
403
 
382
- ``` ruby
404
+ ```ruby
383
405
  client.connection_options[:ssl] = { :verify => false }
384
406
  ```
385
407
 
@@ -444,6 +466,7 @@ Octokit.configure do |c|
444
466
  }
445
467
  end
446
468
  ```
469
+
447
470
  You should set a timeout in order to avoid Ruby’s Timeout module, which can hose your server. Here are some resources for more information on this:
448
471
 
449
472
  - [The Oldest Bug In Ruby - Why Rack::Timeout Might Hose your Server](https://www.schneems.com/2017/02/21/the-oldest-bug-in-ruby-why-racktimeout-might-hose-your-server/)
@@ -473,7 +496,7 @@ repos.last.name
473
496
  # => "faraday-zeromq"
474
497
  ```
475
498
 
476
- When processing API responses, all `*_url` attributes are culled in to the link
499
+ When processing API responses, all `*_url` attributes are culled into the link
477
500
  relations collection. Any `url` attribute becomes `.rels[:self]`.
478
501
 
479
502
  ### URI templates
@@ -509,8 +532,8 @@ Octokit 3.0 aims to be hypermedia-driven, removing the internal URL
509
532
  construction currently used throughout the client.
510
533
 
511
534
  [hypermedia]: http://en.wikipedia.org/wiki/Hypermedia
512
- [Sawyer]: https://github.com/lostisland/sawyer
513
- [Faraday]: https://github.com/lostisland/faraday
535
+ [sawyer]: https://github.com/lostisland/sawyer
536
+ [faraday]: https://github.com/lostisland/faraday
514
537
  [uri-templates]: http://tools.ietf.org/html/rfc6570
515
538
 
516
539
  ## Upgrading guide
@@ -518,8 +541,8 @@ construction currently used throughout the client.
518
541
  Version 4.0
519
542
 
520
543
  - **removes support for a [long-deprecated overload][list-pulls] for
521
- passing state as a positional argument** when listing pull requests. Instead,
522
- pass `state` in the method options.
544
+ passing state as a positional argument** when listing pull requests. Instead,
545
+ pass `state` in the method options.
523
546
  - **drops support for Ruby < 2.0**.
524
547
  - adds support for new [Enterprise-only APIs](#working-with-github-enterprise).
525
548
  - adds support for [Repository redirects][redirects].
@@ -536,6 +559,7 @@ for the client:
536
559
  ```ruby
537
560
  Octokit.default_media_type = "application/vnd.github.beta+json"
538
561
  ```
562
+
539
563
  or per-request
540
564
 
541
565
  ```ruby
@@ -552,21 +576,20 @@ Version 2.0 includes a completely rewritten `Client` factory that now memoizes
552
576
  client instances based on unique configuration options. Breaking changes also
553
577
  include:
554
578
 
555
- * `:oauth_token` is now `:access_token`
556
- * `:auto_traversal` is now `:auto_paginate`
557
- * `Hashie::Mash` has been removed. Responses now return a `Sawyer::Resource`
579
+ - `:oauth_token` is now `:access_token`
580
+ - `:auto_traversal` is now `:auto_paginate`
581
+ - `Hashie::Mash` has been removed. Responses now return a `Sawyer::Resource`
558
582
  object. This new type behaves mostly like a Ruby `Hash`, but does not fully
559
583
  support the `Hashie::Mash` API.
560
- * Two new client error types are raised where appropriate:
584
+ - Two new client error types are raised where appropriate:
561
585
  `Octokit::TooManyRequests` and `Octokit::TooManyLoginAttempts`
562
- * The `search_*` methods from v1.x are now found at `legacy_search_*`
563
- * Support for netrc requires including the [netrc gem][] in your Gemfile or
586
+ - The `search_*` methods from v1.x are now found at `legacy_search_*`
587
+ - Support for netrc requires including the [netrc gem][] in your Gemfile or
564
588
  gemspec.
565
- * DateTime fields are now proper `DateTime` objects. Previous versions outputted DateTime fields as 'String' objects.
589
+ - DateTime fields are now proper `DateTime` objects. Previous versions outputted DateTime fields as 'String' objects.
566
590
 
567
591
  [netrc gem]: https://rubygems.org/gems/netrc
568
592
 
569
-
570
593
  ## Advanced usage
571
594
 
572
595
  Since Octokit employs [Faraday][faraday] under the hood, some behavior can be
@@ -580,7 +603,7 @@ traffic:
580
603
 
581
604
  ```ruby
582
605
  stack = Faraday::RackBuilder.new do |builder|
583
- builder.use Faraday::Request::Retry, exceptions: [Octokit::ServerError]
606
+ builder.use Faraday::Retry::Middleware, exceptions: [Octokit::ServerError] # or Faraday::Request::Retry for Faraday < 2.0
584
607
  builder.use Octokit::Middleware::FollowRedirects
585
608
  builder.use Octokit::Response::RaiseError
586
609
  builder.use Octokit::Response::FeedParser
@@ -594,6 +617,7 @@ Octokit.middleware = stack
594
617
  client = Octokit::Client.new
595
618
  client.user 'pengwynn'
596
619
  ```
620
+
597
621
  ```
598
622
  I, [2013-08-22T15:54:38.583300 #88227] INFO -- : get https://api.github.com/users/pengwynn
599
623
  D, [2013-08-22T15:54:38.583401 #88227] DEBUG -- request: Accept: "application/vnd.github.beta+json"
@@ -637,7 +661,6 @@ Once configured, the middleware will store responses in cache based on ETag
637
661
  fingerprint and serve those back up for future `304` responses for the same
638
662
  resource. See the [project README][cache] for advanced usage.
639
663
 
640
-
641
664
  [cache]: https://github.com/plataformatec/faraday-http-cache
642
665
  [faraday]: https://github.com/lostisland/faraday
643
666
 
@@ -653,12 +676,11 @@ to run a Ruby console to poke on Octokit, you can crank one up with:
653
676
 
654
677
  script/console
655
678
 
656
- Using the scripts in `./script` instead of `bundle exec rspec`, `bundle
657
- console`, etc. ensures your dependencies are up-to-date.
679
+ Using the scripts in `./script` instead of `bundle exec rspec`, `bundle console`, etc. ensures your dependencies are up-to-date.
658
680
 
659
681
  ### Code of Conduct
660
682
 
661
- We want both the Octokit.rb and larger Octokit communities to be an open
683
+ We want both the Octokit.rb and larger Octokit communities to be open
662
684
  and welcoming environments. Please read and follow both in spirit and
663
685
  letter [Code of Conduct](CODE_OF_CONDUCT.md).
664
686
 
@@ -675,43 +697,43 @@ Octokit uses environmental variables for storing credentials used in testing.
675
697
  If you are testing an API endpoint that doesn't require authentication, you
676
698
  can get away without any additional configuration. For the most part, tests
677
699
  use an authenticated client, using a token stored in `ENV['OCTOKIT_TEST_GITHUB_TOKEN']`.
678
- There are several different authenticating method's used across the api.
700
+ There are several different authentication methods used across the api.
679
701
  Here is the full list of configurable environmental variables for testing
680
702
  Octokit:
681
703
 
682
- ENV Variable | Description |
683
- :-------------------|:-----------------|
684
- `OCTOKIT_TEST_GITHUB_LOGIN`| GitHub login name (preferably one created specifically for testing against).
685
- `OCTOKIT_TEST_GITHUB_PASSWORD`| Password for the test GitHub login.
686
- `OCTOKIT_TEST_GITHUB_TOKEN` | [Personal Access Token](https://github.com/blog/1509-personal-api-tokens) for the test GitHub login.
687
- `OCTOKIT_TEST_GITHUB_CLIENT_ID` | Test OAuth application client id.
688
- `OCTOKIT_TEST_GITHUB_CLIENT_SECRET` | Test OAuth application client secret.
689
- `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`
690
- `OCTOKIT_TEST_GITHUB_ORGANIZATION` | Test organization.
691
- `OCTOKIT_TEST_GITHUB_ENTERPRISE_LOGIN` | GitHub Enterprise login name.
692
- `OCTOKIT_TEST_GITHUB_ENTERPRISE_TOKEN` | GitHub Enterprise token.
693
- `OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_PASSWORD` | GitHub Enterprise management console password.
694
- `OCTOKIT_TEST_GITHUB_ENTERPRISE_ENDPOINT` | GitHub Enterprise hostname.
695
- `OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT` | GitHub Enterprise Management Console endpoint.
696
- `OCTOKIT_TEST_GITHUB_INTEGRATION` | [GitHub Integration](https://developer.github.com/early-access/integrations/) owned by your test organization.
697
- `OCTOKIT_TEST_GITHUB_INTEGRATION_INSTALLATION` | Installation of the GitHub Integration specified above.
698
- `OCTOKIT_TEST_INTEGRATION_PEM_KEY` | File path to the private key generated from your integration.
704
+ | ENV Variable | Description |
705
+ | :----------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
706
+ | `OCTOKIT_TEST_GITHUB_LOGIN` | GitHub login name (preferably one created specifically for testing against). |
707
+ | `OCTOKIT_TEST_GITHUB_PASSWORD` | Password for the test GitHub login. |
708
+ | `OCTOKIT_TEST_GITHUB_TOKEN` | [Personal Access Token](https://github.com/blog/1509-personal-api-tokens) for the test GitHub login. |
709
+ | `OCTOKIT_TEST_GITHUB_CLIENT_ID` | Test OAuth application client id. |
710
+ | `OCTOKIT_TEST_GITHUB_CLIENT_SECRET` | Test OAuth application client secret. |
711
+ | `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` |
712
+ | `OCTOKIT_TEST_GITHUB_ORGANIZATION` | Test organization. |
713
+ | `OCTOKIT_TEST_GITHUB_ENTERPRISE_LOGIN` | GitHub Enterprise login name. |
714
+ | `OCTOKIT_TEST_GITHUB_ENTERPRISE_TOKEN` | GitHub Enterprise token. |
715
+ | `OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_PASSWORD` | GitHub Enterprise management console password. |
716
+ | `OCTOKIT_TEST_GITHUB_ENTERPRISE_ENDPOINT` | GitHub Enterprise hostname. |
717
+ | `OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT` | GitHub Enterprise Management Console endpoint. |
718
+ | `OCTOKIT_TEST_GITHUB_INTEGRATION` | [GitHub Integration](https://developer.github.com/early-access/integrations/) owned by your test organization. |
719
+ | `OCTOKIT_TEST_GITHUB_INTEGRATION_INSTALLATION` | Installation of the GitHub Integration specified above. |
720
+ | `OCTOKIT_TEST_INTEGRATION_PEM_KEY` | File path to the private key generated from your integration. |
699
721
 
700
722
  Since we periodically refresh our cassettes, please keep some points in mind
701
723
  when writing new specs.
702
724
 
703
- * **Specs should be idempotent**. The HTTP calls made during a spec should be
725
+ - **Specs should be idempotent**. The HTTP calls made during a spec should be
704
726
  able to be run over and over. This means deleting a known resource prior to
705
727
  creating it if the name has to be unique.
706
- * **Specs should be able to be run in random order.** If a spec depends on
728
+ - **Specs should be able to be run in random order.** If a spec depends on
707
729
  another resource as a fixture, make sure that's created in the scope of the
708
730
  spec and not depend on a previous spec to create the data needed.
709
- * **Do not depend on authenticated user info.** Instead of asserting
731
+ - **Do not depend on authenticated user info.** Instead of asserting
710
732
  actual values in resources, try to assert the existence of a key or that a
711
733
  response is an Array. We're testing the client, not the API.
712
734
 
713
735
  [bootstrapping]: http://wynnnetherland.com/linked/2013012801/bootstrapping-consistency
714
- [VCR]: https://github.com/vcr/vcr
736
+ [vcr]: https://github.com/vcr/vcr
715
737
 
716
738
  ## Supported Ruby Versions
717
739
 
@@ -721,6 +743,8 @@ implementations:
721
743
  * Ruby 2.5
722
744
  * Ruby 2.6
723
745
  * Ruby 2.7
746
+ * Ruby 3.0
747
+ * Ruby 3.1
724
748
 
725
749
  If something doesn't work on one of these Ruby versions, it's a bug.
726
750
 
@@ -757,7 +781,8 @@ The changes made between versions can be seen on the [project releases page][rel
757
781
  [releases]: https://github.com/octokit/octokit.rb/releases
758
782
 
759
783
  ## Making Repeating Requests
760
- In most cases it would be best to use a [webhooks](https://developer.github.com/webhooks/), but sometimes webhooks don't provide all of the information needed. In those cases where one might need to poll for progress or retry a request on failure, we designed [Octopoller](https://github.com/octokit/octopoller.rb). Octopoller is a micro gem perfect for making repeating requests.
784
+
785
+ In most cases it would be best to use [webhooks](https://developer.github.com/webhooks/), but sometimes webhooks don't provide all of the information needed. In those cases where one might need to poll for progress or retry a request on failure, we designed [Octopoller](https://github.com/octokit/octopoller.rb). Octopoller is a micro gem perfect for making repeating requests.
761
786
 
762
787
  ```ruby
763
788
  Octopoller.poll(timeout: 15.seconds) do
@@ -3,6 +3,14 @@ module Octokit
3
3
  # Authentication methods for {Octokit::Client}
4
4
  module Authentication
5
5
 
6
+ # In Faraday 2.x, the authorization middleware uses new interface
7
+ FARADAY_BASIC_AUTH_KEYS =
8
+ if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
9
+ [:authorization, :basic]
10
+ else
11
+ [:basic_auth]
12
+ end
13
+
6
14
  # Indicates if the client was supplied Basic Auth
7
15
  # username and password
8
16
  #
@@ -60,7 +60,10 @@ module Octokit
60
60
  # result.check_runs[0].id # => 51295429
61
61
  # result.check_runs[0].status # => "in_progress"
62
62
  def check_runs_for_ref(repo, ref, options = {})
63
- get "#{Repository.path repo}/commits/#{ref}/check-runs", options
63
+ paginate "#{Repository.path repo}/commits/#{ref}/check-runs", options do |data, last_response|
64
+ data.check_runs.concat last_response.data.check_runs
65
+ data.total_count += last_response.data.total_count
66
+ end
64
67
  end
65
68
  alias :list_check_runs_for_ref :check_runs_for_ref
66
69
 
@@ -81,7 +84,10 @@ module Octokit
81
84
  # result.check_runs[0].check_suite.id # => 50440400
82
85
  # result.check_runs[0].status # => "in_progress"
83
86
  def check_runs_for_check_suite(repo, id, options = {})
84
- get "#{Repository.path repo}/check-suites/#{id}/check-runs", options
87
+ paginate "#{Repository.path repo}/check-suites/#{id}/check-runs", options do |data, last_response|
88
+ data.check_runs.concat last_response.data.check_runs
89
+ data.total_count += last_response.data.total_count
90
+ end
85
91
  end
86
92
  alias :list_check_runs_for_check_suite :check_runs_for_check_suite
87
93
 
@@ -107,7 +113,7 @@ module Octokit
107
113
  # annotations[0].path # => "README.md"
108
114
  # annotations[0].message # => "Looks good!"
109
115
  def check_run_annotations(repo, id, options = {})
110
- get "#{Repository.path repo}/check-runs/#{id}/annotations", options
116
+ paginate "#{Repository.path repo}/check-runs/#{id}/annotations", options
111
117
  end
112
118
 
113
119
  # Methods for Check Suites
@@ -140,7 +146,10 @@ module Octokit
140
146
  # result.check_suites[0].id # => 50440400
141
147
  # result.check_suites[0].app.id # => 76765
142
148
  def check_suites_for_ref(repo, ref, options = {})
143
- get "#{Repository.path repo}/commits/#{ref}/check-suites", options
149
+ paginate "#{Repository.path repo}/commits/#{ref}/check-suites", options do |data, last_response|
150
+ data.check_suites.concat last_response.data.check_suites
151
+ data.total_count += last_response.data.total_count
152
+ end
144
153
  end
145
154
  alias :list_check_suites_for_ref :check_suites_for_ref
146
155
 
@@ -156,7 +156,7 @@ module Octokit
156
156
  # @example Get archive link for octokit/octokit.rb
157
157
  # Octokit.archive_link("octokit/octokit.rb")
158
158
  def archive_link(repo, options={})
159
- repo_ref = options.delete :ref
159
+ repo_ref = ERB::Util.url_encode(options.delete :ref)
160
160
  format = (options.delete :format) || 'tarball'
161
161
  url = "#{Repository.path repo}/#{format}/#{repo_ref}"
162
162
 
@@ -1,4 +1,4 @@
1
- require 'cgi'
1
+ require "erb"
2
2
 
3
3
  module Octokit
4
4
  class Client
@@ -28,7 +28,7 @@ module Octokit
28
28
  # @example Get the "V3 Addition" label from octokit/octokit.rb
29
29
  # Octokit.label("octokit/octokit.rb", "V3 Addition")
30
30
  def label(repo, name, options = {})
31
- get "#{Repository.path repo}/labels/#{name}", options
31
+ get "#{Repository.path repo}/labels/#{ERB::Util.url_encode(name)}", options
32
32
  end
33
33
 
34
34
  # Add a label to a repository
@@ -56,7 +56,7 @@ module Octokit
56
56
  # @example Update the label "Version 1.0" with new color "#cceeaa"
57
57
  # Octokit.update_label("octokit/octokit.rb", "Version 1.0", {:color => "cceeaa"})
58
58
  def update_label(repo, label, options = {})
59
- patch "#{Repository.path repo}/labels/#{label}", options
59
+ patch "#{Repository.path repo}/labels/#{ERB::Util.url_encode(label)}", options
60
60
  end
61
61
 
62
62
  # Delete a label from a repository.
@@ -70,7 +70,7 @@ module Octokit
70
70
  # @example Delete the label "Version 1.0" from the repository.
71
71
  # Octokit.delete_label!("octokit/octokit.rb", "Version 1.0")
72
72
  def delete_label!(repo, label, options = {})
73
- boolean_from_response :delete, "#{Repository.path repo}/labels/#{label}", options
73
+ boolean_from_response :delete, "#{Repository.path repo}/labels/#{ERB::Util.url_encode(label)}", options
74
74
  end
75
75
 
76
76
  # Remove a label from an Issue
@@ -85,7 +85,7 @@ module Octokit
85
85
  # @example Remove the label "Version 1.0" from the repository.
86
86
  # Octokit.remove_label("octokit/octokit.rb", 23, "Version 1.0")
87
87
  def remove_label(repo, number, label, options = {})
88
- delete "#{Repository.path repo}/issues/#{number}/labels/#{label}", options
88
+ delete "#{Repository.path repo}/issues/#{number}/labels/#{ERB::Util.url_encode(label)}", options
89
89
  end
90
90
 
91
91
  # Remove all label from an Issue
@@ -91,7 +91,7 @@ module Octokit
91
91
  conn = Faraday.new(:url => @api_endpoint) do |http|
92
92
  http.headers[:user_agent] = user_agent
93
93
  if basic_authenticated?
94
- http.request :basic_auth, @login, @password
94
+ http.request *FARADAY_BASIC_AUTH_KEYS, @login, @password
95
95
  elsif token_authenticated?
96
96
  http.request :authorization, 'token', @access_token
97
97
  end
@@ -8,30 +8,40 @@ module Octokit
8
8
 
9
9
  # Root for status API
10
10
  # @private
11
- STATUS_ROOT = 'https://status.github.com/api.json'
11
+ SUMMARY_ROOT = 'https://www.githubstatus.com/api/v2/summary.json'
12
+ STATUS_ROOT = 'https://www.githubstatus.com/api/v2/status.json'
13
+ COMPONENTS_ROOT = 'https://www.githubstatus.com/api/v2/components.json'
14
+
15
+ # Returns a summary with the current status and the last status messages.
16
+ #
17
+ # @return [<Sawyer::Resource>] GitHub status summary
18
+ # @see https://www.githubstatus.com/api#summory
19
+ def github_status_summary
20
+ get(SUMMARY_ROOT)
21
+ end
12
22
 
13
23
  # Returns the current system status
14
24
  #
15
25
  # @return [Sawyer::Resource] GitHub status
16
- # @see https://status.github.com/api#api-current-status
26
+ # @see https://www.githubstatus.com/api#status
17
27
  def github_status
18
- get(STATUS_ROOT).rels[:status].get.data
28
+ get(STATUS_ROOT)
19
29
  end
20
30
 
21
31
  # Returns the last human communication, status, and timestamp.
22
32
  #
23
33
  # @return [Sawyer::Resource] GitHub status last message
24
- # @see https://status.github.com/api#api-last-message
34
+ # @see https://www.githubstatus.com/api/#components
25
35
  def github_status_last_message
26
- get(STATUS_ROOT).rels[:last_message].get.data
36
+ get(COMPONENTS_ROOT).components.first
27
37
  end
28
38
 
29
39
  # Returns the most recent human communications with status and timestamp.
30
40
  #
31
41
  # @return [Array<Sawyer::Resource>] GitHub status messages
32
- # @see https://status.github.com/api#api-recent-messages
42
+ # @see https://www.githubstatus.com/api#components
33
43
  def github_status_messages
34
- get(STATUS_ROOT).rels[:messages].get.data
44
+ get(COMPONENTS_ROOT).components
35
45
  end
36
46
  end
37
47
  end
@@ -2,7 +2,6 @@ require 'octokit/connection'
2
2
  require 'octokit/warnable'
3
3
  require 'octokit/arguments'
4
4
  require 'octokit/repo_arguments'
5
- require 'octokit/configurable'
6
5
  require 'octokit/authentication'
7
6
  require 'octokit/gist'
8
7
  require 'octokit/rate_limit'
@@ -133,7 +132,7 @@ module Octokit
133
132
  def initialize(options = {})
134
133
  # Use options passed in, but fall back to module defaults
135
134
  Octokit::Configurable.keys.each do |key|
136
- value = options.key?(key) ? options[key] : Octokit.instance_variable_get(:"@#{key}")
135
+ value = options[key].nil? ? Octokit.instance_variable_get(:"@#{key}") : options[key]
137
136
  instance_variable_set(:"@#{key}", value)
138
137
  end
139
138
 
@@ -238,7 +237,7 @@ module Octokit
238
237
  conn_opts[:ssl] = { :verify_mode => @ssl_verify_mode } if @ssl_verify_mode
239
238
  conn = Faraday.new(conn_opts) do |http|
240
239
  if basic_authenticated?
241
- http.request :basic_auth, @login, @password
240
+ http.request *FARADAY_BASIC_AUTH_KEYS, @login, @password
242
241
  elsif token_authenticated?
243
242
  http.request :authorization, 'token', @access_token
244
243
  elsif bearer_authenticated?
@@ -107,13 +107,13 @@ module Octokit
107
107
  http.headers[:content_type] = "application/json"
108
108
  http.headers[:user_agent] = user_agent
109
109
  if basic_authenticated?
110
- http.request :basic_auth, @login, @password
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 :basic_auth, @client_id, @client_secret
116
+ http.request *FARADAY_BASIC_AUTH_KEYS, @client_id, @client_secret
117
117
  end
118
118
  end
119
119
  end
@@ -2,6 +2,15 @@ require 'octokit/middleware/follow_redirects'
2
2
  require 'octokit/response/raise_error'
3
3
  require 'octokit/response/feed_parser'
4
4
  require 'octokit/version'
5
+ require 'octokit/warnable'
6
+
7
+ if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
8
+ begin
9
+ require 'faraday/retry'
10
+ rescue LoadError
11
+ Octokit::Warnable.octokit_warn 'To use retry middleware with Faraday v2.0+, install `faraday-retry` gem'
12
+ end
13
+ end
5
14
 
6
15
  module Octokit
7
16
 
@@ -20,12 +29,13 @@ module Octokit
20
29
  # Default WEB endpoint
21
30
  WEB_ENDPOINT = "https://github.com".freeze
22
31
 
23
- # In Faraday 0.9, Faraday::Builder was renamed to Faraday::RackBuilder
24
- RACK_BUILDER_CLASS = defined?(Faraday::RackBuilder) ? Faraday::RackBuilder : Faraday::Builder
25
-
26
32
  # Default Faraday middleware stack
27
- MIDDLEWARE = RACK_BUILDER_CLASS.new do |builder|
28
- builder.use Faraday::Request::Retry, exceptions: [Octokit::ServerError]
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
+ builder.use Faraday::Request::Retry, exceptions: [Octokit::ServerError] if defined?(Faraday::Request::Retry)
37
+ builder.use Faraday::Retry::Middleware, exceptions: [Octokit::ServerError] if defined?(Faraday::Retry::Middleware)
38
+
29
39
  builder.use Octokit::Middleware::FollowRedirects
30
40
  builder.use Octokit::Response::RaiseError
31
41
  builder.use Octokit::Response::FeedParser
@@ -11,7 +11,7 @@ module Octokit
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 http: //git.io/j5NT
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
@@ -156,7 +156,7 @@ module Octokit
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: http://git.io/jMir
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
161
  @faraday_configuration ||= Faraday.new(:url => @management_console_endpoint) do |http|
162
162
  http.headers[:user_agent] = user_agent
data/lib/octokit/error.rb CHANGED
@@ -68,6 +68,8 @@ module Octokit
68
68
  def self.error_for_403(body)
69
69
  if body =~ /rate limit exceeded/i
70
70
  Octokit::TooManyRequests
71
+ elsif body =~ /exceeded a secondary rate limit/i
72
+ Octokit::TooManyRequests
71
73
  elsif body =~ /login attempts exceeded/i
72
74
  Octokit::TooManyLoginAttempts
73
75
  elsif body =~ /returns blobs up to [0-9]+ MB/i
@@ -0,0 +1,8 @@
1
+ require 'faraday'
2
+
3
+ module Octokit
4
+ module Response
5
+ # In Faraday 2.x, Faraday::Response::Middleware was removed
6
+ BaseMiddleware = defined?(Faraday::Response::Middleware) ? Faraday::Response::Middleware : Faraday::Middleware
7
+ end
8
+ end
@@ -1,11 +1,11 @@
1
- require 'faraday'
1
+ require 'octokit/response/base_middleware'
2
2
 
3
3
  module Octokit
4
4
 
5
5
  module Response
6
6
 
7
7
  # Parses RSS and Atom feed responses.
8
- class FeedParser < Faraday::Response::Middleware
8
+ class FeedParser < BaseMiddleware
9
9
 
10
10
  def on_complete(env)
11
11
  if env[:response_headers]["content-type"] =~ /(\batom|\brss)/
@@ -1,4 +1,4 @@
1
- require 'faraday'
1
+ require 'octokit/response/base_middleware'
2
2
  require 'octokit/error'
3
3
 
4
4
  module Octokit
@@ -7,7 +7,7 @@ module Octokit
7
7
 
8
8
  # This class raises an Octokit-flavored exception based
9
9
  # HTTP status codes returned by the API
10
- class RaiseError < Faraday::Response::Middleware
10
+ class RaiseError < BaseMiddleware
11
11
 
12
12
  def on_complete(response)
13
13
  if error = Octokit::Error.from_response(response)
@@ -5,7 +5,7 @@ module Octokit
5
5
 
6
6
  # Current minor release.
7
7
  # @return [Integer]
8
- MINOR = 22
8
+ MINOR = 23
9
9
 
10
10
  # Current patch level.
11
11
  # @return [Integer]
@@ -3,6 +3,8 @@ module Octokit
3
3
  # Allows warnings to be suppressed via environment variable.
4
4
  module Warnable
5
5
 
6
+ module_function
7
+
6
8
  # Wrapper around Kernel#warn to print warnings unless
7
9
  # OCTOKIT_SILENT is set to true.
8
10
  #
data/lib/octokit.rb CHANGED
@@ -1,10 +1,11 @@
1
- require 'octokit/client'
2
- require 'octokit/enterprise_admin_client'
3
- require 'octokit/enterprise_management_console_client'
4
1
  require 'octokit/default'
2
+ require 'octokit/configurable'
5
3
 
6
4
  # Ruby toolkit for the GitHub API
7
5
  module Octokit
6
+ autoload(:Client, File.join(__dir__, 'octokit/client'))
7
+ autoload(:EnterpriseAdminClient, File.join(__dir__, 'octokit/enterprise_admin_client'))
8
+ autoload(:EnterpriseManagementConsoleClient, File.join(__dir__, 'octokit/enterprise_management_console_client'))
8
9
 
9
10
  class << self
10
11
  include Octokit::Configurable
data/octokit.gemspec CHANGED
@@ -5,8 +5,8 @@ require 'octokit/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.add_development_dependency 'bundler', '>= 1', '< 3'
8
- spec.add_dependency 'sawyer', '>= 0.5.3', '~> 0.8.0'
9
- spec.add_dependency 'faraday', '>= 0.9'
8
+ spec.add_dependency 'sawyer', '~> 0.9'
9
+ spec.add_dependency 'faraday', '>= 1', '< 3'
10
10
  spec.authors = ["Wynn Netherland", "Erik Michaels-Ober", "Clint Shryock"]
11
11
  spec.description = %q{Simple wrapper for the GitHub API}
12
12
  spec.email = ['wynn.netherland@gmail.com', 'sferik@gmail.com', 'clint@ctshryock.com']
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.22.0
4
+ version: 4.23.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: 2022-01-12 00:00:00.000000000 Z
13
+ date: 2022-05-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -36,36 +36,36 @@ dependencies:
36
36
  name: sawyer
37
37
  requirement: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: 0.5.3
42
39
  - - "~>"
43
40
  - !ruby/object:Gem::Version
44
- version: 0.8.0
41
+ version: '0.9'
45
42
  type: :runtime
46
43
  prerelease: false
47
44
  version_requirements: !ruby/object:Gem::Requirement
48
45
  requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- version: 0.5.3
52
46
  - - "~>"
53
47
  - !ruby/object:Gem::Version
54
- version: 0.8.0
48
+ version: '0.9'
55
49
  - !ruby/object:Gem::Dependency
56
50
  name: faraday
57
51
  requirement: !ruby/object:Gem::Requirement
58
52
  requirements:
59
53
  - - ">="
60
54
  - !ruby/object:Gem::Version
61
- version: '0.9'
55
+ version: '1'
56
+ - - "<"
57
+ - !ruby/object:Gem::Version
58
+ version: '3'
62
59
  type: :runtime
63
60
  prerelease: false
64
61
  version_requirements: !ruby/object:Gem::Requirement
65
62
  requirements:
66
63
  - - ">="
67
64
  - !ruby/object:Gem::Version
68
- version: '0.9'
65
+ version: '1'
66
+ - - "<"
67
+ - !ruby/object:Gem::Version
68
+ version: '3'
69
69
  description: Simple wrapper for the GitHub API
70
70
  email:
71
71
  - wynn.netherland@gmail.com
@@ -155,6 +155,7 @@ files:
155
155
  - lib/octokit/rate_limit.rb
156
156
  - lib/octokit/repo_arguments.rb
157
157
  - lib/octokit/repository.rb
158
+ - lib/octokit/response/base_middleware.rb
158
159
  - lib/octokit/response/feed_parser.rb
159
160
  - lib/octokit/response/raise_error.rb
160
161
  - lib/octokit/user.rb
@@ -180,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
181
  - !ruby/object:Gem::Version
181
182
  version: 1.3.5
182
183
  requirements: []
183
- rubygems_version: 3.1.2
184
+ rubygems_version: 3.2.9
184
185
  signing_key:
185
186
  specification_version: 4
186
187
  summary: Ruby toolkit for working with the GitHub API